# How Deeply to Fine-Tune a Convolutional Neural Network: A Case Study Using a Histopathology Dataset
## 3 Methodology
### Convolutional Neural Networks  
Formally, in supervised machine learning given a training dataset of \(\Phi\ =\ \{(x_{i},y_{i})\}_{i=1}^{N}\), where \(N\) is the training dataset size and \((x_{i},y_{i})\) is a single training example, \(x_{i}\in\Phi\) is the training images and \(y_{i}\in\Phi\) is the respective label of each image \(x_{i}\), \(\theta\) is the model parameters and \(\hat{y}_{i}\) is the predicted label using the function \(f(x_{i};\theta)\). The purpose of training a machine learning classifier can be described as minimizing the loss function \((1)\):  
\[L\ =\ \frac{1}{N}\sum_{i=1}^{N}L_{i}(f(x_{i};\theta),y_{i}) \tag{1}\]  
where, in classification problems, the loss function used is the cross-entropy loss function, which can be formally defined as in Equation (2):  
\[L(\hat{y}_{i},y_{i})\ =\ -\sum_{i=1}^{N}y_{i}(N)\log\hat{y}_{i}(N) \tag{2}\] \begin{table}
\begin{tabular}{c c c c c c} \hline \hline
**Paper** & **Dataset Name** & **Dataset Size** & **Architectures** & **Classes** & **Best Accuracy** \\ \hline [PERSON] et al. [17] & BreakHis [18] & 7909 & \begin{tabular}{c} VGG16 \\ VGG19 \\ ResNet50 \\ \end{tabular} & Binary & 92.6\% \\ [PERSON] et al. [31] & BiolImaging [23] & 260 & \begin{tabular}{c} AlexNet \\ GoogleNet \\ ResNet50 \\ \end{tabular} & Multiclass & 85\% \\ [PERSON] et al. [30] & BreakHis [18] & 7909 & \begin{tabular}{c} AlexNet \\ VGG16 \\ ResNet50 \\ \end{tabular} & Binary & 91.37\% \\ [PERSON] et al. [27] & [PERSON] [22] & 400 & \
\begin{tabular}{c} InceptionV3 \\ ResNet50 \\ \end{tabular} & Multiclass & 97.50\% \\  & PatchCamelyon [21] & 327,680 & Ensemble of: & & 94.64\% \\ [PERSON] et al. [19] & BreakHis [18] & 7909 &
\begin{tabular}{c} VGG19 \\ DenseNet \\ ImageNet \\ \end{tabular} & Binary & 98.13\% \\  & Biolmaging [23] & 249 & ImageNet & & 83.10\% \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Summary of the studies mentioned. given that \(\hat{y}_{i}\ =\ f(x_{i};\theta)\). For binary classification, the cross-entropy loss function can be defined as in Equation (3):  
\[L_{\text{BCE}}(\hat{y}_{i},y_{i})\ =\ -\frac{1}{N}\sum_{i\ =\ 1}^{N}\left[y_{i}\log\hat{y}_ {i}+(1-y_{i})\log(1-\hat{y}_{i})\right] \tag{3}\]  
The convolution operation that composes the convolution layer is a mathematical operation that combines two signals, which can be formally defined as in Equation (4):  
\[o[u,v]\ =\ f[m,n]\star g[u,v]\ =\ \sum_{m}\sum_{n}f[m,n]\ \odot g[u+m,v+n] \tag{4}\]  
where \(f[m,n]\) is the convolution filter, \(g[u,v]\) is the input image, and \(o[u,v]\) is the output feature map. The convolution operation is shown in Figure 2.  
The convolution layers convolve the input images with a small grid shape called the kernel, or convolution filter, starting from the top left corner of the image, as shown in Figure 3. The convolution filter is used to extract important features from the input images that will help in classifying the images. The weights of the convolution filter are the most important in the CNN, which will be learned from the iterative nature of the backpropagation algorithm. Many filters will be used to extract as many features from the images as possible to be able to correctly classify the images. The result of convolving the filter over the input image will produce a matrix that is called a feature map, where it can be considered as a reduced image that will be used instead of the original image in the subsequent layers. Many feature maps will be outputted from the filters used, every one of these maps will capture different features from each image, and these features will be used to correctly classify the images [19]. The backpropagation algorithm is used to tune the weights of the CNN by updating the weights from the last layers to the first. To protect the CNN from vanishing or exploding gradients, the weights of the CNN are initialized with a certain distribution and not from zero. The weights of the network can be transferred from one to another to avoid initializing the weights from scratch. Figure 3: Convolution filter to extract features.