Skip to content

Commit 88744f7

Browse files
committed
docs(readme): rewrite with accurate setup, API table, and limitations
1 parent 73a961f commit 88744f7

1 file changed

Lines changed: 76 additions & 36 deletions

File tree

README.md

Lines changed: 76 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,116 @@
1-
# Pneumonia Detection from X-Ray Images
1+
# Pneumonia Detection from Chest X-Ray Images
22

33
![Python](https://img.shields.io/badge/Python-3776AB?style=flat&logo=python&logoColor=white)
44
![TensorFlow](https://img.shields.io/badge/TensorFlow-FF6F00?style=flat&logo=tensorflow&logoColor=white)
55
![Keras](https://img.shields.io/badge/Keras-D00000?style=flat&logo=keras&logoColor=white)
66
![Flask](https://img.shields.io/badge/Flask-000000?style=flat&logo=flask&logoColor=white)
7+
![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)
78

8-
A deep learning web application that detects pneumonia from chest X-ray images using a Convolutional Neural Network (CNN). Upload an X-ray and get an instant prediction.
9+
A deep-learning web app that classifies a chest X-ray as **Normal** or **Pneumonia**
10+
using a Convolutional Neural Network (CNN). Upload an X-ray and get a prediction with a
11+
confidence score.
912

10-
## About
13+
> ⚠️ **Educational project — not a medical device.** Do not use for diagnosis or
14+
> treatment. See [DISCLAIMER.md](DISCLAIMER.md).
1115
12-
Pneumonia is an infection in the lungs that inflames the air sacs in one or both lungs. It is caused by a bacteria called *Streptococcus pneumoniae* that usually lives in the upper respiratory tract. More than **10 million people in India** are affected by this annually. Doctors use a chest X-ray to confirm the infection and its location. Thus developing an automatic system for detecting the disease can help to treat patients quickly. With powerful Artificial Intelligence algorithms, the medical field has evolved in a very vast manner.
16+
## About
1317

14-
**Deep Learning Convolutional Neural Networks (CNN)** is the go-to algorithm when it comes to image classification. CNN models are so powerful that they are already in use for many disease detections. Moreover, CNN models can be used to analyze and find patterns in images. We build a CNN model to analyze the given X-ray image patterns and predict whether the patient is infected or not.
18+
Pneumonia inflames the air sacs in one or both lungs and is diagnosed clinically, often
19+
with the help of a chest X-ray. CNNs are a strong fit for image classification, and this
20+
project trains one to recognise pneumonia patterns in X-rays as a learning exercise in
21+
applied deep learning.
1522

1623
## Dataset
1724

18-
**Chest X-Ray Images (Pneumonia)**[Kaggle Dataset](https://www.kaggle.com/paultimothymooney/chest-xray-pneumonia) (1.24 GB)
25+
**Chest X-Ray Images (Pneumonia)**[Kaggle](https://www.kaggle.com/paultimothymooney/chest-xray-pneumonia)
26+
(~1.24 GB, ~5,860 images across `train` / `val` / `test`, classes `NORMAL` and `PNEUMONIA`).
27+
28+
## Model
29+
30+
A compact Keras `Sequential` CNN trained on 75×75 grayscale X-rays:
1931

20-
## Features
32+
`Conv2D(64) → MaxPooling2D → Flatten → Dense(512) → Dense(256) → Dense(1, sigmoid)`
2133

22-
- **CNN Model** — Custom convolutional neural network trained on chest X-ray images
23-
- **Web Interface** — Flask-based UI for easy image upload and prediction
24-
- **Instant Results** — Upload an X-ray and get immediate classification
25-
- **Training Notebook** — Jupyter notebook with full model training pipeline
34+
Binary cross-entropy loss, Adam optimizer. The full pipeline is in
35+
[`CNN_model.ipynb`](CNN_model.ipynb), which saves the trained weights to `cnn_model.h5`.
2636

27-
## Tech Stack
37+
## Tech stack
2838

2939
| Component | Technology |
3040
|-----------|-----------|
31-
| **Model** | TensorFlow, Keras (CNN) |
32-
| **Backend** | Flask, Gevent |
33-
| **Frontend** | HTML, CSS, JavaScript |
34-
| **Image Processing** | NumPy, Keras Preprocessing |
41+
| Model | TensorFlow / Keras (CNN) |
42+
| Backend | Flask |
43+
| Frontend | HTML, CSS, JavaScript (jQuery) |
44+
| Image processing | NumPy, Pillow |
3545

36-
## Project Structure
46+
## Project structure
3747

3848
```
39-
├── CNN_model.ipynb # Model training notebook
40-
├── app.py # Flask web application
49+
├── app.py # Flask web application
50+
├── CNN_model.ipynb # Model training notebook
51+
├── requirements.txt # Python dependencies
52+
├── DISCLAIMER.md # Medical disclaimer
53+
├── tests/
54+
│ └── test_smoke.py # Smoke tests (TensorFlow mocked)
4155
├── templates/
42-
│ └── index.html # Web interface
56+
└── index.html # Web interface
4357
└── static/
44-
├── css/
45-
├── js/
46-
└── images/
58+
├── css/ ├── js/ └── images/
59+
```
60+
61+
## Getting started
62+
63+
### 1. Install dependencies
64+
65+
```bash
66+
python -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
67+
pip install -r requirements.txt
4768
```
4869

49-
## Getting Started
70+
### 2. Get a trained model
5071

51-
### Prerequisites
72+
Either train it yourself — download the [dataset](https://www.kaggle.com/paultimothymooney/chest-xray-pneumonia)
73+
and run `CNN_model.ipynb` (set `DATA_DIR` to your local dataset path); it saves
74+
`cnn_model.h5` — or drop an existing `cnn_model.h5` in the project root.
75+
76+
### 3. Run the web app
5277

5378
```bash
54-
pip install tensorflow keras flask numpy gevent
79+
python app.py # serves on http://localhost:5000
5580
```
5681

57-
### Train the Model
82+
Open `http://localhost:5000`, upload a chest X-ray, and click **Predict**.
5883

59-
1. Download the [dataset from Kaggle](https://www.kaggle.com/paultimothymooney/chest-xray-pneumonia)
60-
2. Run `CNN_model.ipynb` to train and save the model as `cnn_model.h5`
84+
## API
6185

62-
### Run the Web App
86+
| Route | Method | Description |
87+
|-------|--------|-------------|
88+
| `/` | GET | Web UI |
89+
| `/health` | GET | Liveness probe → `{"status":"ok","model_present":bool}` |
90+
| `/predict` | POST | multipart `image` file → `{"label","pneumonia","confidence"}` |
6391

6492
```bash
65-
python app.py
93+
curl -F "image=@chest_xray.png" http://localhost:5000/predict
94+
# {"label":"Pneumonia detected","pneumonia":true,"confidence":87.3}
6695
```
6796

68-
Navigate to `http://localhost:5000`, upload a chest X-ray image, and get the prediction.
97+
## Tests
98+
99+
Smoke tests mock TensorFlow, so they run in seconds without the weights or dataset:
100+
101+
```bash
102+
pip install pytest && pytest -q
103+
```
69104

70-
## Author
105+
## Limitations
71106

72-
**Sanjay Santhanam**
107+
- Trained only on the Kaggle dataset; performance on X-rays from other equipment,
108+
populations, or preprocessing pipelines is not guaranteed.
109+
- 75×75 grayscale input discards fine detail a clinical model would retain.
110+
- Binary output only (Normal vs Pneumonia) — it does not identify pneumonia type,
111+
severity, or location, and gives no uncertainty calibration.
112+
- **Not validated for clinical use.** See [DISCLAIMER.md](DISCLAIMER.md).
73113

74-
---
114+
## License
75115

76-
⭐ Star this repo if you found it useful!
116+
[MIT](LICENSE) © Sanjay Santhanam

0 commit comments

Comments
 (0)