# Skin Cancer Classification Using Fine-Tuned Transfer Learning of DENSENET-121
## 3 Materials and Methods
### Model Flow Chart
#### 3.3.6 Fine-Tuned DenseNet-121 (Proposed Model)  
In the realm of skin cancer classification, transfer learning techniques offer a compelling advantage by leveraging pretrained neural network models, such as DenseNet-121, ResNet-34, and VGG-16, which have been trained on large datasets like ImageNet. This approach capitalizes on the knowledge learned from these diverse datasets, enabling the models to extract meaningful features from skin lesion images and thus improve classification accuracy [31]. By transferring the learned representations to the task of skin cancer classification, these models can effectively distinguish between benign and malignant lesions, contributing to early detection and improved patient outcomes.  
Earlier techniques in skin cancer classification have been constrained by several limitations. Traditional machine learning approaches often rely on handcrafted features, which may not adequately capture the complex patterns present in skin lesion images. Additionally, these methods may struggle with scalability and generalization to unseen data due to their fixed feature extraction processes [32].  
DenseNet-121 adopts an approach wherein each layer is connected to every other layer in a forward manner. Unlike traditional convolutional networks, which have only one connection between each layer and its subsequent layer, DenseNet-121 forms direct connections that total \(L(L+1)/2\), where \(L\) is the number of layers. In DenseNet-121, each layer receives the feature maps from all preceding layers as inputs and also passes its own feature maps to all subsequent layers. This design choice brings several advantages. Firstly, it mitigates the vanishing-gradient problem that can hinder the training of deep networks. Secondly, it promotes effective feature propagation throughout the network. Thirdly, it encourages feature reuse, enabling efficient information flow. Finally, it significantly reduces the number of parameters, making it a computationally efficient architecture [33]. It was then fine-tuned by adding one flatten layer and three dense layers. The first dense layer has 32 neurons with a LeakyReLU activation function, while the second dense layer has 16 neurons with a LeakyReLU activation function, and the output dense layer has one neuron with a sigmoid activation function. The model was trained on 1,606,209 parameters and the epochs were reduced to 20; additionally, the DenseNet-121 architecture itself offers regularization benefits by mitigating the vanishing gradient problem and promoting efficient feature reuse throughout the network. These architectural choices, combined with the use of LeakyReLU activation functions in the dense layers, were helpful for faster training and preventing overfitting, allowing the model to achieve better accuracy than if it were trained for more epochs, where overfitting might occur. Additionally, the model takes only a few seconds to run. The pretrained DenseNet-121 extracts features from the  
\begin{table}
\begin{tabular}{l l l} \hline
**Layer** & **Output Shape** & **Parameters Trained** \\ \hline ResNet-34 & (None, 7, 7, 2048) & 23,587,712 \\ Flatten & (None, 100,352) & 0 \\ Dense\_1 & (None, 32) & 3,211,296 \\ LeakyReLU\_1 & (None, 32) & 0 \\ Dense\_2 & (None, 16) & 528 \\ LeakyReLU\_2 & (None, 16) & 0 \\ Dense\_3 & (None, 1) & 17 \\ \hline
**Total Parameters** & & 26,799,553 \\
**Trainable Parameters** & & 3,211,841 \\
**Nontrainable Parameters** & & 23,587,712 \\ \hline \end{tabular}
\end{table}
Table 6: Parameters of fine-tuned ResNet-34.  
input image and transfers them to the layers to classify the skin lesion as either benign or malignant. The model parameters are shown in Table 7.  
The fine-tuned DenseNet-121 model underwent training for 20 epochs using the Adam optimizer with a batch size of 64. The activation function employed for the output dense layer was sigmoid, and binary cross-entropy served as the designated loss function.