You are on page 1of 26

VISVESVARAYA TECHNOLOGICAL UNIVERSITY

Jnana Sangama, Belagavi – 590018

A DIP Mini-Project Report


On

“SKIN CANCER DETECTION”


Submitted in partial fulfilment of the requirements for the award of the degree of

BACHELOR OF ENGINEERING
In
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING
By

DHRUVA KUMAR SHETTY 4MT20AI009


PRAMITH A NAIGA 4MT20AI027

Under the Guidance of


Dr Maryjo M George
Assistant Professor

DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING

MANGALORE INSTITUTE OF TECHNOLOGY&ENGINEERING


Accredited by NAAC with A+ Grade, An ISO 9001: 2015 Certified Institution

Badaga Mijar, Moodabidri-574225, Karnataka


2022-2023
ACKNOWLEDGMENT

The satisfaction and the successful completion of this mini project would be incomplete
without the mention of the people who made it possible, and whose constant guidance
and encouragement crowned our efforts with success.

This Mini project is made under the guidance of Dr Maryjo M George, Assistant
Professor in the Department of Artificial Intelligence and Machine Learning. We would
like to express our sincere gratitude to our guide for all the helping hand and guidance in
this project

We would like to express appreciation to Mr Sunil Kumar S, Senior Assistant


Professor, Head of Department of Artificial Intelligence and Machine Learning for his
support and guidance.

We would like to thank our Dr Prashanth C M, Principal, Mangalore Institute of


Technology and Engineering, Moodabidri, for encouraging us and giving us an
opportunity to accomplish the mini-project.

We also thank our management who helped us directly or indirectly in the completion of
this mini-project.

Our special thanks to faculty members and others for their constant help and support.
Above all, we extend our sincere gratitude to our parents and friends for their constant
encouragement with moral support.
Dhruva Kumar Shetty
(4MT2AI009)
Pramith A Naiga
(4MT20AI027)
ABSTRACT

Skin cancer is a prevalent and potentially life-threatening disease that, if detected early,
can significantly improve patient outcomes. In this project, we propose a skin cancer
detection system employing deep learning techniques. Leveraging the power of transfer
learning, we utilize the ResNet50 architecture, a pre-trained convolutional neural
network (CNN), to automatically learn intricate features from skin lesion images. The
dataset comprises a diverse collection of benign and malignant skin lesions.

The workflow involves data loading, preprocessing, and augmentation, followed by the
construction of a custom classification model on top of the ResNet50 base. The model
is trained on a subset of the dataset, with a focus on optimizing classification accuracy.
Additionally, we employ early stopping to mitigate overfitting during the training
process.

The evaluation phase involves assessing the model's performance on a separate test set,
providing key metrics such as accuracy, precision, recall, and F1-score. Furthermore,
we visualize the training and validation curves to gain insights into the model's
convergence.

To demonstrate the model's real-world application, we include a feature for predicting


the class of custom skin lesion images. The model is saved for future use, and the
classification report offers a comprehensive analysis of its effectiveness.

Our project not only showcases the potential of deep learning in skin cancer detection
but also serves as a foundation for further research and development in the domain of
medical image analysis.
TABLE OF CONTENTS

S.NO CHAPTERS PG.NO

1 INTRODUCTION 1

1.1 PROBLEM STATEMENT

2 REQUIREMENT ANALYSIS AND SPECIFICATIONS 2-3


2.1 FUNCTIONAL REQUIREMENT
2.2 NON FUNCTIONAL REQUIREMENT

3 METHODOLOGY 4-11
3.1 DATASETS
3.2 DATA PREPROCESSING AND FEATURE EXTRACTION
3.3 ALGORITHMS IN PICTURE

4 PERFORMANCE MEASURE 12-13

5 TESTING 14-16
5.1 TEST PROCESS
5.2 TEST CASES

6 RESULTS AND DISCUSSION 17-19

7 CONCLUSION 20

8 REFERENCES 21
SKIN CANCER DETECTION

