# An Improved Small Target Segmentation Model Based on Mask Dino
## 3 Materials and Methods
### Improvement of Swin Transformer
#### 3.1.2 Log-Cpb Method  
During the segmentation process, small objects [28] in images are usually scarce and not prominently displayed. It is difficult for small object features to be passed to deeper layers of the network during parameter transmission. Moreover, as the model learns, information fitting for small objects tends to become excessive, leading to incorrect classifications. To address these issues [15], this paper introduces the log-cpb method to adjust the model's emphasis on minority classes, thereby mitigating the learning bias caused by class imbalance. The log-CPB method modifies the output probability distribution of the model by taking the logarithm of the probabilities for each class and applying a bias factor that depends on the frequency of the class or other prior knowledge. This approach highlights the importance of minority classes and adjusts the loss function to emphasize them, making the model more inclined to recognize and correctly classify small objects during training.  
The following is the process of implementing the log-CPB method:  
1. Calculating weights: Define the weight for each class, which is typically proportional to the inverse frequency of the class. That is, classes that appear less frequently (minority classes) are assigned higher weights. The weights can be calculated using the following formula.The formula is as shown in Equation (3) below: \[\omega_{\text{i}}=\log\left(\frac{1}{\text{p}_{\text{i}}}+\text{e}\right)\] (3)  
\(\text{P}_{\text{i}}\) is the relative frequency of class i, and \(\text{e}\) is a small constant to avoid division by zero. The continuous position bias method does not directly optimize the parameterized bias, but instead adopts a small meta-network on the relative coordinates.The formula is as shown in Equation (4) below: \[\text{B}(\Delta x,\Delta y)=\mathcal{G}(\Delta x,\Delta y)\] (4) where \(\mathcal{G}\) is a small network. By default, there is a ReLU activation between two MLP layers, and the network generates bias values for any relative coordinates.  
Adjusting category weights: By applying a logarithmic transformation to the coordinate system, small object features are magnified in the transformed coordinate system. This allows the model to more easily capture these subtle changes, enhancing its ability to process small-scale features and thereby improving the detection accuracy and segmentation effects of small objects. Therefore, this paper replaces the original linear interval coordinates with logarithmic interval coordinates.The formula is as shown in Equation (5) below:  
\[\begin{array}{l}\widehat{\Delta x}=sign(x)\cdot\log\left(1+|\Delta x|\right) \\ \widehat{\Delta y}=sign(y)\cdot\log(1+|\Delta y|)\end{array} \tag{5}\]  
where \(\widehat{\Delta x}\), \(\widehat{\Delta y}\) and \(\Delta x\), \(\Delta y\) are the logarithmic interval coordinates, and are the linear scaling coordinates. In this method, the image's coordinate system is remapped so that the coordinate intervals grow on a logarithmic scale. This causes the image coordinate intervals to increase with resolution enhancement, making the details around small objects more prominent and recognizable. This enhances the model's sensitivity to small-scale features.  
3. Adjusting the backbone network's loss function: The aforementioned weights are integrated into the loss calculation for the Swin Transformer. For classification tasks that use cross-entropy, the loss function will be adjusted as follows, The formula is as shown in Equation (6) below:  
\[\begin{array}{l}\mathrm{L}=-\sum_{i=1}^{\mathbbm{C}}\omega_{i}y_{i}\log \hat{y}_{i}\end{array} \tag{6}\]  
where \(\mathbbm{C}\) is the total number of classes, \(y_{i}\) is the real class label of each pixel (one-hot encoding), and \(\hat{y}_{i}\) is the predicted class probability.