{'fraction_non_alphanumeric': 0.03070225684499943, 'fraction_numerical': 0.01214342994615649, 'mean_word_length': 4.952608250937606, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
CellCentroidFormer: Combining Self-attention and Convolution for Cell Detection

Cell detection in microscopy images is important to study how cells move and interact with their environment. Most recent deep learning-based methods for cell detection use convolutional neural networks (CNNs). However, inspired by the success in other computer vision applications, vision transformers (ViTs) are also used for this purpose. We propose a novel hybrid CNN-ViT model for cell detection in microscopy images to exploit the advantages of both types of deep learning models. We employ an efficient CNN, that was pre-trained on the ImageNet dataset, to extract image features and utilize transfer learning to reduce the amount of required training data. Extracted image features are further processed by a combination of convolutional and transformer layers, so that the convolutional layers can focus on local information and the transformer layers on global information. Our centroid-based cell detection method represents cells as ellipses and is end-to-end trainable. Furthermore, we show that our proposed model can outperform fully convolutional one-stage detectors on four different 2D microscopy datasets. Code is available at: https://github.com/roydenwa/cell-centroid-former

. Feature maps and cell detection results for a fluorescence microscopy image. The feature map on the left was generated by a transformer encoder in the neck part of our model, the feature map on the right was generated by an adjacent convolutional layer. The transformer encoder focuses on the overall cell shapes (global features), while the convolutional layer focuses on the cell centroids (local features). Both feature maps have been enlarged, their original size is 48 × 48 pixels.

Introduction
Cell detection is an important task when studying biomedical microscopy images and time-lapse microscopy videos. Main applications are the quantification of cellular structures as well as studying how cells move and interact with their environment. Most recent deep learning-based methods for cell detection in microscopy images use convolutional neural networks (CNNs) (e.g., [5], [6], [12]). However, inspired by the success in other computer vision applications, vision transformers (ViTs) (e.g., [13]) are also used for this purpose.
The comparison of ViTs and CNNs in computer vision applications reveals that the receptive fields of ViTs and CNNs are fundamentally different [14]. The receptive fields of ViTs capture local and global information in both earlier and later layers. The receptive fields of CNNs, on the other hand, initially capture local information and gradually grow to capture global information in later layers. This suggests that ViTs better preserve spatial information across the generated feature maps within the models, which is advantageous for object detection. However, a limitation of most current ViT models is that they require much more training data to reach or surpass the performance of CNNs in computer vision tasks [7]. This is a major limitation for biomedical applications, where annotated training samples are limited. Another limitation of ViTs is that their core mechanism, multi-head self-attention, has a computational complexity of O(n 2 ), where n is the length of the input sequence. Consequently, large computational resources are required for training such models.
To exploit the advantages of both types of deep learning models, we propose a hybrid CNN-ViT model for cell detection in microscopy images. We employ an efficient CNN, that was pre-trained on the ImageNet [1] dataset, to extract images features and utilize transfer learning to reduce amount of required training data. Extracted image features are further processed by a combination of convolutional and transformer layers, so that the convolutional layers can focus on local information and the transformer layers on global information. We propose a one-stage cell detection method that is end-to-end trainable. Overall, the contributions of our paper are twofold: 1. We introduce a novel deep learning model that combines self-attention and convolution for cell detection in microscopy images. 2. We propose a centroid-based cell detection method that represents cells as ellipses.

Related Work
Several related methods use CNNs [3,5,6,9,12,22,24] or combine CNNs with classical image analysis approaches [17] for cell detection in biomedical microscopy images. Amongst these methods, two approaches are common: (i) to perform cell detection by predicting a heatmap for cell positions [3,12,24] or (ii) to perform cell detection by predicting the coordinates of bounding boxes for cells [5,6,9]. The heatmap-based methods are well suited for cell counting, but are unsuitable for morphological studies since they only predict where cells are located and do not provide information on the cell dimensions. The bounding box-based methods are more flexible as they predict the cell positions and the cell dimensions (width and height). However, the bounding box-based methods use a cascade of two CNNs and are therefore not end-to-end trainable. To deal with sparsely annotated or small datasets, semi-supervised learning [3,12] or pre-training with synthetic data [24] is used. Thus complicating the training process, since pseudolabels must be iteratively generated or synthetic data must be created in advance.
The Cell-DETR [13] model is architecturally most related to ours. Cell-DETR is a hybrid CNN-ViT model for cell detection and segmentation. Prangemeier et al. use a CNN backbone to extract image features, a transformer encoderdecoder block to process image features and a model head with a multi-layer perceptron for cell detection. Due to the high computational complexity of the transformer encoder-decoder block, they use a small input size of 128 × 128 pixels. Therefore, a considerable amount of information is lost when downsizing high-resolution microscopy images.

Model Architecture
The proposed hybrid CNN-ViT model combines self-attention and convolution for cell detection. For this purpose, we use MobileViT blocks [11], which combine transformer encoders [2,19] with convolutional layers. In MobileViT blocks, input tensors are first processed by convolutional layers, then, the extracted features are unfolded into a sequence and passed through a transformer encoder. Finally, the output tensor of the transformer encoder is folded again into a 3D representation and concatenated with the input tensor. Thereby, the convolutional layers extract local information and the self-attention mechanism in the transformer encoder associates local information from distant features to capture global information. We use MobileViT blocks in the neck part of our proposed model to enhance global information compared to a fully convolutional neck part. MobileViT blocks are a light-weight alternative to the original transformer encoder-decoder design [19]. However, due to their multi-head self-attention layers, MobileViT blocks still have a much higher computational complexity (CC) than convolutional layers: where n is the sequence length, d is the sequence depth, h is the number of selfattention heads, k the size of the convolutional kernels, and f is the number of convolutional filters. Thus, we combine MobileViT blocks in the neck part of our model with convolutional layers to extract more features without increasing the computational complexity excessively. In addition, we add layer normalization layers for regularization and to allow higher learning rates during training.
As backbone of our proposed model, we use parts of an EfficientNetV2S [16] CNN model. EffcientNet models consist of six high-level blocks, we use five of these blocks to extract image features. We initialize the backbone with weights learned from training on the ImageNet dataset to leverage transfer learning and reduce the amount of required training data. EfficientNetV2S models are optimized for a fixed input size of 384 × 384 × 3 pixels. Therefore, we resize all input images to this input size. We represent cells by their centroid, their width, and their height. Our model contains two fully convolutional heads to predict these cell properties. The heads contain 2D convolution, batch normalization, and bilinear upsampling layers. We do not use further MobileViT blocks in the heads to reduce the computational complexity of our model, and since later convolutional layers have a large receptive field that allows them to capture global information [14]. The first head predicts a heatmap for cell centroids, and the second head predicts the cell dimensions (width and height) at the position of the corresponding cell centroid. The output dimensions of our model are 384 × 384, thus, the output stride is one and we do not need an additional offset head to account for offset errors (as in, e.g., [25]). Figure 2 shows the overall model architecture.

Bounding Ellipses for Cell Detection
Yang et al. [25] argue that traditional bounding box-based object detection methods are not optimized for biomedical applications. They state that most relevant objects in biomedical applications have round shapes, and thus they propose using bounding circles instead of bounding boxes. We extend this idea and use bounding ellipses for cell detection, since most cell types in biomedical applications have an ellipsoidal shape. Figure 3 shows how we generate training samples for the proposed centroid-based cell detection method. We approximate the centroid of a cell by an ellipse with width and height adjusted to the corresponding cell dimensions. We blur the centroid ellipses using a Gaussian kernel to reduce the loss value when a centroid is only missed by a small distance. Similar as in [26], the cell width and cell height are encoded in rectangles located at the position of the cell centroids.

Datasets and Pre-processing
We evaluate our hybrid CNN-ViT model using four different 2D microscopy datasets from the Cell Tracking Challenge [18]. The Fluo-N2DL-HeLa (HeLa) dataset consists of 2D fluorescence microscopy images of cells stably expressing H2b-GFP. The images of this dataset have a size of 700 × 1100 pixels. The Fluo-N2DH-SIM+ (SIM+) dataset consists of simulated 2D fluorescence microscopy images of HL60 cells stained with Hoechst dyes. The images of this dataset have a size of 773 × 739 pixels. The Fluo-N2DH-GOWT1 (GOWT1) dataset consists of 2D fluorescence microscopy images of mouse stem cells. These images have a size of 1024 × 1024 pixels. The PhC-C2DH-U373 (U373) dataset consists of 2D phase contrast microscopy images of glioblastoma-astrocytoma U373 cells on a polyacrylamide substrate. The images of this dataset have a size of 520 × 696 pixels. Similar as in [20], we use pseudocoloring to generate input images with three channels suitable for the pretrained backbone. We use the ncar pseudo spectral colormap 1 , which is well suited for coloring cell nuclei and their immediate surroundings to distinguish these regions from the background. Figure 4 shows pseudocolored image crops of the SIM+ and GOWT1 datasets.

Baseline Model
Similar to semantic segmentation, our method treats cell detection as a pixelwise regression objective. Therefore, we choose a CNN designed for semantic segmentation as baseline model in the following experiments. The Dual U-Net model [10] has an encoder-decoder architecture with two decoders. Most recently, the Dual U-Net model was used as part of a tracking and segmentation method [15] that achieved multiple top-3 rankings in the Cell Tracking Challenge 2 . Analogously to our model, we use one decoder of the Dual U-Net model to predict the centroid heatmap and the other to predict the cell dimensions.

Training Setup, Metrics, and Hyperparameters
We use geometric data augmentations such as grid distortion, elastic transformation, shifting, and rotation to increase the size of each dataset to 2150 samples. The resulting datasets are each split into a training dataset (80%), a validation dataset (10%), and a test dataset (10%). All images are normalized using min-max scaling. Our CellCentroidFormer model is trained with pseudocolored training samples, the Dual U-Net model with normalized grayscale training samples. We use three Huber loss functions [4], one loss function per output, to train both models. The total loss is computed by a weighted sum of the three loss values: The centroid heatmap loss (L heatmap ) contributes the most to the total loss because our method is inherently centroid-based. When decoding the predictions of our model, the width and height of the cells are only looked up at positions where cell centroids are located according to the centroid heatmap prediction.
As performance metrics, we use the mean intersection over union (Mean-IoU) and the structural similarity metric (SSIM) [21]. We convert the centroid heatmaps to binary masks to evaluate the detection performance. Therefore, we apply thresholding to the heatmaps. Afterwards, we compute the MeanIoU value of the predicted and the ground truth centroid mask: For the two class labels (C), background and cell centroids, the true positive (TP), false positive (FP), and false negative (FN) pixels are determined. For the cell dimensions (height and width), we use the SSIM metric to quantify the performance. The metric measures the similarity between two images or matrices and is defined as: For the two inputs (x 1 and x 2 ), the mean (µ), the variance (σ), and the dynamic range (L) are computed. We train both models per dataset for 50 epochs with a batch size of 4 using a Nvidia® V100 GPU. We use Adam [8] as optimizer with an initial learning rate of 1 −4 and reduce the learning rate at plateaus.   Our model converges around the 30th epoch, whereas the baseline model converges around the 40th epoch. In these training epochs, the lowest learning rate of 1 −6 is also reached for both models and, accordingly, the metrics do not change much in the following epochs. Our model converges faster since the pretrained backbone was already trained to extract image features. The performance difference for the cell centroid MeanIoU score is greater than for the cell dimensions SSIM score, but overall our model yields higher values for all considered metrics on both datasets (training and validation).  Table 1 shows a comparison the performance of the two models on the used test datasets. Additionally, we train a CircleNet [25] model with an Efficient-NetV2S as backbone. As in [23,26], we combine the backbone with upsampling blocks, such that the CircleNet has an output stride of 4. CircleNets detect bounding circles for cells by predicting a heatmap for cell centers, the circle radius, and a local offset. We train the model with pseudocolored samples, use a Huber loss for the center heatmap predictions, and keep the rest of the training setup as in [25]. To compute the SSIM score for the cell dimensions, we compute the SSIM score for the radius prediction and cell width map, the SSIM score for the radius prediction and cell height map, and average them.

Training Curves and Performance Comparison
Our CellCentroidFormer model outperforms the Dual U-Net and the CircleNet on all considered datasets. As in Figure 5, the performance difference for the cell centroid MeanIoU score is greater than for the cell dimensions SSIM score. Our model and the Dual U-Net model yield higher cell dimensions SSIM scores than the CircleNet model since most cells have an ellipsoidal shape, which is more accurately represented by an ellipse than by a circle. On the SIM+ dataset, our model and the CircleNet model outperform the Dual U-Net model on the cell centroid MeanIoU score. On the HeLa dataset, the CircleNet performs worst because this dataset contains many small cells (see Figure 6), that are challenging to distinguish in a low resolution output of 128 × 128. Table 2 shows a comparison of the training times, the inference times, and the overall number of parameters per model. As previously shown [11], vision transformers need more time for training and inference than CNNs. This also applies to our hybrid model, thus, it requires more time to train our model for one epoch (T Epoch ), and the inference time for one input image is somewhat slower (TI GP U ). However, our model only requires one third of the parameters of the Dual U-Net model and roughly half of the parameters of the CircleNet model (11.5 M vs. 33 M vs. 24.6 M) to achieve superior performance. Figure 6 shows example images of the considered datasets and the corresponding cell detection results of our model.

Conclusion
We have presented a novel hybrid CNN-ViT model that combines self-attention and convolution for cell detection. Our centroid-based cell detection method represents cells as ellipses and is end-to-end trainable. We have shown that the transformer layers in the neck part of our proposed model can focus on the overall cell shapes, while adjacent convolutional layers focus on the cell centroids. Our experiments reveal that pseudocoloring in combination with pretrained backbones improves the cell detection performance, whereas larger output strides worsen the performance. Furthermore, our CellCentroidFormer model outperforms fully convolutional one-stage detectors on four different 2D microscopy datasets despite having less parameters overall.