# TransMed: Transformers Advance Multi-modal Medical Image Classification

Yin Dai, Yifan Gao · arXiv · 2021-3-10

- **Problem** Pure transformers need large training sets, while medical imaging collections are small, and multi-modal MRI fusion has mostly relied on CNN schemes that model cross-modality relations weakly.
- **Method** Stacks three adjacent slices into a three-channel image, cuts it into K×K patches, extracts patch embeddings with a 2D CNN, and models them with a DeiT-based transformer whose class token output is classified.
- **Results** TransMed-S reached 88.9±3.0 ACC on the parotid gland tumors dataset, against 76.1±5.5 for P3D, the best baseline row.

![Table 1: Comparison on the parotid gland tumors dataset (average accuracy % and precision % for each disease. IF , FF and DF represent input-level fusion, feat…](https://refivu.com/papers/23fc0792-8c66-4fa5-9842-427e13e4215b/figures/figure-2756f9fe5b892e01fe9539d92fbc22f2.png?thumb=512)

**TABLE 1** . Comparison on the parotid gland tumors dataset (average accuracy % and precision % for each disease. IF , FF and DF represent input-level fusion, feature-level fusion and decision-level fusion, respectively.).

[Original paper](https://arxiv.org/abs/2103.05940v1) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Yin Dai, Yifan Gao · TransMed: Transformers Advance Multi-modal Medical Image Classification · Original paper figure · Extracted the figure area from page 6 of the original PDF.

## Why pure transformers fall short here

Transformers model relations across a sequence through self-attention, which is why they suit images as well as text. Natural images expose their sequence structure only implicitly, once they are cut into patches. The authors argue that medical scans show clearer sequence structure across modality, slice and patch, and that this structure carries information a model can use over long distances.

Pure transformers generally need large datasets, and medical imaging collections are comparatively small. The authors state that pure transformer networks based on ViT and DeiT perform unsatisfactorily on multi-modal medical classification, which they link to the small dataset size and to too little information about low-level features.

The design answer is to keep a CNN for low-level features and give the transformer the job of relating the resulting sequence elements across modalities and positions. The authors state that TransMed is the first transformer-based framework for multi-modal medical image classification known to them.

## Three fusion strategies and their costs

Existing deep multi-modal work sorts fusion into three types: input-level, feature-level and decision-level. Input-level fusion stacks the modalities as channels of one network before training, so the network learns a joint representation from the start. Feature-level fusion gives each modality its own path and combines their representations inside the network, while decision-level fusion combines the outputs of separate networks.

Each type has a cost. Input-level fusion struggles to model the relation between the modalities of one patient, which the authors link to weaker performance. Feature-level designs need a network for each modality, and the computational cost grows with the number of modalities. Decision-level outputs stay independent of one another, so the model cannot link the modalities of one patient.

Prior studies vary in how they fuse. Hyper DenseNet built dual networks for MRI modalities and linked features across the streams, and another work fused final features from modality-specific paths. Some decision-level designs add a gate network that weights each decision, and others use modality-specific encoders with a decoder that fuses low-level and high-level features.

Work that compares several fusion types at once still shows poor scalability, heavy computation and difficulty with long-range connections, according to the authors.

## Turning MRI volumes into a sequence

The input is a multi-modal image with batch size B, M modalities, C channels, depth D and spatial resolution H×W. \\\[ x \\in \\mathbb{R}^{B\\times M\\times C\\times D\\times H\\times W} \\\]

Before the CNN, three adjacent 2D slices are superimposed into one three-channel image, so each image carries three neighbouring slices. Each such image is then divided into K×K patches, and a larger K gives smaller patches.

The CNN is a 2D network whose last fully connected layer is replaced by a linear projection, which maps each patch's features into an embedding space. In this role the CNN extracts low-level features from the image sequence and encodes them before the transformer sees them. The length P of each patch embedding is set to fit the input size of the transformer.

## Transformer blocks and embeddings

The transformer branch follows the original DeiT implementation as closely as possible, so its design and pre-trained weights are easy to reuse. Compared with DeiT, the linear projection layer and the distillation token are removed.

Self-attention projects each input vector into query, key and value vectors. The output is a weighted sum of the values, with each weight given by the dot product of a query and a key. \\\[ \\mathrm{Attention}(Q,K,V)=\\mathrm{Softmax}\\left(\\frac{QK^{T}}{\\sqrt{d\_k}}\\right)V \\\] Here d\_k is the dimension of the key vector. The authors say dividing by its square root keeps the gradients more stable.

Multi-head Self-Attention splits the projections into several heads that run in parallel, each with its own trainable projection matrices. The head outputs are concatenated and multiplied by an output projection. \\\[ \\mathrm{head}\_i=\\mathrm{Attention}(QW^{Q}\_{i},\\,KW^{K}\_{i},\\,VW^{V}\_{i}) \\\] \\\[ \\mathrm{MSA}(Q,K,V)=\\mathrm{Concat}(\\mathrm{head}\_i,\\ldots,\\mathrm{head}\_i)\\,W^{O} \\\] The printed concatenation repeats the index i, and the paper defines h as the number of transformer layers, although the formula concatenates over heads; the text does not settle which index runs over which set.

The MLP is made of linear layers separated by a GeLU activation, and it sits after the MSA layer in each block. Each sub-block has a skip connection and layer normalization, which the paper writes as LN in the formulas. \\\[ \\hat{x}\_t=\\mathrm{MSA}(\\mathrm{LN}(x\_{t-1}))+x\_{t-1} \\\] \\\[ x\_t=\\mathrm{MLP}(\\mathrm{LN}(\\hat{x}\_t))+\\hat{x}\_t \\\] Here x\_{t-1} is the input of layer t, and the skip connections add the block input back after each sub-block.

The patch tokens are the CNN patch embeddings with a position embedding added, so the spatial location of each patch is kept. \\\[ x^{pt}=\\mathrm{Conv}(x)+x^{po} \\\] A trainable class token is attached to the patch tokens before the transformer layers. \\\[ x^{ct}=W^{c} \\\] After the transformer layers, the class token output passes through a fully connected layer that predicts the class.

## Parotid MRI dataset and training setup

The dataset comes from cooperating hospitals and contains T1 and T2 MRI of 344 patients, with ground-truth labels from biopsies. The paper cites an incidence of about 20% for malignant tumors among parotid gland tumors as the reason preoperative diagnosis matters. The labels cover five categories: Pleomorphic Adenoma (PA), Warthin Tumor (WT), Malignant Tumor (MT), Basal Cell Adenoma (BCA) and Other Benign Lesions (OBL).

Foreground is extracted with OTSU thresholding, the modalities of each patient are registered, and each image is resampled to (18, 448, 448). The text also gives (36, 448, 448) as the size of each stacked T1 and T2 volume, and it does not spell out how the per-image size becomes the stacked size.

Training-time augmentation flips each image with 50 % probability. It also adds Gaussian noise with mean 0 and variance 0.1 to each image.

Patients are split at random at a 4:1 ratio into 275 training patients and 69 independent test patients, and the training group fits the model parameters. The optimizer is SGD with learning rate 10−3 and momentum 0.7, for at most 100 training rounds. Each model is run in 10 independent experiments, each with its own random split, and the other settings are kept the same.

The runs use one NVIDIA 3080 GPU with 10GB memory, implemented in PyTorch and TorchIO.

Overall accuracy is ACC, the number of correctly predicted samples Tc divided by the total number of samples T. \\\[ \\mathrm{ACC}=\\frac{T\_c}{T} \\\] Per-class precision P(i) divides the samples correctly predicted as class i, Tic, by all samples predicted as class i, which are Tic plus the wrongly predicted Tif. \\\[ P(i)=\\frac{T\_{ic}}{T\_{ic}+T\_{if}} \\\]

## Accuracy against fusion baselines

The baselines cover input-level fusion with 2D and 3D networks, namely Resnet34, Resnet152, 3D Resnet34, P3D and C3D. Feature-level fusion uses the two methods of \[11\] and \[12\], which the authors modified for classification because the originals target segmentation. Decision-level fusion reuses the input-level backbones.

TransMed-T pairs ResNet18 with DeiT-Tiny, TransMed-S uses ResNet34 with DeiT-Small, TransMed-B uses ResNet50 with DeiT-Base, and TransMed-L uses ResNet152 with DeiT-B. Their ACC values are 87.0±2.6 for TransMed-T, 88.9±3.0 for TransMed-S, 87.4±2.1 for TransMed-B and 86.6±3.4 for TransMed-L.

The highest baseline ACC is 76.1±5.5, for P3D with input-level fusion, and every TransMed row exceeds every baseline row in ACC. Per class, TransMed is above every baseline on MT and OBL, but TransMed-T, TransMed-S and TransMed-L fall below the best baseline on BCA, and TransMed-T is below Resnet34 on PA. TransMed-T's PA value is 80.1±13.8 against 81.0±11.0 for Resnet34 under input-level fusion, and its BCA value is 82.5±15.3 against 83.2±16.3 for Resnet152 under decision-level fusion.

The text reports that TransMed-S gives about 12.8% higher average accuracy than the P3D baseline, but it names this model TransFuse-S, a name that matches no row in Table 1. TransMed-S's ACC of 88.9±3.0 against P3D's 76.1±5.5 is the comparison the table supports directly.

The authors say the larger TransMed-B and TransMed-L slightly suffer from overfitting on this dataset. Going from TransMed-T to TransMed-S improves average accuracy by 1.9% at a much larger computational cost.

## Removing each branch and varying patch size

The ablation starts from TransMed-T, with either the transformer branch or the CNN branch removed and all other conditions unchanged.

Removing the transformer branch lowers ACC from 87.0±2.6 to 71.3±2.5, so keeping the transformer branch is the choice these numbers support. The authors say the transformer improves how the model explores relations between modalities with little extra parameters or computation. Removing the CNN branch gives the lowest ACC, 51.3±5.9, and the authors attribute the weak pure-transformer result to the small dataset.

The patch-size sweep changes K with the other conditions held fixed. The authors report poor performance when K is large and attribute it to image patches that become too small to keep semantic information. By the paper's own definition a larger K gives smaller patches, so the stated explanation and the stated condition describe the same setting from opposite ends, and the text does not reconcile them.

## Limitations

The evidence comes from one dataset of 344 patients with T1 and T2 MRI, and from one five-category task on parotid gland tumors. The authors name tumor segmentation and lesion detection as tasks TransMed has not yet been applied to.

The ablations and the patch-size sweep were run on TransMed-T, which the authors chose because of computation cost. Whether the branch conclusions hold for TransMed-S, TransMed-B or TransMed-L was not tested.

The authors state that a gap remains between pure transformers and typical CNNs on small medical image datasets, based on their preliminary experiments. The feature-level baselines were built for segmentation and then changed for classification, so they are adapted rather than reproduced as published.

The table captions do not define the ± values, and the text does not say which TransMed parameters start from the DeiT pre-trained weights.

## Paper info

- **Authors**: Yin Dai, Yifan Gao
- **Venue**: arXiv · Preprint
- **First published**: 2021-3-10
- **Added**: 2026-11-6
- **Updated**: 2021-3-10
- **Version**: v1
- **arXiv**: 2103.05940
- **Category**: cs.CV
- **Original paper terms**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
- **What we show**: Paper info, commentary and permitted figures from the original paper

[Original paper ↗](https://arxiv.org/abs/2103.05940v1) · [PDF ↗](https://arxiv.org/pdf/2103.05940v1)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Abstract

Over the past decade, convolutional neural networks (CNN) have shown very competitive performance in medical image analysis tasks, such as disease classification, tumor segmentation, and lesion detection. CNN has great advantages in extracting local features of images. However, due to the locality of convolution operation, it can not deal with long-range relationships well. Recently, transformers have been applied to computer vision and achieved remarkable success in large-scale datasets. Compared with natural images, multi-modal medical images have explicit and important long-range dependencies, and effective multi-modal fusion strategies can greatly improve the performance of deep models. This prompts us to study transformer-based structures and apply them to multi-modal medical images. Existing transformer-based network architectures require large-scale datasets to achieve better performance. However, medical imaging datasets are relatively small, which makes it difficult to apply pure transformers to medical image analysis. Therefore, we propose TransMed for multi-modal medical image classification. TransMed combines the advantages of CNN and transformer to efficiently extract low-level features of images and establish long-range dependencies between modalities. We evaluated our model for the challenging problem of preoperative diagnosis of parotid gland tumors, and the experimental results show the advantages of our proposed method. We argue that the combination of CNN and transformer has tremendous potential in a large number of medical image analysis tasks. To our best knowledge, this is the first work to apply transformers to medical image classification.

## Quote from the paper

Yin Dai, Yifan Gao (2021). TransMed: Transformers Advance Multi-modal Medical Image Classification. arXiv:2103.05940v1. https://arxiv.org/abs/2103.05940v1

**BibTeX**

```
@misc{dai2021transmed,
  title = {{TransMed: Transformers Advance Multi-modal Medical Image Classification}},
  author = {Yin Dai and Yifan Gao},
  year = {2021},
  eprint = {2103.05940},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2103.05940v1}
}
```

## Other paper commentary

- [Multimodal Fusion Transformer for Remote Sensing Image Classification](https://refivu.com/en/papers/5115f05f-19f9-447c-ab75-0ba016db652e-multimodal-fusion-transformer-for-remote-sensing-image.md)
- [A Generalized Deep Learning Framework for Whole-Slide Image Segmentation and Analysis](https://refivu.com/en/papers/17229723-709e-4a8a-9857-8cd6f0d14883-a-generalized-deep-learning-framework-for-whole-slide.md)
- [Fast R-CNN](https://refivu.com/en/papers/cf1d88ea-f632-4173-bcfd-eec504e5c175-fast-r-cnn.md)
- [End-to-End Training of Deep Visuomotor Policies](https://refivu.com/en/papers/67bd34bf-8571-4d8e-9691-251431e21af1-end-to-end-training-of-deep-visuomotor-policies.md)
- [Unsupervised Deep Anomaly Detection for Multi-Sensor Time-Series Signals](https://refivu.com/en/papers/878b018b-6c5e-4a6c-9708-982ce4d20f8a-unsupervised-deep-anomaly-detection-for-multi-sensor-time.md)
- [YOLOP: You Only Look Once for Panoptic Driving Perception](https://refivu.com/en/papers/61212604-6561-425b-9de1-178543e2926c-yolop-you-only-look-once-for-panoptic-driving.md)
- [Anomaly Detection on Attributed Networks via Contrastive Self-Supervised Learning](https://refivu.com/en/papers/c20bdbfe-b419-4df5-8f33-b1066c4f4576-anomaly-detection-on-attributed-networks-via-contrastive.md)
- [BEHRT: Transformer for Electronic Health Records](https://refivu.com/en/papers/cadb146f-6d4d-4255-8058-89ac62ed2dc8-behrt-transformer-for-electronic-health-records.md)
- [PredRNN: A Recurrent Neural Network for Spatiotemporal Predictive Learning](https://refivu.com/en/papers/c0da3abd-5c1e-4383-ae59-22d04fe3eb7d-predrnn-a-recurrent-neural-network-for-spatiotemporal.md)
- [Deep Multi-agent Reinforcement Learning for Highway On-Ramp Merging in Mixed Traffic](https://refivu.com/en/papers/5a4426df-329c-4335-a2f9-61fd8bab85a2-deep-multi-agent-reinforcement-learning-for-highway-on.md)
- [SuperSpike: Supervised learning in multi-layer spiking neural networks](https://refivu.com/en/papers/69e65b6b-2815-4179-aaac-1c5294019aba-superspike-supervised-learning-in-multi-layer-spiking-neural.md)
- [Deep Reinforcement Learning Based Intelligent Reflecting Surface for Secure Wireless Communications](https://refivu.com/en/papers/7f104da3-3d98-4ecd-95d9-a25944d61e36-deep-reinforcement-learning-based-intelligent-reflecting.md)

## Terms in this paper

- [Transformer](https://refivu.com/en/terms/48e8be2570bc-transformer)
- [self-attention](https://refivu.com/en/terms/426589b81077-self-attention)
- [Data Augmentation](https://refivu.com/en/terms/cc5618231f4a-data-augmentation)
- [layer normalization](https://refivu.com/en/terms/7af9eccdb60d-layer-normalization)
- [CNN](https://refivu.com/en/terms/06880f5198e6-cnn)
- [SGD](https://refivu.com/en/terms/96a2d83e44ca-sgd)
- [DeiT](https://refivu.com/en/terms/24b9f164881b-deit)
- [GELU](https://refivu.com/en/terms/8897c492bcfe-gelu)
- [multi-layer perceptron](https://refivu.com/en/terms/835dd4f24c91-multi-layer-perceptron)
- [ViT](https://refivu.com/en/terms/c041b72c53b8-vit)
- [ACC](https://refivu.com/en/terms/e6cad80f6e60-acc)
- [multi-head self-attention](https://refivu.com/en/terms/075f5cbf9073-multi-head-self-attention)
- [patch embedding](https://refivu.com/en/terms/29de7fe43e42-patch-embedding)
- [class token](https://refivu.com/en/terms/5290d74b3faf-class-token)
- [position embedding](https://refivu.com/en/terms/240915f7a95a-position-embedding)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/23fc0792-8c66-4fa5-9842-427e13e4215b-transmed-transformers-advance-multi-modal-medical-image)
