## 2 Methods
### Loss Function  
Incorporating prior knowledge into the loss function is important to improve segmentation accuracy and reduce the number of user interactions [25]. By observing breast tumors in ultrasound images, we found some prior knowledge that is useful for tumor segmentation. First, most tumors are actually compact contiguous domains. Some benign tumors are even closer to round or ellipse shapes. Second, the physician usually ensures that only one tumor remains on the image when saving the breast ultrasound. Even when there are two or more tumors on the image, they can be separated by cropping the image.  
Based on the above findings, we proposed a shape-aware compound loss function \(\mathcal{L}_{\text{total}}\) to incorporate prior knowledge with CNN. As defined in (8), \(\mathcal{L}_{\text{total}}\) is composed by binary cross entropy loss (\(\mathcal{L}_{\text{BCE}}\)), dice loss (\(\mathcal{L}_{\text{Dice}}\)), and shape constraint loss (\(\mathcal{L}_{\text{SC}}\)).  
\[\mathcal{L}_{\text{total}}=\mathcal{L}_{\text{BCE}}-\log(1-\mathcal{L}_{Dice} )+\omega\cdot\mathcal{L}_{\text{SC}}, \tag{8}\]  
where \(\omega\) is the weight of \(\mathcal{L}_{\text{SC}}\).  
Figure 4: The process of getting interaction points in the testing phase. (**a**) The input image with the initial segmentation (green line); (**b**) the foreground point (cyan) and background point (red) given by the user interaction; (**c**) the foreground point distance map; (**d**) the background point distance map.  
Figure 3: Examples of simulated interaction points in the training phase. The yellow and green lines are the contours of the ground truth and the previous segmentation, respectively. The cyan and red points are foreground and background interaction points, respectively.  
Here \(\mathcal{L}_{\text{SC}}\) is the loss function we used for the shape constraint:  
\[\mathcal{L}_{\text{SC}}=\frac{p^{2}}{4\pi S}, \tag{9}\]  
where \(S\) and \(P\) are the area and the perimeter of the prediction segmentation.  
When the predicted tumor shape is circular, the loss \(\mathcal{L}_{\text{SC}}\) is the minimum value of 1. Since the tumor area is compact and connected, the loss \(\mathcal{L}_{\text{SC}}\) is be greater than 1 when multiple areas are segmented or the tumor shape is dispersed. Since the shape constraint itself converges to 1 when the shape is a circle, in order to use only its compact shape constraint function without affecting the overall segmentation effect, \(\omega\) takes 0.05 here.  
Cross entropy (CE) is commonly used as a loss function in deep learning and binary cross entropy (BCE) can be used as a loss function in binary classification tasks. The formula for BCE is as follows:  
\[\mathcal{L}_{\text{BCE}}=-Y\log(X)-(1-Y)\log(1-X), \tag{10}\]  
where \(X\) and \(Y\) represent the segmentation of the method and the ground truth, respectively.  
Dice loss is a dice-based loss function. The reason why dice loss is sometimes directly used as the loss function is that the real goal of segmentation is to maximize the dice coefficient. In general, the use of dice loss has a negative impact on back propagation and tends to make the training unstable.  
\[\mathcal{L}_{\text{Dice}}=1-\text{Dice}=1-\frac{2|X\cap Y|}{|X|+|Y|}, \tag{11}\]  
where \(X\) and \(Y\) represent the same things with (10).