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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🩺 Chest X-Ray Pneumonia Detection using Deep Learning
2
+
3
+ <div align="center">
4
+
5
+ ![Python](https://img.shields.io/badge/Python-3.10-blue?style=for-the-badge&logo=python)
6
+ ![TensorFlow](https://img.shields.io/badge/TensorFlow-2.x-orange?style=for-the-badge&logo=tensorflow)
7
+ ![Keras](https://img.shields.io/badge/Keras-Deep%20Learning-red?style=for-the-badge&logo=keras)
8
+ ![Flask](https://img.shields.io/badge/Flask-Backend-black?style=for-the-badge&logo=flask)
9
+ ![Streamlit](https://img.shields.io/badge/Streamlit-Web_App-ff4b4b?style=for-the-badge&logo=streamlit)
10
+ ![OpenCV](https://img.shields.io/badge/OpenCV-Image_Processing-green?style=for-the-badge&logo=opencv)
11
+ ![CNN](https://img.shields.io/badge/CNN-Custom_Model-success?style=for-the-badge)
12
+ ![VGG16](https://img.shields.io/badge/VGG16-Transfer_Learning-blueviolet?style=for-the-badge)
13
+
14
+ </div>
15
+
16
+ ---
17
+
18
+ # πŸ“Œ Project Overview
19
+
20
+ This project is an **AI-powered Chest X-Ray Pneumonia Detection System** that automatically classifies chest X-ray images into:
21
+
22
+ - βœ… NORMAL
23
+ - 🦠 PNEUMONIA
24
+
25
+ The project demonstrates multiple Deep Learning approaches and compares their performance using:
26
+
27
+ - Custom CNN (10 Epochs)
28
+ - Improved CNN (20 Epochs)
29
+ - Transfer Learning (VGG16)
30
+
31
+ The trained models are deployed using **Flask**, while the frontend is developed using **Streamlit**, creating a complete end-to-end AI medical imaging application.
32
+
33
+ ---
34
+
35
+ # πŸš€ Features
36
+
37
+ βœ” Binary Classification
38
+
39
+ βœ” Three Deep Learning Models
40
+
41
+ βœ” Custom CNN Architecture
42
+
43
+ βœ” Improved CNN Architecture
44
+
45
+ βœ” Transfer Learning using VGG16
46
+
47
+ βœ” Real-time Image Prediction
48
+
49
+ βœ” Flask REST Backend
50
+
51
+ βœ” Streamlit Interactive UI
52
+
53
+ βœ” Hugging Face Model Hosting
54
+
55
+ βœ” GPU Training Support
56
+
57
+ βœ” Model Comparison
58
+
59
+ βœ” Confidence Score Prediction
60
+
61
+ βœ” Production Ready
62
+
63
+ ---
64
+
65
+ # 🧠 Problem Statement
66
+
67
+ Pneumonia is one of the leading causes of death worldwide.
68
+
69
+ Radiologists inspect Chest X-rays manually which is:
70
+
71
+ - Time Consuming
72
+ - Error Prone
73
+ - Expensive
74
+
75
+ This project automates the diagnosis process using Deep Learning.
76
+
77
+ ---
78
+
79
+ # πŸ“‚ Dataset
80
+
81
+ ## Chest X-Ray Dataset
82
+
83
+ ```
84
+ Dataset
85
+ β”‚
86
+ β”œβ”€β”€ train
87
+ β”‚ β”œβ”€β”€ NORMAL
88
+ β”‚ └── PNEUMONIA
89
+ β”‚
90
+ β”œβ”€β”€ validation
91
+ β”‚ β”œβ”€β”€ NORMAL
92
+ β”‚ └── PNEUMONIA
93
+ β”‚
94
+ └── test
95
+ β”œβ”€β”€ NORMAL
96
+ └── PNEUMONIA
97
+ ```
98
+
99
+ Image Format
100
+
101
+ - JPG
102
+ - JPEG
103
+ - PNG
104
+
105
+ Classes
106
+
107
+ | Label | Description |
108
+ |---------|-------------|
109
+ | NORMAL | Healthy Lung |
110
+ | PNEUMONIA | Infected Lung |
111
+
112
+ ---
113
+
114
+ # βš™οΈ Tech Stack
115
+
116
+ ## Programming
117
+
118
+ - Python
119
+
120
+ ---
121
+
122
+ ## Deep Learning
123
+
124
+ - TensorFlow
125
+ - Keras
126
+
127
+ ---
128
+
129
+ ## Computer Vision
130
+
131
+ - OpenCV
132
+ - NumPy
133
+ - Matplotlib
134
+
135
+ ---
136
+
137
+ ## Backend
138
+
139
+ - Flask
140
+
141
+ ---
142
+
143
+ ## Frontend
144
+
145
+ - Streamlit
146
+
147
+ ---
148
+
149
+ ## Deployment
150
+
151
+ - Hugging Face
152
+ - Render
153
+
154
+ ---
155
+
156
+ ## Version Control
157
+
158
+ - Git
159
+ - GitHub
160
+
161
+ ---
162
+
163
+ # πŸ— Complete Project Architecture
164
+
165
+ ```
166
+ Chest X-Ray Image
167
+ β”‚
168
+ β–Ό
169
+ Upload Image (UI)
170
+ β”‚
171
+ β–Ό
172
+ Streamlit Frontend
173
+ β”‚
174
+ β–Ό
175
+ Flask REST API
176
+ β”‚
177
+ β–Ό
178
+ Image Preprocessing
179
+ β”‚
180
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
181
+ β”‚ β”‚ β”‚
182
+ β–Ό β–Ό β–Ό
183
+ CNN Model CNN 20 Model VGG16 Model
184
+ β”‚ β”‚ β”‚
185
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
186
+ β”‚
187
+ β–Ό
188
+ Prediction Probability
189
+ β”‚
190
+ β–Ό
191
+ NORMAL / PNEUMONIA Result
192
+ β”‚
193
+ β–Ό
194
+ Display Prediction
195
+ ```
196
+
197
+ ---
198
+
199
+ # πŸ“Š End-to-End Workflow
200
+
201
+ ```
202
+ Dataset
203
+ β”‚
204
+ β–Ό
205
+ Image Loading
206
+ β”‚
207
+ β–Ό
208
+ Image Preprocessing
209
+ β”‚
210
+ β–Ό
211
+ Resize Images (100x100)
212
+ β”‚
213
+ β–Ό
214
+ Convert to Array
215
+ β”‚
216
+ β–Ό
217
+ Normalize Images
218
+ β”‚
219
+ β–Ό
220
+ Train / Validation Split
221
+ β”‚
222
+ β–Ό
223
+ Model Training
224
+ β”‚
225
+ β–Ό
226
+ Model Evaluation
227
+ β”‚
228
+ β–Ό
229
+ Save Best Model
230
+ β”‚
231
+ β–Ό
232
+ Deploy Model
233
+ β”‚
234
+ β–Ό
235
+ User Upload Image
236
+ β”‚
237
+ β–Ό
238
+ Prediction
239
+ ```
240
+
241
+ ---
242
+
243
+ # 🧹 Image Preprocessing Pipeline
244
+
245
+ Each X-Ray undergoes the following preprocessing steps:
246
+
247
+ ### Step 1
248
+
249
+ Load Image
250
+
251
+ ↓
252
+
253
+ ### Step 2
254
+
255
+ Convert to Grayscale (CNN Models)
256
+
257
+ ↓
258
+
259
+ ### Step 3
260
+
261
+ Convert to RGB (VGG16)
262
+
263
+ ↓
264
+
265
+ ### Step 4
266
+
267
+ Resize
268
+
269
+ ```
270
+ 100 Γ— 100
271
+ ```
272
+
273
+ ↓
274
+
275
+ ### Step 5
276
+
277
+ Convert to NumPy Array
278
+
279
+ ↓
280
+
281
+ ### Step 6
282
+
283
+ Normalize Pixel Values
284
+
285
+ ```
286
+ 0 β†’ 255
287
+
288
+ ↓
289
+
290
+ 0 β†’ 1
291
+ ```
292
+
293
+ ↓
294
+
295
+ ### Step 7
296
+
297
+ Feed into Model
298
+
299
+ ---
300
+
301
+ # πŸ€– Model 1
302
+
303
+ ## Custom CNN (10 Epochs)
304
+
305
+ Architecture
306
+
307
+ ```
308
+ Input (100Γ—100Γ—1)
309
+
310
+ ↓
311
+
312
+ Conv2D (64)
313
+
314
+ ↓
315
+
316
+ MaxPooling
317
+
318
+ ↓
319
+
320
+ Dropout
321
+
322
+ ↓
323
+
324
+ Conv2D (128)
325
+
326
+ ↓
327
+
328
+ MaxPooling
329
+
330
+ ↓
331
+
332
+ Dropout
333
+
334
+ ↓
335
+
336
+ Conv2D (256)
337
+
338
+ ↓
339
+
340
+ MaxPooling
341
+
342
+ ↓
343
+
344
+ Dropout
345
+
346
+ ↓
347
+
348
+ Flatten
349
+
350
+ ↓
351
+
352
+ Dense (64)
353
+
354
+ ↓
355
+
356
+ Dropout
357
+
358
+ ↓
359
+
360
+ Dense (1)
361
+
362
+ ↓
363
+
364
+ Sigmoid
365
+ ```
366
+
367
+ Loss
368
+
369
+ ```
370
+ Binary Crossentropy
371
+ ```
372
+
373
+ Optimizer
374
+
375
+ ```
376
+ Adam
377
+ ```
378
+
379
+ Epochs
380
+
381
+ ```
382
+ 10
383
+ ```
384
+
385
+ ---
386
+
387
+ # πŸ€– Model 2
388
+
389
+ ## Improved CNN (20 Epochs)
390
+
391
+ Architecture
392
+
393
+ ```
394
+ Input
395
+
396
+ ↓
397
+
398
+ Conv2D (64)
399
+
400
+ ↓
401
+
402
+ ReLU
403
+
404
+ ↓
405
+
406
+ MaxPooling
407
+
408
+ ↓
409
+
410
+ Dropout
411
+
412
+ ↓
413
+
414
+ Conv2D (128)
415
+
416
+ ↓
417
+
418
+ ReLU
419
+
420
+ ↓
421
+
422
+ MaxPooling
423
+
424
+ ↓
425
+
426
+ Dropout
427
+
428
+ ↓
429
+
430
+ Conv2D (256)
431
+
432
+ ↓
433
+
434
+ ReLU
435
+
436
+ ↓
437
+
438
+ MaxPooling
439
+
440
+ ↓
441
+
442
+ Dropout
443
+
444
+ ↓
445
+
446
+ Flatten
447
+
448
+ ↓
449
+
450
+ Dense (64)
451
+
452
+ ↓
453
+
454
+ Dropout
455
+
456
+ ↓
457
+
458
+ Dense (1)
459
+
460
+ ↓
461
+
462
+ Sigmoid
463
+ ```
464
+
465
+ Epochs
466
+
467
+ ```
468
+ 20
469
+ ```
470
+
471
+ Optimizer
472
+
473
+ ```
474
+ Adam
475
+ ```
476
+
477
+ Loss
478
+
479
+ ```
480
+ Binary Crossentropy
481
+ ```
482
+
483
+ ---
484
+
485
+ # πŸ€– Model 3
486
+
487
+ ## Transfer Learning (VGG16)
488
+
489
+ Pretrained
490
+
491
+ ```
492
+ ImageNet
493
+ ```
494
+
495
+ Frozen Layers
496
+
497
+ ```
498
+ All VGG16 Convolution Layers
499
+ ```
500
+
501
+ Custom Head
502
+
503
+ ```
504
+ Flatten
505
+
506
+ ↓
507
+
508
+ Dense (256)
509
+
510
+ ↓
511
+
512
+ Dense (128)
513
+
514
+ ↓
515
+
516
+ Dense (64)
517
+
518
+ ↓
519
+
520
+ Dense (1)
521
+
522
+ ↓
523
+
524
+ Sigmoid
525
+ ```
526
+
527
+ Callbacks
528
+
529
+ - ModelCheckpoint
530
+ - EarlyStopping
531
+
532
+ ---
533
+
534
+ # 🧠 Why VGG16?
535
+
536
+ Instead of training from scratch,
537
+
538
+ VGG16 already knows how to detect
539
+
540
+ - Edges
541
+ - Shapes
542
+ - Textures
543
+ - Patterns
544
+
545
+ Only the classifier is trained on Chest X-rays.
546
+
547
+ This greatly improves performance while reducing training time.
548
+
549
+ ---
550
+
551
+ # πŸ“ Saved Models
552
+
553
+ ```
554
+ model_xray.h5
555
+ ```
556
+
557
+ Custom CNN
558
+
559
+ ---
560
+
561
+ ```
562
+ model_pre.h5
563
+ ```
564
+
565
+ Improved CNN
566
+
567
+ ---
568
+
569
+ ```
570
+ best_model.keras
571
+ ```
572
+
573
+ Best Transfer Learning Model
574
+
575
+ ---
576
+
577
+ # πŸ“ˆ Training Strategy
578
+
579
+ - GPU Training
580
+ - Batch Size = 4 (CNN)
581
+ - Batch Size = 32 (VGG16)
582
+ - Validation Dataset
583
+ - Binary Crossentropy
584
+ - Adam Optimizer
585
+ - Early Stopping
586
+ - Model Checkpoint
587
+
588
+ ---
589
+
590
+ # πŸ“Š Prediction Pipeline
591
+
592
+ ```
593
+ Upload Image
594
+
595
+ ↓
596
+
597
+ Read Image
598
+
599
+ ↓
600
+
601
+ Resize
602
+
603
+ ↓
604
+
605
+ Preprocess
606
+
607
+ ↓
608
+
609
+ Load Model
610
+
611
+ ↓
612
+
613
+ Predict Probability
614
+
615
+ ↓
616
+
617
+ Threshold = 0.5
618
+
619
+ ↓
620
+
621
+ NORMAL
622
+
623
+ or
624
+
625
+ PNEUMONIA
626
+ ```
627
+
628
+ ---
629
+
630
+ # 🌐 Deployment Architecture
631
+
632
+ ```
633
+ User
634
+ β”‚
635
+ β–Ό
636
+ Streamlit Frontend
637
+ β”‚
638
+ β–Ό
639
+ Flask Backend
640
+ β”‚
641
+ β–Ό
642
+ Load Selected Model
643
+ β”‚
644
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
645
+ β–Ό β–Ό β–Ό
646
+ CNN10 CNN20 VGG16
647
+ β”‚ β”‚ β”‚
648
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
649
+ β–Ό
650
+ Prediction Engine
651
+ β”‚
652
+ β–Ό
653
+ Display Result
654
+ ```
655
+
656
+ ---
657
+
658
+ # πŸ“‚ Project Structure
659
+
660
+ ```
661
+ Chest-XRay-Pneumonia-Detection
662
+ β”‚
663
+ β”œβ”€β”€ app.py
664
+ β”œβ”€β”€ config.py
665
+ β”œβ”€β”€ predictor.py
666
+ β”œβ”€β”€ utils.py
667
+ β”œβ”€β”€ requirements.txt
668
+ β”œβ”€β”€ README.md
669
+ β”‚
670
+ β”œβ”€β”€ models
671
+ β”‚ β”œβ”€β”€ model_xray.h5
672
+ β”‚ β”œβ”€β”€ model_pre.h5
673
+ β”‚ └── best_model.keras
674
+ β”‚
675
+ β”œβ”€β”€ static
676
+ β”‚
677
+ β”œβ”€β”€ templates
678
+ β”‚
679
+ β”œβ”€β”€ css
680
+ β”‚
681
+ β”œβ”€β”€ dataset
682
+ β”‚
683
+ └── screenshots
684
+ ```
685
+
686
+ ---
687
+
688
+ # ▢️ Installation
689
+
690
+ Clone Repository
691
+
692
+ ```bash
693
+ git clone https://github.com/yourusername/Chest-XRay-Pneumonia-Detection.git
694
+ ```
695
+
696
+ Install Dependencies
697
+
698
+ ```bash
699
+ pip install -r requirements.txt
700
+ ```
701
+
702
+ Run Flask
703
+
704
+ ```bash
705
+ python app.py
706
+ ```
707
+
708
+ Run Streamlit
709
+
710
+ ```bash
711
+ streamlit run app.py
712
+ ```
713
+
714
+ ---
715
+
716
+ # πŸ–₯ Example Prediction
717
+
718
+ Input
719
+
720
+ ```
721
+ Chest X-Ray Image
722
+ ```
723
+
724
+ ↓
725
+
726
+ Model Prediction
727
+
728
+ ```
729
+ Probability : 0.9821
730
+
731
+ Prediction :
732
+
733
+ 🦠 PNEUMONIA
734
+ ```
735
+
736
+ ---
737
+
738
+ # πŸ“ˆ Future Improvements
739
+
740
+ - EfficientNet
741
+ - ResNet50
742
+ - DenseNet121
743
+ - Grad-CAM Heatmaps
744
+ - Multi-Class Disease Detection
745
+ - DICOM Support
746
+ - Cloud Deployment
747
+ - Docker
748
+ - CI/CD Pipeline
749
+ - REST API Authentication
750
+
751
+ ---
752
+
753
+ # πŸ‘¨β€πŸ’» Author
754
+
755
+ **Sudheer Muthyala**
756
+
757
+ B.Tech – Electronics and Communication Engineering
758
+
759
+ Machine Learning | Deep Learning | Computer Vision | Python | Flask | Streamlit
760
+
761
+ GitHub:
762
+ https://github.com/M-Sudheer18
763
+
764
+ ---
765
+
766
+ # ⭐ If you found this project helpful
767
+
768
+ Please consider giving this repository a ⭐ on GitHub.
769
+ It motivates future improvements and helps others discover the project.