Image

Skin Cancer Detection Using Deep Learning

Introduction
Skin cancer is a widespread and potentially dangerous disease that requires early detection for effective treatment. In this project, we developed an automated system to identify skin cancer using advanced deep learning techniques. By utilizing a dataset of skin lesion images, we built and trained several convolutional neural network (CNN) models, including DenseNet121 and EfficientNetB4. These models help classify skin lesions into various categories, aiding doctors in making quicker and more accurate diagnoses. This project covers all essential steps from data processing and model training to evaluation and visualization.

Explanation All Code

Step 1:

Mounting Google Drive

We mount Google Drive to access our dataset stored in the cloud.


Importing Libraries

We import essential libraries for data processing, model building, evaluation, and visualization.


Data collection and preparation:


We utilized the Skin Cancer Dataset for Deep Learning Classification. We collected a skin cancer dataset consisting of 2500 images. After augmenting the images, the total dataset increased to 4500 images. Then, divide the dataset into 80% for training and 20% for validation.



Load Datasets

We set the paths for training and validation datasets stored in Google Drive.


Listing Categories

We list the categories (labels) in the training dataset directory.


Step 2:

Data Processing

We define a function to read and resize images, storing them with their respective labels. We also count the number of images per class.


Processing Training Data

We process the training data and print the total number of training samples.


Plotting Class Distributions

We plot the distribution of classes in the training dataset.


Processing Validation Data

We process the validation data and print the total number of validation samples.


Plotting Validation Data Distribution

We plot the distribution of classes in the validation dataset.


Step 3:

Preparing Data for Model

We convert image data and labels to numpy arrays and normalize the images.


Visualizing Random Training Images

We display random images from the training dataset for visualization.


Step 4:


Skin Cancer Detection Using CNN, DenseNet121 and EfficientNetB4 Model

  • Basic CNN (Convolutional Neural Network): This model is designed to recognize patterns in images, making it a strong choice for image classification tasks like detecting skin cancer.
  • DenseNet121: This model connects each layer to every other layer in a feed-forward fashion, which helps in improving efficiency and reducing the number of parameters. It is highly effective for detailed image analysis required in skin cancer detection.
  • EfficientNetB4: This is an advanced model known for its efficiency and accuracy. It balances performance and resource usage, making it ideal for complex image classification tasks.


By using these models, my project aims to accurately detect skin cancer from medical images, leveraging the strengths of each model to improve overall performance


Building a Basic CNN Model

We define and compile a basic CNN model.


Training the Basic CNN Model

We train the model and save the best weights.


Plotting Training History

We plot the accuracy and loss curves of the model.


Evaluating Model Performance

Evaluating the Model

We load the best model and evaluate it on the test data. There is the accuracy of 89.50%.


Plotting Confusion Matrix and Classification Report

We plot the confusion matrix and print the classification report.


Step 5:

Building a Densenet121

We define and compile a Densenet121 Model.


Training the Densenet121 Model.

We train the model and save the best weights.


Plotting Training History

We plot the accuracy and loss curves of the model.


Evaluating Model Performance

Evaluating the Model

We load the best model and evaluate it on the test data. There is DenseNet121 Accuracy of 71.22%.


Saving the DenseNet121 Model

We save the DenseNet121 model architecture and weights.


Plotting Confusion Matrix and Classification Report

We plot the confusion matrix and print the classification report.


Step 6:

Building a efficientnet_b4

We define and compile a EfficientNetB4 model.


Training the EfficientNetB4

We train the model and save the best weights.


Plotting Training History

We plot the accuracy and loss curves of the model.


Evaluating Model Performance

Evaluating the Model

We load the best model and evaluate it on the test data. There is the EfficientNetB4 Accuracy of 80.44%.


Saving the EfficientNet Model

We save the EfficientNet model architecture and weights.


Plotting Confusion Matrix and Classification Report

We plot the confusion matrix and print the classification report.


Step 7:

Prediction

Load the Model efficientnet_b4

This code loads a pre-trained EfficientNetB4 model, processes an input image for prediction, makes a prediction, identifies the predicted class, and then displays the image with the predicted class label.


Conclusion


Our project successfully demonstrates how deep learning can enhance the detection of skin cancer. By using powerful models like DenseNet121 and EfficientNetB4, we achieved notable accuracy in classifying skin lesions. The EfficientNetB4 model, in particular, reached an accuracy of 80.44%. These results show that deep learning has the potential to support healthcare professionals in early skin cancer detection, leading to better patient outcomes. Future work could focus on expanding the dataset, testing more advanced models, and creating an easy-to-use application for clinical settings.

Code Editor