## 3 Materials and Methods
### Loss Function  
In this study, we use a hybrid loss function that consists of three components: supervised training losses for both segmentation models(HTCSNet-1 and HTCSNet-2) using labeled data (Loss-sup), CPS loss applied to all data (Loss-cps), and contrastive learning loss for unlabeled data (Loss-sim). For the supervised training losses using labeled data, the outputs from the HTCSNet-1 and HTCSNet-2 are matched against the ground truth to calculate Loss-sup\({}_{1}\) and Loss-sup\({}_{2}\). These losses are computed using a composite loss, which integrates a weighted Intersection over Union (IoU) loss and a weighted Binary Cross-Entropy (BCE) loss. The supervised training loss is defined as in Equations (1)-(3). \[\text{Loss-sup}_{1} =\text{Loss}^{W}_{\text{IoU}_{1}}+\text{Loss}^{W}_{\text{BCE}_{1}} \tag{1}\] \[\text{Loss-sup}_{2} =\text{Loss}^{W}_{\text{IoU}_{2}}+\text{Loss}^{W}_{\text{BCE}_{2}}\] (2) \[\text{Loss-sup} =\text{Loss-sup}_{1}+\text{Loss-sup}_{2} \tag{3}\]  
For the CPS loss, all data are fed into two models, each followed by a sigmoid activation function, to obtain their respective segmentation predictions as pseudo-labels (\(S_{i}\)(i = 1,2)), which can be used as a supervisory signal for the other network. Different from the supervised training losses, the cross-pseudo supervision loss (Loss-cps)uses cross-pseudolabels of both networks as the true labels. Loss-cps can also be determined by combining a weighted IoU loss with a weighted BCE loss. Loss-cps is calculated as in Equations (4)-(6). \[\text{Loss-cps}_{1} =(\text{Loss}_{\text{IoU}_{1}}^{\text{w}}+\text{Loss}_{\text{ BCE}_{1}}^{\text{w}})_{\text{S}_{2}} \tag{4}\] \[\text{Loss-cps}_{2} =(\text{Loss}_{\text{IoU}_{2}}^{\text{w}}+\text{Loss}_{\text{ BCE}_{2}}^{\text{w}})_{\text{S}_{1}}\] (5) \[\text{Loss-cps} =\text{Loss-cps}_{1}+\text{Loss-cps}_{2} \tag{6}\]  
In the context of patch-wise contrastive learning, unlabeled data are fed into two distinct models, HTCNet-1 and HTCNet-2, to generate polyp distribution maps. These maps are then processed by projectors to obtain high-level semantic representations of the polyp images. When the same polyp image is transformed using both HTCNet-1, HTCNet-2, as well as two projectors, the high-level features produced are expected to be consistent. Therefore, patch-wise contrastive loss (Loss-sim) is employed to measure their similarity, with the calculation of Loss-sim detailed in Equation (7). \[\text{Loss-sim}=-\log\frac{\exp(\text{p}\cdot\text{p}^{+}/\tau)}{\exp(\text{ p}\cdot\text{p}^{+}/\tau)+\sum\exp(\text{p}\cdot\text{p}^{-}/\tau)} \tag{7}\]  
Here, (\(\text{p}\cdot\text{p}^{+}\)) and (\(\text{p}\cdot\text{p}^{-}\)) denote positive and negative sample pairs, respectively, representing feature representations from projector-1 and projector-2 at the same position and at different positions. In the experiments, we set \(\tau\) as the temperature coefficient to 0.07. The SemiPolypSeg framework, designed for the segmentation of polyps, harnesses the power of both labeled and unlabeled data for learning. For the labeled data, the loss is composed of the supervised training loss and the cross-pseudo supervision loss; For the unlabeled data, the loss is composed of the contrastive learning loss and the CPS loss. By progressively minimizing the total loss using gradient descent throughout the training process, the model achieves optimal segmentation performance. The total loss (**Loss-Total**) is determined by Equation (8). \[\text{Loss-Total}=\lambda\cdot\text{Loss-sup}+\beta\cdot\text{Loss-cps}+\gamma \cdot\text{Loss-sim} \tag{8}\]  
where \(\lambda\), \(\beta\), and \(\gamma\) are the weights of the supervised training losses, the cross-pseudo supervision loss, and the patch-wise contrastive learning loss, which are hype parameters. Considering the importance and scarcity of labeled data, we assigned a higher weight (\(\lambda\)) to the supervised loss to ensure that the model effectively leverages this valuable resource, which is crucial for learning accurate representations.