# DkFD: Optimizing Common Pediatric Dermatoses Detection with Novel Loss Function and Post-Processing
## 3 Preliminaries
### Loss Function  
Loss is the term used to describe the discrepancy between each sample's actual and predicted values in deep learning. The loss function, which is typically a non-negative function and can be denoted by \(L(y,f(x))\), is a function that is used to determine the loss. The impact of a model prediction is measured by the loss function; the smaller the loss, the better the trained model. The cross-entropy loss function is frequently used in deep learning classification tasks, typically in conjunction with the sigmoid or softmax function. The cross-entropy can be expressed as Equation (4) for situations involving multiple classifications. \[CE(p,q)=-\sum_{i=1}^{n}p(x_{i})\log(q(x_{i})) \tag{4}\]  
where \(p(x)\) denotes the true category probability distribution of the detection boxes and \(n\) denotes the number of categories in the dataset. With the exception of the true category chance, which is 1, all categories in the true labels have probabilities of 0. The expected probability distribution of the detection boxes is represented by \(q(x)\). As a result, sample imbalance issues such as positive and negative sample imbalance, difficult and easy sample imbalance, and sample imbalance between categories cannot be resolved by the cross-entropy because it handles all samples equally. Classical techniques such as OHEM and Focal Loss have become more popular in recent years in the study of the difficult and simple sample imbalance problem. It is inherent to OHEM to determine the loss value of each proposal box in the Fast R-CNN, rank the proposal boxes incrementally based on the loss value, and choose the top N hard samples. Only these \(N\) proposal boxes' gradients are transmitted back during back-propagation, while the gradients of the other proposal boxes are set to 0. Although OHEM can partially address the imbalance between hard and easy samples by only keeping the samples with higher loss and completely discarding the easy samples, this naturally alters the input distribution during training and results in the model losing its ability to distinguish easy samples. The Focal Loss operates on all training-proposed boxes, in contrast to the OHEM technique. Increase coefficient \(\alpha_{t}\) based on the traditional cross-entropy loss function to balance the weights of positive and negative data. The hard-easy sample weights are simultaneously adjusted by using the \((1-p_{t})^{\gamma}\) function, where \(p_{t}\) denotes the predicted probability score matching the true category of the detection box. When a box is incorrectly classified, its loss is almost unaffected, \(p_{t}\) is smaller, and \((1-p_{t})^{\gamma}\) is close to 1. The classification prediction is improved and the sample is easier to analyze when \(p_{t}\) is close to \(1\), \((1-p_{t})^{\gamma}\) is close to \(0\), and the loss is minimized. Equation (5) illustrates the suggested Focal Loss function based on these two methods, with \(p_{t}\) defined as in Equation (6). \[FL(p_{t})=-a_{t}(1-p_{t})^{\gamma}\log(p_{t}), \tag{5}\]  
\[p_{t}=\left\{ \begin{array}{cl}p_{t}&if\ y=1\\ 1-p_{t}&otherwise\end{array} \right. \tag{6}\]  
Based on the aforementioned ideas for making improvements, one of the most important ways to address the imbalance between difficult and easy samples is to adjust the weight penalty. This imbalance can be addressed by increasing the relative loss contribution of difficult samples for classifying, which will result in an increase in the penalty that the model imposes on these samples. However, at present, most researchers only consider the predicted score to measure the difficulty of object detection, without taking into account the global distribution and disregarding the obstacles caused by inter-class similarity and intra-class variability. In the dataset, if a category has a similarity with \(k\) categories, the difficulty of detection will vary with the value of \(k\).