Melanoma standing out as the most lethal type of skin cancer. This gives the CNN model to detect it.
To build a CNN based model which can accurately detect melanoma.
The break down of the final provided CNN architecture step by step:
-
Data Augmentation: The
augmentation_data
variable refers to the augmentation techniques applied to the training data. Data augmentation is used to artificially increase the diversity of the training dataset by applying random transformations such as rotation, scaling, and flipping to the images. This helps in improving the generalization capability of the model. -
Normalization: The
Rescaling(1./255)
layer is added to normalize the pixel values of the input images. Normalization typically involves scaling the pixel values to a range between 0 and 1, which helps in stabilizing the training process and speeding up convergence. -
Convolutional Layers: Three convolutional layers are added sequentially using the
Conv2D
function. Each convolutional layer is followed by a rectified linear unit (ReLU) activation function, which introduces non-linearity into the model. Thepadding='same'
argument ensures that the spatial dimensions of the feature maps remain the same after convolution. The number within eachConv2D
layer (16, 32, 64) represents the number of filters or kernels used in each layer, determining the depth of the feature maps. -
Pooling Layers: After each convolutional layer, a max-pooling layer (
MaxPooling2D
) is added to downsample the feature maps, reducing their spatial dimensions while retaining the most important information. Max-pooling helps in reducing computational complexity and controlling overfitting. -
Dropout Layer: A dropout layer (
Dropout
) with a dropout rate of 0.2 is added after the last max-pooling layer. Dropout is a regularization technique used to prevent overfitting by randomly dropping a fraction of the neurons during training. -
Flatten Layer: The
Flatten
layer is added to flatten the 2D feature maps into a 1D vector, preparing the data for input into the fully connected layers. -
Fully Connected Layers: Two fully connected (dense) layers (
Dense
) are added with ReLU activation functions. The first dense layer consists of 128 neurons, and the second dense layer outputs the final classification probabilities for each class label. -
Output Layer: The number of neurons in the output layer is determined by the
target_labels
variable, representing the number of classes in the classification task. The output layer does not have an activation function specified, as it is followed by the loss function during training. -
Model Compilation: The model is compiled using the Adam optimizer (
optimizer='adam'
) and the Sparse Categorical Crossentropy loss function (loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
), which is suitable for multi-class classification problems. Additionally, accuracy is chosen as the evaluation metric (metrics=['accuracy']
). -
Training: The model is trained using the
fit
method with the specified number of epochs (epochs=50
). TheModelCheckpoint
andEarlyStopping
callbacks are employed to monitor the validation accuracy during training. TheModelCheckpoint
callback saves the model with the best validation accuracy, while theEarlyStopping
callback stops training if the validation accuracy does not improve for a specified number of epochs (patience=5 in this case). These callbacks help prevent overfitting and ensure that the model converges to the best possible solution.
-
Dataset https://drive.google.com/file/d/1xLfSQUGDl8ezNNbUkpuHOYvSpTyxVhCs/view
-
UpGrad tutorials on Convolution Neural Networks (CNNs) on the learning platform
Created by @hkatarki