A Semi-Supervised Classification Method of Apicomplexan Parasites and Host Cell Using Contrastive Learning Strategy

A common shortfall of supervised learning for medical imaging is the greedy need for human annotations, which is often expensive and time-consuming to obtain. This paper proposes a semi-supervised classification method for three kinds of apicomplexan parasites and non-infected host cells microscopic images, which uses a small number of labeled data and a large number of unlabeled data for training. There are two challenges in microscopic image recognition. The first is that salient structures of the microscopic images are more fuzzy and intricate than natural images' on a real-world scale. The second is that insignificant textures, like background staining, lightness, and contrast level, vary a lot in samples from different clinical scenarios. To address these challenges, we aim to learn a distinguishable and appearance-invariant representation by contrastive learning strategy. On one hand, macroscopic images, which share similar shape characteristics in morphology, are introduced to contrast for structure enhancement. On the other hand, different appearance transformations, including color distortion and flittering, are utilized to contrast for texture elimination. In the case where only 1% of microscopic images are labeled, the proposed method reaches an accuracy of 94.90% in a generalized testing set.


I. INTRODUCTION
Apicomplexans comprise a group of intracellular protozoan parasites, including Plasmodium, Babesia, and Toxoplasma, which are amongst the most prevalent and morbiditycausing pathogens in humans and animals worldwide, and they live inside host cells Erythrocytes. Plasmodium is the causative agent of malaria, which impacts over 200 million individuals and kills over 300,000 children annually. Babesiosis caused by Babesia is a disease with many clinical features that are similar to those of malaria. Toxoplasma is estimated to infect one-third of the world's population, which is the leading cause of infectious retinitis in children and is life-threatening in pregnancy and to the immunocompromised [1].
The risk of illness and death could be significantly reduced with accurate and affordable diagnostic testing. Measuring parasite infection by direct microscopy observation remains relatively widespread as a point-of-care diagnostic in clinical and epidemiological settings [2].
Recently, deep learning techniques become a popular choice in both computer vision and the medical imaging community [3]. For parasites and Erythrocytes recognition, deep learning models have obtained impressive results. A *The authors are with the Graduate School of Information, Production and Systems, Waseda University, Kitakyushu-shi, 808-0135 Japan.
deep learning model using hand-craft features in the shape to classify healthy and abnormal Erythrocytes [4]. Wellknown Convolutional Neural Networks (CNNs), including Inception v3 [5], LeNet, AlexNet and GoogLeNet [6], are used to identify Plasmodium parasites. Furthermore, a solution for multiple apicomplexan parasites and Erythrocytes [7] is given based on the fact that Toxoplasma, Babesia, Plasmodium, and Erythrocyte are variant in morphology under microscopy. However, the outlined methods have been designed in the prerequisite that all the training data has accurate human annotations. In practical clinical scenarios, lack of labels and annotations is a common and fatal problem [8] due to the shortage of specialists in diagnostic imaging despite the increasing spread of equipment.
In addition, there are two challenges for microscopic image recognition. The first is that salient structures of microscopic images are more fuzzy and intricate than realworld objects', which leads to that microscopic images are not as distinguishable as real-world images. The second is that insignificant textures, like image background staining, lightness, or contrast level, are variant a lot in samples from different clinical scenarios, while the available training data [9] is of a similar pattern in each category, which may lead to poor generalization in the real-world application.
In this paper, we propose a semi-supervised learning (SSL) solution for the classification of apicomplexan parasites and host cell microscopic images, considering that a small number of reliable annotations are relatively affordable and it is easy to acquire a large amount of unlabeled data. The proposed method contains data pre-processing, a CNNbased feature extractor, and a multilayer perceptron (MLP) classifier.
To address these challenges, we learn a distinguishable and appearance-invariant representation by using the contrastive learning strategy. For structure enhancement, the macroscopic images which share similar shape characteristics in morphology are introduced for contrast. We encourage the similarity between the microscopic images and their corresponding macroscopic images, and the dissimilarity between the unrelated images. For texture elimination, different appearance transformations, including color distortion and flittering, are utilized for contrast. We maximize the similarity between two different appearance transformed views of the same image, while simultaneously minimizing the similarity between different images.