Chapter 1
INTRODUCTION
Skin cancer, among the most prevalent forms of cancer globally, poses a substantial
public health challenge. Timely detection and accurate diagnosis play a pivotal role in
enhancing patient outcomes and reducing the morbidity associated with this disease.
Traditional methods of skin cancer diagnosis heavily rely on visual inspection by
dermatologists, a process that can be time-consuming and subjective. In recent years,
advances in deep learning, particularly convolutional neural networks (CNNs), have
demonstrated remarkable capabilities in image classification tasks, including medical
image analysis. This project endeavors to harness the potential of deep learning to
create an automated system for skin cancer detection, facilitating early diagnosis and
intervention. The primary objective of this project is to develop a robust and accurate
model capable of distinguishing between benign and malignant skin lesions. To
achieve this, we leverage transfer learning, utilizing the ResNet50 architecture as a
pre-trained feature extractor. This approach allows the model to benefit from the
knowledge gained through training on a diverse set of images, enabling it to recognize
intricate patterns and features associated with skin cancer.

1.1 Problem Statement

The manual diagnosis of skin lesions is time-consuming and subjective, often leading
to delays in treatment. Leveraging the power of deep learning, our project aims to
develop an efficient and accurate model capable of automatically discerning between
benign and malignant skin lesions. By addressing these challenges, we seek to enhance
the speed and accuracy of skin cancer diagnosis, ultimately improving patient
outcomes.

This project focuses on utilizing transfer learning with the ResNet50 architecture,
incorporating data loading, preprocessing, and model training. Through this endeavor,
we aspire to contribute to the field of dermatology by providing a reliable tool for early
skin cancer detection, thereby facilitating timely and effective medical interventions.

Dept of AIML MITE,MOODABIDRI Page 1


SKIN CANCER DETECTION

Chapter 2

REQUIREMENT ANALYSIS AND SPECIFICATION

2.1 Functional Requirements


The System Requirement Specification (SRS) is a document, which
describes completely the external behavior of the software as well as the behavior of
the hardware. The first and foremost work of the developer is to study the system to
be developed and specify the user requirements before going for the designing phase.
It includes a set of use cases that describes all the interaction the users will have with
software. Use cases are also known as functional requirements. In addition to use
cases, the SRS also contains non-functional requirements. Non-functional
requirements are requirements, which impose constraints on the design or
implementation.
The functional Requirements are broadly classified into 2 categories :
● Hardware Requirements
● Software Requirements

Hardware Specifications:

Processor : Intel i3/i5, 1.8 GHz machine or above


Main Memory : 4GB RAM or above
Hard disk : 1TB or above

Software Specifications:

Operating system: Windows 7 and above


Programming Language : Python
Platform Used : Anaconda, Jupyter, Visual Studio , Google Colab

2.2 Non Functional Requirements

Non-functional requirements are requirements that are not directly concerned with
the specific functions delivered by the system. The plan for implementing functional
requirements is detailed in the system design. The plan for implementing non-
functional requirements is detailed in the system architecture.

Dept of AIML MITE,MOODABIDRI Page 2


SKIN CANCER DETECTION

Performance: The code should be optimized to provide efficient and fast processing
of images during both training and inference. It should be able to handle a large
number of images without significant delays.

Accuracy: The image classification model should achieve a high level of accuracy
in predicting the correct class labels for the images. The code should aim to achieve
state-of-the-art performance in terms of classification accuracy.

Scalability: The code should be scalable to handle a growing dataset and


accommodate an increasing number of classes for image classification. It should be
able to handle larger training datasets without sacrificing performance.

Maintainability: The code should be written in a modular and well-organized


manner, making it easy to understand and maintain. It should follow coding best
practices and use appropriate naming conventions.

Portability: The code should be designed to be portable across different platforms


and environments. It should work seamlessly on various operating systems and with
different versions of the required libraries and frameworks.

