# Semi-Supervised Medical Image Classification Based on Attention and Intrinsic Features of Samples
## 3 Method
### Semi-Supervised Learning Framework  
The semi-supervised loss function [18; 30] previously used for classification tasks can be divided into two parts: the supervised loss of labeled samples and the unsupervised consistency loss of total samples. We express labeled datasets and unlabeled datasets as \(\text{S}_{\text{L}}=\left\{\left(\text{x}^{\text{i}},\text{y}^{\text{i}}\right) \right\}_{\text{i=1}}^{\text{N}}\) and \(\text{S}_{\text{U}}=\left\{\text{x}^{\text{i}}\right\}_{\text{i=N+1}}^{\text{ N+M}}\), respectively, where \(\text{x}^{\text{i}}\) is an inputted two-dimensional medical image, such as a skin lesion image or a chest disease image, and \(\text{y}^{\text{i}}\) is an artificially marked image real label using one-hot coding. The overall optimization objectives of the whole framework are as follows:  
\[\min_{\theta}\left(\sum\
olimits_{\text{i=1}}^{\text{N}}\text{L}_{\text{S}}( \text{f}(\text{x}_{\text{i}};\theta),\text{y}_{\text{i}})+\lambda\text{L}_{ \text{U}}\left(\left\{\text{x}^{\text{i}}\right\}_{\text{i=N+1}}^{\text{N+M} };\text{f}(\cdot),\theta,\eta,\theta^{\prime},\eta^{\prime}\right)\right) \tag{10}\]  
where \(\text{L}_{\text{S}}\) represents the supervised loss (cross-entropy loss) of labeled samples, \(\text{L}_{\text{U}}\) represents the unsupervised consistency loss of total samples, \(\text{f}(\cdot)\) represents the classification network, \(\theta\) and \(\theta^{\prime}\) are the parameter weights of the student model and teacher model, respectively, and \(\eta\) and \(\eta^{\prime}\), respectively, represent two different disturbances of the two models with the same input. \(\lambda\) is a weighting factor used to weigh the supervised loss against the unsupervised loss. Its teacher model parameter weight \(\theta^{\prime}\) is the exponential average of the student model weight \(\theta\), and the iterative training of teacher model weight with time is defined as:  
\[\theta^{\prime}_{\text{t}}=\text{a}\theta^{\prime}_{\text{t-1}}+(1-\text{a}) \theta_{\text{t}} \tag{11}\]  
where a is the smoothing coefficient super-parameter that controls the weight update rate. In terms of unsupervised loss, to encourage the consistency of the outputs of the student model and the teacher model, we keep the traditional individual consistency mechanism [29] as follows:  
\[\text{L}_{\text{u}}=\sum\
olimits_{\text{i=1}}^{\text{N+M}}\text{E}_{\eta, \eta^{\prime}}\parallel\text{f}\left(\text{x}_{\text{i}},\theta^{\prime}, \eta^{\prime}\right)-\text{f}(\text{x}_{\text{i}},\theta,\eta)\parallel_{2}^ {2} \tag{12}\]  
In terms of supervision loss, focal loss [31] is defined as follows:  
\[\text{FL}(\text{p}_{\text{t}})=-(1-\text{p}_{\text{t}})^{\gamma}\log(\text{p}_ {\text{t}}) \tag{13}\]  
\(\text{P}_{\text{t}}\) is set to:  
\[\text{P}_{\text{t}}=\left\{ \begin{array}{ll}\text{P}&\text{if y}=1\\ 1-\text{P}&\text{otherwise}\end{array} \right. \tag{14}\]  
\(\text{P}_{\text{t}}\) marks the predicted probability value of the sample. In Figure 3, we introduce the super-parameter threshold on the basis of focal loss. Compared with this, the supervision loss is defined as follows:  
\[\text{L}_{\text{t}}=\left\{ \begin{array}{ll}\text{W}_{\text{C}}\times\text{ L}_{-}\text{w}\ \times\ (\ -\log(\text{p}_{\text{t}}))&\text{otherwise}\\ \text{W}_{\text{C}}\times\text{H}_{-}\text{w}\ \times\ (\ -\log(\text{p}_{\text{t}}))&\text{if $\text{p}_{\text{t}}>$ threshold}\end{array} \right. \tag{15}\]  
where \(\text{L}_{-}\text{w}=1\) and \(\text{H}_{-}\text{w}=(1-\text{p}_{\text{t}})^{\gamma}\), respectively, represent the weights that should be given to the samples with wrong classification and correct classification.