II. PROBLEM STATEMENT
Microscopic images from parasite infection samples of preserved slides stained with Giemsa [9] including 5758 Plasmodium, 5741 Toxoplasma, 5878 Babesia, and 6981 Erythrocytes, which are non-infected host cells, are used as Micro data. 1000 Micro data in each category are split as a testing set. To evaluate the generalization ability of a model, the testing set is transformed to a color dropped version, which will never be used as data augmentation in the training phase. For the training phase, we suppose that only 50 Micro data in each category are labeled, about 1% of the whole data set, in a practical clinical scenario. According to the parasitologist-level knowledge, Plasmodium is ring-shaped, Toxoplasma is generally banana-shaped, Babesia is typically double-pear-shaped and Erythrocytes resemble an apple. We photo 500 macroscopic images each of ring, banana, double-pear, and apple as Macro data, which best match the Micro objects of interest, instead of using images from the Internet [7], since there are usually irrelative items and confusing background, and collecting from the Internet takes much more effort than photoing. Macro data share the same label with their corresponding Micro data.
Therefore, we have 2000 Macro data which is fully labeled with y s ∈ {0, 1, 2, 3} as source data, 200 labeled Micro data X T = {(x t , y t )} T t=1 with y t ∈ {0, 1, 2, 3} as target data, and 20158 unlabeled Micro data X U = {x u } U u=1 in the training set. Fig. 1 shows some samples. As illustrated in Fig. 2, here are three modules in our proposed method. Firstly, Macro data is transformed to its adaptive version with the style of corresponding Micro data, as data pre-processing. Then a feature extractor is trained by all the training sets, where the contrastive learning strategy is employed to enhance the salient structure and eliminate the insignificant texture. Finally, with the learned feature extractor fixed, an MLP classifier is trained by the labeled data including adaptive Macro data and labeled Micro data.

A. Data Pre-processing
Real-world objects have clearer shapes and are easier to discriminate. However, if simply use full labeled Macro data and weakly labeled Micro data together in the training phase, the model may perform worse due to the different data distributions, known as "domain shift" [10].
Since the shape of Macro data is clearer, while Micro data accounting for a large proportion in quantity. We try to adapt Macro data to appear as if drawn from the Micro domain to realize the visual alignment, as shown in Fig. 2

(A).
In this subsection, we take rendering the ring image with Plasmodium style as an example. The low-level features of overall the labeled Plasmodium data should be separated as Plasmodium style, and the high-level content in terms of the object in the ring image should be extracted and recombined with Plasmodium style to produce an adaptive ring image.
Firstly a pre-trained CNN is used to extract and store the features. Content features are from the ring image (x s , 0), and style features are from all the labeled Plasmodium The features on CNN layer l could be stored in a matrix F l ∈ R N l ×H l ×W l , where N l is the number of distinct filters, H l and W l denotes the height and width of the feature map respectively. The style on CNN layer l could be represented by Gram matrix G l ∈ R N l ×N l , where G l,ij = F l,i F l,j is the inner product between the vectorized feature maps i and j in layer l [11].
Secondly, the overall loss function is minimized to update the image x a iteratively until it simultaneously matches the content features of x s and the style features of X t , where x a can be initiated as a white noise image and λ s is a coefficient. Since our goal is structure enhancement, which requires preserving the semantic content precisely, we empirically set a small weight of λ s = 10 −3 for this purpose. Fig. 3. Train the feature extractor e using a contrastive learning strategy. The network F , including the feature extractor e and a nonlinear projection head h, is updated by the back-propagation on a combination of supervised loss J S and unsupervised loss J U . An offline network Fm is used as a memory trick, which is an exponential moving average (EMA) of F , with a discrete dictionary Q on metric embeddings vm maintained as a queue. J S is defined by aligning the labeled Micro data with corresponding Macro data. J U is defined by aligning two views of different appearance transformation(at) of the same image, where at1 is random color distortion and at2 is Sobel flittering for example. For the learned representation z, J S contributes to the distinguishability and J U contributes to the appearance-invariance.
Based on the fact that deeper convolutional layers respond to higher semantics [12], J content and J style are defined as where L h are the higher CNN layers which capture the highlevel content in terms of objects, L o are all the other CNN layers, w l is the weight of layer l. Specifically, we useḠ l t = t G l t p as the average style features in the Micro domain instead of using the style of a single Micro data.
With the usage of labeled Micro data, all the Macro data X S = {(x s , y s ) S s=1 } is transferred to its adaptive version X A = {(x a , y s ) S s=1 } with corresponding Micro style.