Usability: The code should be user-friendly, providing clear instructions and error
messages to guide users in its usage. It should have well-defined input and output
formats, making it intuitive for users to interact with the system.

Reliability: The code should be robust and reliable, handling unexpected scenarios
and errors gracefully. It should incorporate error handling mechanisms and provide
appropriate error messages to users.

Security: If applicable, the code should include necessary security measures to


protect user data and ensure secure communication between the user interface and
the backend system. It should follow security best practices to mitigate potential
vulnerabilities.

Extensibility: The code should be designed to be easily extendable, allowing for


future enhancements or modifications. It should have well-defined interfaces and
modular components to facilitate the addition of new features or functionalities.

Dept of AIML MITE,MOODABIDRI Page 3


SKIN CANCER DETECTION

Chapter-3
METHODOLOGY
3.1 Datasets

The success of any machine learning project heavily relies on the quality and
diversity of the dataset used for training and evaluation. In our skin cancer detection
project, we meticulously curated a dataset that encapsulates the spectrum of benign
and malignant skin lesions. The dataset serves as the foundation for model training,
validation, and testing, ensuring the robustness and generalization of our deep learning
model.

The skin cancer dataset used in this project comprises a total of 2637 samples. The
dataset is meticulously curated to facilitate the training and evaluation of a deep
learning model for skin cancer detection. The samples are categorized into two classes:

Number of Malignant Samples: 1197


These samples represent instances of skin lesions identified as malignant. Malignant
skin lesions encompass various types of skin cancers, including melanoma, basal cell
carcinoma, and squamous cell carcinoma.

FIG 3.1 : MALIGNANT

Dept of AIML MITE,MOODABIDRI Page 4


SKIN CANCER DETECTION

Number of Benign Samples: 1440


These samples correspond to benign skin lesions, covering a spectrum of non-
cancerous dermatological conditions.

FIG 3.2 : BENIGN

The dataset is balanced, ensuring a representative distribution of both malignant and


benign samples. Each sample is associated with a corresponding file path, enabling
seamless integration into the deep learning model training process. The diversity of
the dataset, along with careful annotation by medical professionals, contributes to the
robustness and generalization of the skin cancer detection model.

Dept of AIML MITE,MOODABIDRI Page 5


SKIN CANCER DETECTION

FIG 3.3 : Comparison between Benign and Malignant

This comprehensive dataset forms the foundation for the development and evaluation
of an accurate and clinically relevant skin cancer detection system.

Dept of AIML MITE,MOODABIDRI Page 6


SKIN CANCER DETECTION

3.2 Data Preprocessing And Model Training


Data Augmentation:
Purpose: Data augmentation is employed to artificially increase the diversity of the
training dataset, preventing the model from overfitting to the specific images in the
training set. The ImageDataGenerator is configured with the preprocess_input function,
which aligns pixel values with the preprocessing used during training ResNet50 on
ImageNet. During training, the generator applies random transformations to the images,
such as rotation, zooming, horizontal flipping, and width/height shifts.
Preprocessing Function:
Purpose: Normalize pixel values and preprocess images to be compatible with the
ResNet50 model. The preprocess_input function is applied to each image array. It
normalizes the pixel values and performs other preprocessing steps, ensuring that the
images fed into the model have a format consistent with ResNet50's expectations.
Flow from DataFrame:
Purpose: Generate batches of augmented and preprocessed images during model
training and testing. flow_from_dataframe is used to create a generator that reads file
paths and labels from the DataFrame (train). Images are resized to the target size of
(100, 100), and class mode is set to 'categorical' for multi-class classification. The
generator yields batches of augmented and preprocessed images during training, with
shuffling enabled.
Training and Validation Generators:
Purpose: Create separate generators for training and validation datasets to provide
batches of images during model training and evaluation. Separate generators are created
for the validation and test datasets using flow_from_dataframe. For the validation
generator (valid_gen), shuffling is disabled to evaluate the model on a fixed set of
validation data. The test generator (test_gen) is used to evaluate the model on unseen
test data during the final evaluation step.
Model Compilation:
Objective: Before training, the model needs to be configured for the learning process.
This involves specifying the optimizer, loss function, and evaluation metric. Optimizer
('adam'): Adam is a popular optimization algorithm that adapts the learning rates during
training, making it well-suited for a variety of tasks.
Loss Function ('categorical_crossentropy'): Categorical crossentropy is often used for
multi-class classification problems.
Metrics (['accuracy']): The accuracy metric is chosen to monitor the model's
performance during training.

