## 2 Method
### Weakly Supervised Loss Construction
#### 2.4.2 Color Similarity Loss  
Although projection loss is able to constrain the prediction mask to be within the true bounding box, further accurate segmentation of the pixel-wise instances inside the bounding box is hardly to be achieved. The color similarity loss [32] is introduced to obtain finer masks in the bounding box. The principle of color similarity loss is to calculate the color similarity between the pixel and its surrounding pixel and divide the pixel by a color similarity threshold. Then, the consistency classification of foreground or background is constrained by the pixel categories divided by color similarity in the image.  
Color similarity loss is used to constrain the classification of the image foreground or background consistency so that the image pixels have the consistency of the foreground or background in the area of similar color and the instance targets in the bounding box are more accurately distinguished. As illustrated in Figure 6, first, an undirected graph \(G=(V,E)\) is constructed on the image, where \(V\) is the sum of all the pixels in the image and E is the sum of all the edges in the image. The color similarity loss is calculated by combining the probability of foreground or background consistency predicted by pairs of pixels with the category of pixel determined by color similarity. During calculation, each pixel is connected with its surrounding 8 pixels. In order to increase the receptive field and make the calculation range of color similarity between pixels larger, the method of interval pixel sampling is used.  
Figure 5: Diagram of the projection loss.  
Firstly, an edge is defined as e, and \(y_{e}\) is the label of edge \(E\). When \(y_{e}=1\), the two pixels connected by edge \(e\) have the same true value label, which means that the two pixels are both foreground or background. When \(y_{e}=0\), it means that two pixels have different labels, one for foreground and the other for background. Pixels (\(c\), \(d\)) and (\(e\),\(f\)) for the edge pixels are at the ends of the e, so network prediction \(m_{c,d}\) can be seen as pixel (\(c\), \(d\)) is the prospect of probability. The same \(m_{e,f}\) can be said for (\(e\),\(f\)) as the prospect of probability. Then, the probability calculation \(y_{e}=1\) can be expressed as follows:  
\[P(y_{e}=1)=m_{c,d}\cdot m_{e,f}+(1-m_{c,d})\cdot(1-m_{e,f}) \tag{10}\]  
and the probability \(y_{e}=0\) is calculated as follows:  
\[P(y_{e}=0)=1-P(y_{e}=1) \tag{11}\]  
Generally, the predicted probability distribution of the network can be trained with a binary cross-entropy loss, so the loss function can be expressed as  
\[\begin{split} L_{cs}&=-\frac{1}{N}\sum_{e\in E_{ in}}y_{e}\log P(y_{e}=1)\\ &+(1-y_{e})\log P(y_{e}=0)\end{split} \tag{12}\]  
Among them, \(E_{in}\) represents the set of edges that contain at least one pixel in the box. \(E_{in}\) is used instead of the set of all edges \(E\) to avoid the loss calculation being affected by other irrelevant pixels outside the bounding box, which causes the color similarity loss to not properly constrain the prediction mask. N is the number of edges in \(E_{in}\) inside the box. Loss function formula contains the color similarity \(y_{e}=1\), and \(y_{e}=0\) is the sum of two cases of loss, but in practice, when \(y_{e}=0\) is the label for unknown edges, it is easy to cause the network to distinguish the background of the target with error constraints. As a result, the accuracy of the prediction mask decreases, so the loss function in the case of \(y_{e}=0\) is partially eliminated when using the color similarity loss, and the final color similarity loss function is obtained as follows:  
\[L_{cs}=-\frac{1}{N}\sum_{e\in E_{in}}y_{e}\log P(y_{e}=1) \tag{13}\]  
Figure 6: Diagram of the color similarity loss.