B. Feature Extractor Learned by contrastive learning strategy
We aim to learn a distinguishable and appearance-invariant representation z for the downstream classification task using a small number of labeled Micro data X T = {(x t , y t )} T t=1 and a large amount of unlabeled Micro data X U = {x u } U u=1 , with the additional adaptive Macro data X A = {(x a , y s ) S s=1 }. We denote all the labeled data as X L = X T ∪ X A , and all the data except labels as X = X T ∪ X A ∪ X U . Fig.3 illustrates the proposed method to train the feature extractor e in Fig. 2(B). Our model denoted as F (x; Θ) : X → R |v| can be decomposed further into a CNN based feature extractor e(x; θ e ) : X → Z and a MLP projection head h(z; θ h ) : Z → V conceptually [13], where z is the representation for downstream tasks and v is the metric embedding for contrastive loss, with respect to an input x, and a(·) is a non-linear activation function using k-sparse strategy [14] a Γ = supp k {W T z} containing hidden units with top-k% activation values. In addition to the online network F , a offline momentum network F m (x; Θ m ) is used as a memory trick [15]. The update of Θ is by back-propagation on a combination of supervised loss J S and unsupervised loss J U while Θ m is an exponential moving average(EMA) of Θ where we follow the empirical experience and set α = 0.999. Considering the problem of similarity matching as a form of dictionary look-up, with similarity measured by the dot product of the metric embeddings, InfoNCE [16] is adopted as the form of contrastive loss function due to its efficiency and simplicity, with a well-grounded motivation from information theory. Given query v, the InfoNCE is the negative log-likelihood − log p v (6) where the likelihood is and σ is a temperature parameter that controls the concentration level of the distribution [17]. The value of InfoNCE is low when v is similar to its positive key v + , and dissimilar to all the other keys(considered as negative keys v − for v).
The way we define the positive keys and negative keys for all the training data realizes structure enhancement and texture elimination. 1) Structure Enhancement in J S : Instead of using a simple cross-entropy loss for labeled data X L , a contrastive loss is used to enhance the structure information by connecting Micro and Macro data directly. Every query embedding v t from Micro data, its positive keys are sampled from its corresponding adaptive Macro set, and its negative keys are the embeddings of all the other unrelated adaptive Macro data. Thus, Micro data is encouraged to be similar to its corresponding adaptive Macro data, while dissimilar to unrelated adaptive Macro data simultaneously. And it is the same way for adaptive Macro data. Therefore, the supervised loss for X L is and we define where t is the index of Micro data and Ω a are all the indexes of its corresponding adaptive Macro data, a is the index of adaptive Macro data and Ω t are all the indexes of its corresponding Micro data. Ω T are all the indexes of Micro data and Ω A are all the indexes of adaptive Macro data.
2) Texture Elimination in J U : To eliminate the insignificant texture, two kinds of appearance transformations are introduced, color distortion (which randomly changes the hue, lightness, and saturation of an image) and flittering (such as Sobel, Scharr, Laplacian). For every x u in X, it is randomly transformed to two different views x q , x m , and we define the positive pair p + (v q , v m ), naturally, all the other images are as the negative keys for x u .
Since InfoNCE benefits from more negative keys, we apply an offline momentum network F m (x; Θ m ) and maintain a discrete dictionary Q on metric embeddings v m as a queue [15]. The metric embeddings of the current minibatch are enqueued, and the oldest are dequeued. Introducing Q decouples the dictionary size from the mini-batch size, which can be much larger than the mini-batch size. Θ m is the exponential moving average copy from online network Θ which smooths the learning dynamics. The unsupervised loss for X is and we define where v q = F (x q ; Θ), v m = F m (x m ; Θ m ), and i is the index of the metric embeddings in the maintained queue under the current state.

C. MLP Classifier
All the labeled data X L is used to train a non-linear MLP classifier c in Fig. 2(C), which has a ReLU hidden layer, with the learned feature extractorê fixed.