Dept of AIML MITE,MOODABIDRI Page 7


SKIN CANCER DETECTION

Model Training:
Objective: Train the model using the provided training data and evaluate it on the
validation set. Adjust the model's weights based on the computed gradients.
train_gen: The training generator (train_gen) yields batches of augmented and
preprocessed images along with their labels.
validation_data=valid_gen: The validation generator (valid_gen) provides batches of
validation data to assess the model's performance during training.
epochs=100: The model is trained for a maximum of 100 epochs.
callbacks=my_callbacks: Early stopping is employed as a callback during training.
These data preprocessing steps collectively ensure that the model is trained on a varied
and well-prepared dataset, promoting better generalization to new, unseen skin lesion
images.

Dept of AIML MITE,MOODABIDRI Page 8


SKIN CANCER DETECTION

Fig 3.4 : Flowchart of Complete Model

Dept of AIML MITE,MOODABIDRI Page 9


SKIN CANCER DETECTION

3.3 Algorithms In Picture


Here's a brief explanation of the main algorithms used in the code :
ResNet50 : ResNet50 is a deep convolutional neural network architecture known for
its groundbreaking approach to addressing the challenge of training very deep
networks. It was introduced by Kaiming He et al. in 2015 and is characterized by the
innovative use of residual learning blocks. ResNet50 serves as a powerful feature
extractor. Its pre-trained layers are used to capture hierarchical features from skin
cancer images. By excluding the top layers and adding custom dense layers, the model
is fine-tuned to specialize in the task of classifying skin lesions as benign or malignant.
This transfer learning approach allows the model to leverage the knowledge gained
from ImageNet and adapt it to the specific nuances of skin cancer detection.
Data Augmentation: This technique involves applying various transformations to the
training data, such as rotation, flipping, shifting, shearing, and zooming. Data
augmentation helps increase the diversity of the training data, allowing the model to
generalize better and handle variations in the input images.
Adam Optimization: Adam is an optimization algorithm used to update the weights
and biases of the neural network during training. It combines ideas from adaptive
learning rates and momentum methods, resulting in efficient and effective
optimization.
Categorical Cross-Entropy Loss: This is a common loss function used in multi-class
classification problems. It measures the dissimilarity between the predicted class
probabilities and the true class labels. The goal is to minimize the cross-entropy loss,
encouraging the model to make accurate predictions.
Softmax Classifier: The softmax classifier, also known as the multinomial logistic
regression, is used to assign class probabilities to input data. It is commonly used in
multi-class classification problems where there are more than two classes.
Activation Function: The softmax activation function is applied to the output layer
of the neural network model. It takes the raw class scores and converts them into
probabilities. The softmax function ensures that the predicted probabilities sum up to
1, allowing the model to make confident predictions about the input's class
membership.
Loss Function: Categorical cross-entropy loss is used as the loss function to measure
the dissimilarity between the predicted class probabilities and the true class labels. The
goal is to minimize this loss during training, encouraging the model to make accurate
predictions.

Dept of AIML MITE,MOODABIDRI Page 10


SKIN CANCER DETECTION

In summary, the main classification algorithm used in the code is the softmax
classifier, which assigns class probabilities to input data using the softmax activation
function. The model is trained to minimize the categorical cross-entropy loss, allowing
it to make accurate predictions for multi-class classification tasks.

Dept of AIML MITE,MOODABIDRI Page 11


SKIN CANCER DETECTION

Chapter 4
Performance Analysis

