A deep learning-powered web application for detecting cancer in medical images. Built with Streamlit and PyTorch, this application uses a fine-tuned ResNet34 model to provide real-time cancer detection from medical imaging data.
- Real-time cancer detection from medical images
- Interactive web interface built with Streamlit
- Probability distribution visualization with confidence scores
- Support for TIF format medical images
- System information monitoring
- Data augmentation during training
- Transfer learning using pretrained ResNet34
The application uses a modified ResNet34 architecture:
- Base: Pretrained ResNet34 from torchvision
- Modifications:
- Frozen feature extraction layers
- Custom fully connected layer (num_features → 2 classes)
- Optimized for binary classification
- Dataset Split:
- Training: 2608 images
- Validation: 100 images
- Test: Remaining images
- Data Augmentation:
- Random horizontal flips
- Random rotation (±5 degrees)
- Resize to 224x224
- Normalization (ImageNet statistics)
- Training Parameters:
- Optimizer: Adam (lr=3e-4)
- Loss Function: CrossEntropyLoss
- Batch Size: 32
- Workers: 2
- Hardware: Supports both CPU and GPU training
python >= 3.6
streamlit
torch
torchvision
Pillow
huggingface_hub
pandas
numpy
tqdm
- Clone the repository:
git clone https://github.com/yourusername/cancer-detection-webapp.git
cd cancer-detection-webapp
- Create a virtual environment (recommended):
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install the required packages:
pip install -r requirements.txt
- Configure Hugging Face credentials:
- Create an account on Hugging Face
- Replace
YOUR_HUGGING_FACE_USERNAME
with your username inapp.py
- For private repositories, set your HF token:
export HF_TOKEN=your_token_here # On Windows: set HF_TOKEN=your_token_here
-
Prepare your dataset:
data/ ├── data_sample/ │ ├── image1.tif │ ├── image2.tif │ └── ... └── labels.csv
-
Run the training script:
python train_model.py
- Start the Streamlit application:
streamlit run app.py
-
Open your web browser and navigate to
http://localhost:8501
-
Use the application:
- Upload a medical image (
.tif
format) - Click "Analyze Image"
- View results and probability distribution
- Upload a medical image (
The model is evaluated on a held-out test set with metrics including:
- Binary classification accuracy
- Loss convergence during training
- Real-time performance metrics available in the web interface
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Future improvements planned:
- Support for additional image formats
- Model explainability visualizations
- Batch processing capabilities
- GPU acceleration support
- REST API endpoint
- Docker containerization
- ResNet34 architecture from torchvision
- Web interface built with Streamlit
- Model hosting on Hugging Face Hub
If you use this project in your research or work, please cite it as:
@software{cancer_detection_webapp,
author = {[Faraz Shamim]},
title = {Cancer Detection Web Application},
year = {2024},
url = {https://github.com/mr-imperium/cancer-detection}
}