This is a Flask web application that uses a trained PyTorch model to predict diseases from chest X-ray images.
- Upload X-ray images via drag-and-drop or file selector
- Preview uploaded images before prediction
- Disease prediction with probability percentages
- Visual results with plots showing the original image and probability distribution
-
Ensure you have Python installed (version 3.7 or higher recommended)
-
Activate the virtual environment:
.\venv\Scripts\activate -
Install the required packages (if not already done):
pip install flask torch torchvision pillow numpy matplotlib -
Place your trained model in the
modeldirectory:model/best_model.pthNote: You need to have a trained model. The model should be a PyTorch checkpoint file.
-
Run the Flask application:
python app.py -
Open your web browser and navigate to:
http://127.0.0.1:5000/
- Drag and drop a chest X-ray image onto the upload area or click the "Select File" button to choose an image file.
- After uploading, a preview of the image will be displayed.
- Click the "Predict Diseases" button to analyze the image.
- Results will show on the right side, including:
- A visual plot of the X-ray and disease probabilities
- A table listing all diseases and their predicted probabilities
The model uses a DenseNet121 architecture pre-trained on ImageNet and fine-tuned for multi-label classification of 14 different lung diseases commonly found in chest X-rays:
- Atelectasis
- Cardiomegaly
- Effusion
- Infiltration
- Mass
- Nodule
- Pneumonia
- Pneumothorax
- Consolidation
- Edema
- Emphysema
- Fibrosis
- Pleural Thickening
- Hernia