Precision F1 Reca Suppo


score ll rt

0.88 0.87 0.88 353


Benign

0.85 0.87 0.86 307

Malignant

- - 0.87 660

Accuracy

0.87 0.87 0.87 660


Macro Avg

0.87 0.87 0.87 660


Weighted Avg

Table 4.1 Model Analysis

Dept of AIML MITE,MOODABIDRI Page 12


SKIN CANCER DETECTION

Precision:
Benign Class (0.88): Of all instances predicted as benign, 88% were correctly
classified.
Malignant Class (0.85): Of all instances predicted as malignant, 85% were correctly
classified.

Recall (Sensitivity):
Benign Class (0.87): Of all actual benign instances, the model correctly identified
87%.
Malignant Class (0.87): Of all actual malignant instances, the model correctly
identified 87%.

F1-Score:
Benign Class (0.88): The harmonic mean of precision and recall for the benign class
is 88%.
Malignant Class (0.86): The harmonic mean of precision and recall for the malignant
class is 86%.

Support:
Benign Class (353): The number of actual instances of the benign class.
Malignant Class (307): The number of actual instances of the malignant class.
Accuracy (Overall Correct Predictions):
Accuracy (0.87): The proportion of correctly classified instances out of the total
(benign and malignant).

Macro Avg (Unweighted Average):


Macro Avg Precision (0.87): The unweighted average of precision for both classes.
Macro Avg Recall (0.87): The unweighted average of recall for both classes.
Macro Avg F1-Score (0.87): The unweighted average of F1-scores for both classes.

Weighted Avg (Weighted by Support):


Weighted Avg Precision (0.87): The average of precision, weighted by the number of
instances in each class.
Weighted Avg Recall (0.87): The average of recall, weighted by the number of
instances in each class.
Weighted Avg F1-Score (0.87): The average of F1-scores, weighted by the number of
instances in each class.

The model shows good precision, recall, and F1-score for both benign and malignant
classes.
The balanced values indicate that the model is performing well for both classes without
a significant bias towards one.

Dept of AIML MITE,MOODABIDRI Page 13


SKIN CANCER DETECTION

An accuracy of 87% suggests that the model is generally effective in classifying skin
lesions as benign or malignant.

Fig 4.1 : Accuracy Graph

Fig 4.2 : Accuracy Graph

Dept of AIML MITE,MOODABIDRI Page 14


SKIN CANCER DETECTION

Chapter 5
TESTING

5.1 Test Processes


The testing phase in your model involves evaluating the trained skin cancer detection
model's performance on a separate, previously unseen dataset. Here's a brief overview:

Data Splitting:
The dataset is split into training and testing sets using train_test_split from scikit-learn.
ImageDataGenerator : ImageDataGenerator is used for preprocessing during the
testing phase, ensuring consistency with the preprocessing applied during training.

Model Evaluation:
The trained model is evaluated on the test set using the evaluate method.
Metrics such as accuracy, loss, precision, recall, and F1-score are computed to assess
the model's performance.

Results Analysis:
The classification report is generated using scikit-learn's classification_report function,
providing detailed metrics for each class (benign and malignant).

Visualization:
Matplotlib is utilized to visualize the model's performance, including accuracy and loss
trends over epochs.

Custom Image Prediction:


A custom image is loaded and preprocessed, and the model predicts its class.
The result, including the predicted class and confidence, is displayed using Matplotlib.

5.2 Test Case


A Test Case is a software testing document, which consists of events, action, input,
output, expected result and actual result. Technically a test case includes test
description, procedure, expected result and remarks. Test cases should be based
primarily on the software requirements and developed to verify correct functionality
and to establish conditions that reveal potential errors.

Dept of AIML MITE,MOODABIDRI Page 15


SKIN CANCER DETECTION

No of Action Input Expected_ Actual_ Status


test output output
cases
Run VS Run Predicted Predicted pass
1 code images of images of
skin skin
cancer cancer

