A multiclass classification model to detect melanoma and other skin diseases using a custom CNN built in TensorFlow.
- General Information
- Problem Statement
- Dataset Details
- Project Pipeline
- Technologies Used
- Model Architecture and Approach
- Handling Challenges
- Conclusions
- Acknowledgements
- Contact
Skin cancer is one of the most common forms of cancer, with melanoma being the most lethal subtype. Early detection can save lives, but manual diagnosis is time-consuming and subject to human error. This project aims to build a machine learning solution that assists dermatologists in accurately detecting melanoma and other skin conditions from images using a custom convolutional neural network (CNN).
By leveraging a dataset of skin lesion images, the model predicts whether the lesion belongs to one of nine classes of oncological diseases. This solution aims to reduce diagnostic time and enhance the accuracy of skin cancer detection.
Melanoma accounts for 75% of skin cancer deaths despite representing a small proportion of skin cancers. Early and accurate detection is critical to improve survival rates. The aim of this project is to:
- Build a custom CNN model to classify skin lesion images into nine categories accurately.
- Address challenges like class imbalance and potential overfitting in the training process.
- Implement data augmentation strategies to improve the robustness and generalization of the model.
The dataset used in this project was sourced from the International Skin Imaging Collaboration (ISIC). It contains 2,357 labeled images of skin lesions, categorized into the following nine diseases:
- Actinic keratosis
- Basal cell carcinoma
- Dermatofibroma
- Melanoma
- Nevus
- Pigmented benign keratosis
- Seborrheic keratosis
- Squamous cell carcinoma
- Vascular lesion
- The dataset is slightly imbalanced, with more images of melanoma and moles compared to other classes.
- All images were resized to a uniform dimension of 180x180 pixels for training.
The project follows these structured steps:
- Read and preprocess the dataset.
- Divide the dataset into training and validation sets.
- Resize all images to 180x180 pixels and batch them with a size of 32.
- Visualize one representative image from each of the nine classes to understand the dataset distribution.
- Build a custom CNN architecture to classify images into nine classes.
- Normalize pixel values to the range [0, 1] by rescaling images.
- Use an appropriate optimizer (e.g., Adam) and loss function (e.g., sparse categorical crossentropy).
- Train the model for ~20 epochs and analyze results for overfitting/underfitting.
- Apply data augmentation techniques (e.g., rotation, flipping, zooming) to improve model generalization and address overfitting.
- Re-train the model on the augmented dataset for ~20 epochs.
- Analyze the results to check whether overfitting/underfitting has been resolved.
- Use the Augmentor library to address the class imbalance in the training dataset.
- Augment data for underrepresented classes to ensure balanced representation.
- Train the model on the class-balanced dataset for ~30 epochs.
- Evaluate the final model performance to ensure robustness and accuracy.
The custom CNN architecture includes:
- Convolutional layers with ReLU activation for feature extraction.
- MaxPooling layers to reduce spatial dimensions and prevent overfitting.
- Dropout layers to add regularization.
- Fully connected dense layers for classification into nine classes.
- Optimizer: Adam (learning rate = 0.001)
- Loss Function: Sparse categorical crossentropy
- Batch Size: 32
- Epochs: Initial (20), Augmented Data (20), Balanced Data (30)
- Regularization using dropout layers in the CNN.
- Data augmentation techniques to create variations in the training data.
- Identified dominant and underrepresented classes in the dataset.
- Used the Augmentor library to increase samples for minority classes.
- Experimented with different CNN architectures and hyperparameters.
- Evaluated model accuracy and loss metrics after each training phase.
- Python
- TensorFlow
- Keras
- NumPy
- Matplotlib
- Pandas
- Augmentor
- Google Colab - For GPU runtime during model training
- The custom CNN achieved high accuracy in classifying skin lesions into nine classes.
- Data augmentation significantly reduced overfitting and improved generalization.
- Addressing class imbalance using the Augmentor library further enhanced the model's robustness.
- The final model demonstrates the potential to assist dermatologists in diagnosing melanoma and other skin conditions effectively.
- This project was inspired by the International Skin Imaging Collaboration (ISIC) initiative.
- References:
- ISIC Archive
- TensorFlow and Keras documentation.
- Special thanks to Google Colab for providing free GPU resources for training.
Created by Sagar Maru
Feel free to reach out for collaborations or queries!