A. Evaluation Metrics
We use accuracy (AC), F1-measure (F1) of sensitivity (SE) and specificity (SP), and Jaccard index (JA) to evaluate the performance AC = T P + T N T P + F P + T N + F N

B. Implementation
We adopt DenseNet-121 [18] architecture as the CNN backbone. In particular, we only include the five convolutional layers in the set, i.e., L = {conv1, dense1c, dense2d, dense3f, dense4c} for rendering the Macro data with Micro style, as the representations of these layers, in general, have the highest capability in each scale.
For a fair comparison, DenseNet-121 architecture is employed as the CNN backbone for all the methods, whose last fully-connected layer (after global average pooling) has a fixed-dimensional output (1024-D). The MLP projection head h leads to 128-D v with a 256-D hidden layer. The ReLU hidden layer of MLP classifier c is 256-D. In particular, we set temperature σ = 0.08 and k-sparse 20%. The batch size is 256, and the Queue size is 4096. The network was trained by SGD algorithm with a learning rate of 0.0001 and a momentum of 0.9. All the experiments are trained for 500 iterations and three repeat training are performed.

C. Result of Proposed Method
In this part, we report the performance of the supervised baseline and our method trained with only 50 randomly selected Macro data in each category, 200 labeled Micro data X T , and 20158 unlabeled Micro data X U in Table. I.  It is obvious that our semi-supervised method achieves higher performance on all the evaluation metrics, with 6.78%, 5.01%, and 11.76% improvements on AC, F1, and JA, respectively, compared with the supervised-only method. Our method, trained with 1% labeled Micro data and 10% Macro data, reaches an accuracy of 94.90% under a generalized testing set. It is comparable to the reported 95.7% (AC) in [7], which is trained in a full supervised scenario.
As illustrated in Fig. 4, a receiver operating characteristic (ROC) curve is created to visualize the classification performance of our proposed method for all four classes, and an overall area under the curve (AUC) value is computed to summarize the diagnostic performance. The proposed model achieves an overall AUC value of 0.94.

D. Effectiveness of Macro Data Introducing
We analyze how introducing Macro data helps the final performance, and the results are listed in Table. II.
The first three rows are the results of the supervised method, it helps a lot when introducing Macro data even in its original version. However, the results of the semi-supervision scenario in the last three rows tell a different story. There is a tiny improvement when introducing original Macro data, while an impressive improvement when the Macro data is transformed to its adaptive version. These results conform to our assumption that 'domain shift' is remarkable in a semi-supervision scenario since there are a large amount of unlabeled data being trained together with the labeled data.

E. Comparison With Other Semi-supervised Methods
As it is much easier to collect real-world objects naturally labeled than annotating microscopic parasites, we analyze the performances with the different numbers of Macro data, where two state-of-the-art semi-supervised learning methods are compared as counterparts.
Mean Teacher (MT) [19] used the same EMA strategy as our proposed method from a student network to a teacher network, but simply encourage consistent representations from the same input, without any comparison with others. With the same goal of consistency regularization, Virtual Adversarial Training (VAT) [20] directly approximated a tiny perturbation to add to input which would most significantly affect the output of the prediction function, instead of using data augmentation. Quantitative results are in Table. III and we draw the AC score of the results in Fig. 5. All these three semi-supervised methods perform better than the supervised baseline consistently, demonstrating that all the SSL methods effectively utilize the unlabeled data and bring performance gains. As expected, the performances of all the methods increase when more labeled training data are available, and the gap between supervised baseline and semi-supervised methods narrows as more labeled training data are available.
Compared with other methods, we achieve the greatest improvement over the supervised baseline, especially when there are only 200 labels. The comparison shows the effectiveness of our proposed method, compared with other semisupervised methods. And the success is naturally attributed to contrastive learning strategy.

V. CONCLUSION AND FUTURE WORK
In this work, we propose a semi-supervised method using a contrastive learning strategy to classify three apicomplexan parasites and non-infected host cell. The learned representation is more distinguishable by the alignment between Micro data and Macro data, while it is appearance-invariant by encouraging the consistent representation between two different appearance transformed views of the same image. The results verify the effectiveness of the proposed method. At present, the classifier is relatively simple, it worth further exploring how to take full advantage of the learned representation for classification.