Upload Benign Skin Uploaded Uploaded pass


Image Cancer image image
2
image

Upload Malignant Uploaded Uploaded


3
image Skin image image pass
Cancer
image

Table 5.2.1 Test case for various inputs.

Dept of AIML MITE,MOODABIDRI Page 16


SKIN CANCER DETECTION

Chapter 6

RESULT & DISCUSSION

Fig 6.1

Fig 6.1 show us the section of code where we are uploading the image i.e in
custom_image_path. We can see that we have already loaded our trained mode in order
to predict the custom images.

Dept of AIML MITE,MOODABIDRI Page 17


SKIN CANCER DETECTION

Fig 6.2

Fig 6.2 shows us some custom images which are downloaded from the internet. We
are using these images for our model to make the predictions.

Dept of AIML MITE,MOODABIDRI Page 18


SKIN CANCER DETECTION

Fig 6.3
Fig 6.3 shows us the classified image after running the model. In this case we have
uploaded the image of Malignant skin cancer and as we can see, the model predicted
it correctly .

Dept of AIML MITE,MOODABIDRI Page 19


SKIN CANCER DETECTION

Chapter 7
CONCLUSION
In conclusion, the skin cancer detection project has successfully implemented a
Convolutional Neural Network (CNN) with transfer learning using ResNet50,
showcasing robust performance in classifying skin lesions as benign or malignant. The
model exhibits commendable accuracy, precision, recall, and F1-score on a diverse
dataset. The utilization of data augmentation, transfer learning, and meticulous
preprocessing contributes to the model's ability to generalize well across various
scenarios.
The project's visualizations provide insights into the model's training dynamics and
performance metrics. Additionally, the incorporation of early stopping enhances
efficiency by preventing overfitting during training. The successful deployment of the
model is demonstrated through real-time predictions on custom skin lesion images.

Future Scope :
• Fine-Tuning and Hyperparameter Optimization: Explore further fine-tuning of
hyperparameters to potentially enhance model performance.

• Additional Data Sources: Integrate data from additional sources or datasets to


increase the model's diversity and generalization.

• Ensemble Learning: Investigate the implementation of ensemble learning


techniques to combine predictions from multiple models for improved
accuracy.

• Explainability and Interpretability: Enhance model explainability and


interpretability for better understanding of decision-making processes, crucial
in medical applications.

• Clinical Validation: Collaborate with healthcare professionals to clinically


validate the model's performance in real-world settings.

• Continuous Monitoring and Updates: Implement mechanisms for continuous


monitoring and updates to adapt the model to emerging patterns and changes
in skin cancer characteristics.

• Incorporate Domain Expertise: Involve dermatologists and domain experts in


the development process to refine the model's features and enhance its clinical
relevance.

Dept of AIML MITE,MOODABIDRI Page 20


SKIN CANCER DETECTION

• Mobile Application Integration: Develop a user-friendly mobile application for


convenient and accessible skin cancer detection, promoting early diagnosis.

• Internationalization: Validate and adapt the model to diverse demographics and


skin types, ensuring its applicability on a global scale.

• Integration with Telemedicine Platforms: Integrate the model with


telemedicine platforms to facilitate remote consultations and skin cancer
screenings.

• Security and Privacy Considerations: Implement robust security and privacy


measures, especially when dealing with sensitive medical data.

Dept of AIML MITE,MOODABIDRI Page 21


SKIN CANCER DETECTION

Chapter 8

REFERENCES

Kaggle Dataset :

https://www.kaggle.com/datasets/kmader/skin-cancer-mnist-ham10000

TensorFlow Tutorial :

https://www.tensorflow.org/tutorials/images/cnn

Hands on Machine Learning :

https://www.oreilly.com/library/view/hands-on-machine-learning/9781098125967/

YouTube Tutorial :

https://youtu.be/2OXV9MiATOY?si=iayLvdpja9EqHxtD

Dept of AIML MITE,MOODABIDRI Page 22

You might also like