## 3 Materials and Methods  
### Outline of the SemiPolypSeg Framework  
Although pixel-level labeling of polyp images requires significant effort and time, unlabeled polyp images are readily available. We propose an SSL framework leveraging CPS and patch-wise contrastive learning for polyp segmentation, utilizing unlabeled images alongside a small set of finely labeled images, aiming to derive more valuable and insightful information from the unlabeled data. The framework considers the combined loss from a limited set of labeled data and a substantial amount of unlabeled data during training, which greatly enhances the model's adaptability. Figure 1 illustrates the SemiPolypSeg framework, which comprises three main components: Hybrid Transformer-CNN Segmentation Networks (HTCSNet-1 and HTCSNet-2), projectors (project-1 and projector-2), and a hybrid loss function. The framework reduces reliance on labeled data by leveraging a large volume of unlabeled data alongside a small subset of labeled data for joint training. Figure 1: General structure of the proposed SSL framework (SemiPolypSeg). Consider the labeled set \(X_{n}^{L}=\{(x_{1}^{L},y_{1}^{L}),\ldots,(x_{n}^{L},y_{n}^{L})\}\), where each pair \((x_{i}^{L},y_{i}^{L})\) includes an image \(x_{i}^{L}\in\mathbb{R}^{C\times H\times W}\) and its corresponding ground truth mask \(y_{i}^{L}\in\{0,1\}^{H\times W}\). Additionally, let \(X_{m}^{U}=\{u_{i}\}_{i=1}^{m}\) represent a set of m unlabeled images, where \(u_{i}\in\mathbb{R}^{C\times H\times W}\) and \(m\gg n\). The main objective is to develop a segmentation model using the combined dataset \(X_{All}=(X_{n}^{L}\cup X_{m}^{U})\). Throughout the training process, the entire dataset \(X_{All}\) undergoes various perturbations for both weak and strong data augmentation. The augmented labeled and unlabeled data are subsequently fed into HTCSNet-1 and HTCSNet-2, with each initialized using distinct parameters, to independently generate their predictions. For additional contrastive learning, the predictions are input into projectors (projector-1 and projector-2) for all unlabeled data. During inference, we can input polyp images into any segmentation network model to achieve segmentation results without needing projectors. Our study introduces a novel loss function composed of supervised segmentation loss, feature consistency loss (CPS loss), and patch-wise contrastive loss (similarity loss)--aimed at enhancing model convergence. \(X_{n}^{L}\) with weak data augmentation, including rotations and flips, are input to HTCSNet-1 and HTCSNet-2, computing \(P1_{n}^{L}\) and \(P2_{n}^{L}\). We then apply the activation function (sigmoid) to generate the respective polyp segmentation outputs maps \(S1_{n}^{L}\) and \(S2_{n}^{L}\). The supervised losses for HTCSNet-1 and HTCSNet-2 are determined by the differences between \(S1_{n}^{L}\), \(S2_{n}^{L}\), and \(Y_{n}^{L}\). After undergoing strong data augmentation, including rotations, flips, affine transformations, random grayscale noise, Gaussian blur, color jittering, and GridMask [62], \(X_{All}\) is fed into different segmentation networks. This process generates the corresponding polyp probability distribution predictions \(P1_{All}\) and \(P2_{All}\). The polyp segmentation maps \(S1_{All}\) and \(S2_{All}\) are derived from \(P1_{All}\) and \(P2_{All}\) using the sigmoid activation function. These maps, \(S1_{All}\) and \(S2_{All}\), serve as pseudo-labels and are compared to calculate the CPS loss for both networks. All unlabeled images \(X_{m}^{U}\) with strong data augmentation are fed into HTCSNet-1 and HTCSNet-2 to obtain \(P1_{m}^{U}\) and \(P2_{m}^{U}\). Then, the feature representations \(\text{Pro}(P1_{m}^{U})\) and \(\text{Pro}(P2_{m}^{U})\) are extracted through projector modules \(\{Pro_{i}(\cdot)\}_{i=1}^{2}\). Finally, patch-wise contrastive loss is employed to maximize feature variations at disparate spatial locations and minimize feature variations at matching spatial locations between \(\text{Pro}(P1_{m}^{U})\) and \(\text{Pro}(P2_{m}^{U})\).