- Overview
- Key Features
- Architecture
- Datasets
- Results
- Installation
- Usage
- Project Structure
- Technologies Used
- Acknowledgments
This project presents a comprehensive end-to-end deep learning pipeline for automated melanoma detection in dermoscopic images. Melanoma is the deadliest form of skin cancer, and early detection is crucial for successful treatment. Our pipeline addresses two critical tasks:
- ๐จ Lesion Segmentation: Precise pixel-wise localization of skin lesions using U-Net with ResNet34 encoder
- ๐ Lesion Classification: Binary classification (benign vs. malignant) using EfficientNet-B0
The pipeline combines both models to provide accurate lesion localization and diagnosis, supporting clinical decision-making in melanoma detection.
- โ Dual-Task Architecture: Segmentation + Classification in one pipeline
- โ State-of-the-Art Models: U-Net with ResNet34 encoder & EfficientNet-B0
- โ Smart Preprocessing: Segmentation-based cropping for improved classification
- โ High Performance: Achieved strong metrics on both tasks
- โ End-to-End Inference: From raw image to diagnosis prediction
- โ Comprehensive Evaluation: Multiple metrics (Dice, IoU, Accuracy, Confidence scores)
Our segmentation model uses a U-Net architecture with a pre-trained ResNet34 encoder for feature extraction.
Architecture Highlights:
- Encoder: Pre-trained ResNet34 (ImageNet weights)
- Decoder: Symmetric upsampling path with skip connections
- Input Size: 512ร512ร3
- Output: Single-channel binary mask
- Loss Function: Combined BCE + Dice Loss
The classification model leverages EfficientNet-B0 for efficient and accurate melanoma diagnosis.
Architecture Highlights:
- Base Model: EfficientNet-B0 (ImageNet pre-trained)
- Input: 224ร224ร3 (segmentation-cropped lesions)
- Output: 2 classes (Benign, Malignant)
- Loss Function: Cross-Entropy Loss
- Optimizer: Adam with ReduceLROnPlateau scheduler
- Source: International Skin Imaging Collaboration
- Task: Lesion Boundary Segmentation
- Training Images: ~2,594
- Validation Images: ~100
- Test Images: ~1,000
- Annotations: Pixel-level binary masks
- Source: Kaggle - Melanoma Skin Cancer Dataset
- Task: Binary Classification (Benign vs. Malignant)
- Total Images: ~10,000 dermoscopic images
- Classes:
- Benign: Non-cancerous lesions
- Malignant: Melanoma cases
- Split: 80% train, 20% validation, separate test set
Test Set Metrics:
| Metric | Score |
|---|---|
| Dice Coefficient | ~0.89+ |
| IoU (Jaccard Index) | ~0.82+ |
| Pixel Accuracy | ~0.95+ |
Training Details:
- Epochs: 50 (with early stopping)
- Batch Size: 8
- Optimizer: Adam (lr=1e-4)
- Scheduler: ReduceLROnPlateau
- Best model saved based on validation loss
Test Set Metrics:
| Metric | Score |
|---|---|
| Test Accuracy | ~85%+ |
| Training Accuracy | ~90%+ |
Training Details:
- Epochs: 20 (with early stopping)
- Batch Size: 32
- Optimizer: Adam (lr=1e-4)
- Early Stopping: 5 epochs patience
Left to Right: Input Image | Segmentation Mask | Classification Result
Left to Right: Input Image | Segmentation Mask | Classification Result
- Python 3.8+
- CUDA-compatible GPU (recommended)
- Google Colab (optional, for notebook execution)
pip install torch torchvision
pip install segmentation-models-pytorch
pip install opencv-python
pip install numpy pandas matplotlib
pip install scikit-learn
pip install tqdm- Clone the repository:
git clone https://github.com/yourusername/melanoma-detection.git
cd melanoma-detection- Install dependencies:
pip install -r requirements.txt-
Download datasets:
- ISIC 2018: Official Website
- HAM10000: Kaggle Dataset
-
Organize data structure:
Melanoma Detection/
โโโ Training/
โ โโโ images/
โ โโโ masks/
โโโ Validation/
โ โโโ images/
โ โโโ masks/
โโโ Test/
โ โโโ images/
โ โโโ masks/
โโโ melanoma_cancer_dataset/
โโโ train/
โ โโโ benign/
โ โโโ malignant/
โโโ test/
โโโ benign/
โโโ malignant/
- Open the Jupyter Notebook:
jupyter notebook Melanoma-Detection.ipynb- Execute cells sequentially for:
- Data loading and preprocessing
- Segmentation model training
- Classification model training
- Inference and evaluation
# Load and preprocess data
train_loader, val_loader = prepare_segmentation_data()
# Initialize U-Net
model = smp.Unet(
encoder_name='resnet34',
encoder_weights='imagenet',
in_channels=3,
classes=1
)
# Train
train_segmentation_model(model, train_loader, val_loader, epochs=50)# Load segmentation-cropped data
train_loader, val_loader, test_loader = prepare_classification_data()
# Initialize EfficientNet
cls_model = efficientnet_b0(pretrained=True)
cls_model.classifier[1] = nn.Linear(cls_model.classifier[1].in_features, 2)
# Train
train_classification_model(cls_model, train_loader, val_loader, epochs=20)# Load trained models
seg_model = load_segmentation_model('best_unet.pth')
cls_model = load_classification_model('best_classifier.pth')
# Run inference
prediction = predict(image_path, seg_model, cls_model)
print(f"Prediction: {prediction['label']} (Confidence: {prediction['confidence']:.2%})")Melanoma-Detection/
โ
โโโ Melanoma-Detection.ipynb # Main notebook with full pipeline
โโโ Melanoma-Detection.key # Presentation slides
โโโ README.md # Project documentation
โโโ requirements.txt # Python dependencies
โ
โโโ Assets/ # Visual assets for documentation
โ โโโ benign.png
โ โโโ malignant.png
โ โโโ Classification-Epoch.png
โ โโโ Segmentation-Epoch.png
โ โโโ U-Net Architecture.png
โ โโโ EfficientNet Architecture.png
โ
โโโ models/ # Saved model weights (not in repo)
โ โโโ best_unet.pth
โ โโโ best_classifier.pth
โ
โโโ data/ # Dataset directory (not in repo)
โโโ Training/
โโโ Validation/
โโโ Test/
โโโ melanoma_cancer_dataset/
- Deep Learning Framework: PyTorch 2.0+
- Segmentation: Segmentation Models PyTorch
- Pre-trained Models:
- ResNet34 (ImageNet)
- EfficientNet-B0 (ImageNet)
- Computer Vision: OpenCV
- Data Processing: NumPy, Pandas
- Visualization: Matplotlib
- Training Environment: Google Colab (GPU)
- Data Preprocessing Matters: Proper image-mask pairing and normalization significantly impact model performance
- Transfer Learning is Powerful: Pre-trained encoders (ResNet34) accelerated segmentation training
- Combined Loss Functions: BCE + Dice Loss improved segmentation boundary accuracy
- Smart Cropping: Using segmentation masks to crop lesions before classification improved accuracy
- Early Stopping: Prevented overfitting and reduced training time
- Evaluation Metrics: Multiple metrics (Dice, IoU, Accuracy) provide comprehensive performance assessment
- Implement multi-class classification (7+ skin lesion types)
- Add data augmentation (rotation, flipping, color jittering)
- Experiment with larger models (EfficientNet-B3/B4)
- Deploy as web application using Flask/FastAPI
- Add explainability features (Grad-CAM, attention maps)
- Implement ensemble methods for improved robustness
- Optimize for mobile deployment (TensorFlow Lite)
- Ronneberger, O., Fischer, P., & Brox, T. (2015). U-Net: Convolutional Networks for Biomedical Image Segmentation.
- Tan, M., & Le, Q. (2019). EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks.
- ISIC 2018: Skin Lesion Analysis Towards Melanoma Detection Challenge
- Tschandl, P., Rosendahl, C., & Kittler, H. (2018). The HAM10000 dataset: A large collection of multi-source dermatoscopic images of common pigmented skin lesions.
This project is licensed under the MIT License - see the LICENSE file for details.
- Dalhousie University for providing computational resources
- ISIC Archive for the segmentation dataset
- Kaggle community for the HAM10000 classification dataset
- PyTorch and Segmentation Models PyTorch library developers
For questions or collaborations, please reach out through:
- GitHub Issues
- Email: [hetgpatel@dal.ca]
โญ If you found this project helpful, please consider giving it a star! โญ



