How a CNN Machine Learning Model Can Be Used to Detect Skin Cancer

How ML + Healthcare can be combined to create a versatile tool.


In the US, 9,500 patients are diagnosed with skin cancer daily, making it the most common form of cancer in the country (American Academy of Dermatology, Skin Cancer 2022). If left untreated for too long, it can be fatal, as it can spread to tissues and bones (Vanguard Dermatology). But in low-income and rural communities, where access to healthcare is limited, there is a risk of not receiving detection and treatment in time. Fortunately, recent technology developments have led to a new application of the convolutional neural network (CNN), a machine learning model that can process image data to provide a more efficient and affordable mechanism to identify types of skin cancer. By identifying and extracting distinctive features in each skin condition, a CNN model efficiently learns features from skin cancer images and therefore provides an early, efficient, and accurate detection of skin cancer, which can ultimately save lives.

What are CNNs?

Invented in the 80s by a computer science researcher called Yann LeCun, CNNs, a popular model used in machine learning, can be used to classify images (Dickson, 2020). For example, if shown with cat and dog images, a CNN can learn each animal’s distinctive traits and classify a new image into categories of either cat or dog. In the healthcare field, CNNs can serve as early detection devices for people who may have skin cancer.

How do CNNs work to detect skin cancer?

When CNNs are fed with a dataset of skin images, the kernels of the CNNs, or matrices of numbers that serve as weights, can help determine which parts of the data are most important. When a CNN scans over a skin image, the kernel’s numbers are multiplied with the input data of the image to extract the most important features and patterns to produce an output, which is either the name of a type of skin cancer, such as melanoma, or noncancerous (Ganesh 2019).

After the images are scanned by the CNN and transformed into matrices of values, these matrices go through pooling layers to reduce image dimension sizes to scale down the complexity of CNN computations and retain only important features, such as the characteristic brown wavy shape of melanoma. These layers help the CNN model learn distinctive features of each form of skin cancer. Next, a ReLU, or Rectified Linear Unit, is added to introduce nonlinearity in the CNN model in order to better classify the skin images. Afterward, the flatten layer flattens the matrices of values into a one-dimensional shape and utilizes the fully connected layer to combine all the features the model learned together. Lastly, the softmax activation function, after transforming the numeric values into probabilities that sum to one, produces the highest probable value, which maps to the corresponding category of the skin image (Raghav 2019 and Sammy and Anurag 2019).

Figure 1: the CNN scans a car image; in this case, the correct output is car.

How can people use CNNs in real-time?

When a CNN model is trained on a skin cancer dataset to detect and classify different types of skin cancers with above 90% accuracy, it can be deployed into a web or mobile app, where patients can take a picture of their skin condition and upload it to the app to see the identification and classification output. The app can be accessible and free for patients around the world to receive an early and efficient detection at home.

How does the CNN model improve survival rates, save lives, and reduce costs?

Early detection of cancer is extremely critical for patients’ survival rates. CNNs can be trained and set up easily to help patients detect and keep track of any skin condition that emerges, providing a quick and early detection of potentially dangerous skin conditions that then allows patients to seek subsequent and necessary medical procedures promptly to increase survival rate. Early detection of cancer also reduces the overall medical cost that would have incurred if patients were to be treated for later stages of cancers. Thus, CNNs would not only be more affordable to patients but also free up health care resources in communities to focus more on health promotion and disease prevention.


With the advent of machine learning technology and the extensive research into its applications, CNNs have become a more convenient and affordable solution to detect skin cancer at home. A recent paper by Telkom University researchers recorded a staggering 99% skin cancer classification accuracy with a CNN (Fu’adah et al., 2020). An accurate CNN model like this can be commercialized to help reduce skin cancer fatality and preserve lives, as it provides a convenient and affordable tool for early detection, especially for people who need it the most in rural and low-income communities, especially during the current COVID pandemic.


Dickson, Ben, et al. “What Are Convolutional Neural Networks (CNN)?” TechTalks, 6 Jan.


Fu’adah, Yunendah Nur, et al. “Convolutional Neural Network (CNN) for Automatic Skin

Cancer Classification System.” IOP Conference Series: Materials Science and Engineering. Vol. 982. №1. IOP Publishing, 2020.

Ganesh, Prakhar. “Types of Convolution Kernels : Simplified.” Medium, Towards Data Science,

18 Oct. 2019,

“How Cancer Is Diagnosed.” National Cancer Institute,

Raghav, Prabhu. “Understanding of Convolutional Neural Network (CNN) — Deep Learning.”

Medium, Medium, 21 Nov. 2019,

Sammy and Anurag. “How to Implement the Softmax Function in Python.” Intellipaat

Community, 18 Sept. 2019,

“Skin Cancer.” American Academy of Dermatology,,skin%20cancer%20in%20their%20lifetime.&text=It%20is%20estimated%20that%20approximately,with%20skin%20cancer%20every%20day.

“Skin Cancer Facts & Statistics.” The Skin Cancer Foundation, 8 Mar. 2022,

“The Dangers of Leaving Skin Cancer Untreated.” Vanguard Dermatology,



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
technojules/Julia Huang

technojules/Julia Huang


Student and aspiring coder and musician. Has interests in both tech and music.