Manuscript Offprint
arXiv:2610.33965Accuracy Is Not Enough: An Efficiency- and Statistics-Aware Benchmark of ResNet50 and Vision Transformer for Explainable Multi-Class Gastrointestinal Diseases Classification
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Abstract
Automated classification of gastrointestinal (GI) findings in endoscopic images could support early diagnosis, but architectures are often chosen on accuracy alone. We present a controlled, reproducible benchmark of ResNet50 and ViT-B/16 for eight-class GI classification on the public Kvasir dataset (4,000 images), using a stratified split (400 test images) and stratified group 5-fold cross-validation over all images. In cross-validation, ResNet50 and ViT-B/16 reached 92.12% and 91.70% accuracy, and a two one-sided tests (TOST) procedure showed equivalence within a ±3 percentage-point margin (difference +0.43 points, 90% CI -0.33 to +1.18; p < 0.001). The architectures differed mainly in cost: ResNet50 had 3.6 times fewer parameters and 4.3 times fewer operations, 2.5-fold lower single-image CPU latency (69 vs. 177 ms) and 3.8-fold higher GPU throughput. Cross-validated calibration was similar (expected calibration error 0.021 vs. 0.023). An edge-oriented transformer, MobileViT-S, was most accurate on the test split (95.5%) but lost 9.4 points when an acquisition artefact present in some classes (the ScopeGuide inset) was occluded, whereas ResNet50 was not significantly affected. On 500 unseen polyp images with expert masks, both models' Grad-CAM maps focused on the lesion (3.6 times chance). On a de-duplicated external subset of GastroVision (1,998 images), accuracy fell to 78–80% for all three models and differences between them remained small. Accuracy differences between architectures were thus small relative to the effects of shortcut learning and domain shift, whereas efficiency differences were large. An efficient CNN is a defensible default for resource-constrained screening, but no model is deployment-ready without local validation.
Keywords: Gastrointestinal disease classification; endoscopic imaging; ResNet50; Vision Transformer; equivalence testing; shortcut learning; resource-constrained deployment.
1 Introduction
Gastrointestinal (GI) diseases including inflammatory disorders, ulcers, polyps, and cancers remain among the most prevalent causes of morbidity and mortality worldwide, cause a significant strain on healthcare resources . The International Agency for Research on Cancer (IARC), the World Health Organization's (WHO) specialized cancer agency, reports that gastrointestinal (GI) cancers are responsible for approximately 3.5 million new cases globally each year. These types of cancers collectively account for an estimated 2.2 million deaths annually, a mortality-to-incidence ratio of about 63% [4]. Early and accurate detection of GI abnormalities can dramatically improve treatment outcomes, yet timely diagnosis remains a challenge in many clinical settings due to increasing patient loads, a shortage of trained endoscopists, and the subjective nature of visual interpretation [5]. Conventional endoscopy, while highly effective for visualizing the internal structure of the gastrointestinal tract, relies heavily on the expertise of clinicians to detect and classify pathological features and it can lead to potential errors in disease classification [6]. Although endoscopy stands as the undisputed gold standard for inspecting the gastrointestinal (GI) tract [4], its true potential is significantly curtailed by a critical variable: operator performance. The efficacy of this vital procedure, therefore, hinges directly on the skill and consistency of the individual wielding the endoscope. Inter-observer variability and operator fatigue can lead to missed or delayed diagnoses, especially in subtle or early-stage cases. To address these challenges, researchers and clinicians have increasingly turned to artificial intelligence (AI) and deep learning systems to augment diagnostic workflows and reduce human error.
Recent advances in computer vision, particularly convolutional neural networks (CNNs), have demonstrated significant success in medical image classification, segmentation, and anomaly detection tasks [7–9]. Architectures such as ResNet, DenseNet, and Inception have been widely adopted in gastrointestinal imaging, showing high performance in tasks like polyp detection[10], ulcer identification, and disease staging [11]. These models excel in learning hierarchical spatial features through convolutional filters, making them well-suited to identifying texture and shape abnormalities in medical images [5, 11].
However, despite the success of CNNs, they suffer from certain limitations. CNNs are inherently biased toward local patterns due to their receptive field constraints and inductive biases. This makes them less effective in modeling long-range dependencies or capturing global context an important consideration in medical imaging where subtle variations in texture and anatomical structures may span large regions of the image [12]. Vision Transformers (ViTs), a recent innovation in the computer vision community, offer a promising alternative. Inspired by transformer models in natural language processing, ViTs utilize self-attention mechanisms to model relationships between all parts of an image simultaneously [13, 14]. This global reasoning capability enables ViTs to potentially outperform CNNs in tasks requiring holistic interpretation [12, 15]. However, ViTs generally require larger datasets and are computationally more intensive, raising questions about their practical utility in medical imaging, where labeled data is limited, and real-time processing is often critical [16].
To explore these trade-offs, we conduct a systematic comparison between ResNet50, a widely used, lightweight CNN, and ViT-B/16, a transformer-based architecture, complemented by an edge-oriented hybrid transformer (MobileViT-S), for multi-class gastrointestinal disease classification using the Kvasir dataset. The Kvasir dataset contains 4,000 annotated endoscopic images representing eight clinically relevant classes: dyed-lifted-polyps (post-treatment assessment), dyed-resection-margins (surgical boundary evaluation), esophagitis (inflammation), normal-cecum (healthy colon start), normal-pylorus (stomach exit), normal-z-line (esophagus-stomach junction), polyps (pre-cancerous growths), and ulcerative-colitis (chronic inflammation). Unlike prior works that focus on binary classification or polyp segmentation, we evaluate these models on a more challenging 8-class classification task that better reflects real-world clinical complexity. In addition to classification accuracy, we assess the models across several critical dimensions: computational efficiency (in terms of MACs and parameter count), generalization (held-out test accuracy, cross-validation and an external dataset), calibration, explainability (Grad-CAM, LIME, SHAP and attention rollout), and robustness to an acquisition artefact. By analyzing both overall metrics and class-specific performance, we aim to uncover the strengths and limitations of each architecture and provide practical guidelines for model deployment in clinical settings.
This paper makes the following key contributions:
-
We provide a controlled, fully reproducible benchmark of a standard CNN (ResNet50) and a standard Vision Transformer (ViT-B/16) for 8-class gastrointestinal disease classification, evaluated on a fixed stratified split and with stratified group 5-fold cross-validation in which near-duplicate images are never split across folds. Rather than inferring equivalence from a non-significant test, we combine McNemar's paired test with a two one-sided tests (TOST) equivalence procedure and a ±3 percentage-point margin, and show that the two architectures are equivalent in cross-validated accuracy (92.12% vs. 91.70%; 90% CI for the difference −0.33 to +1.18 points).
-
We characterize computational cost with a standardized protocol (parameters, multiply-accumulate operations, GPU and CPU latency and throughput, peak memory, and training time). ResNet50 needs fewer parameters and fewer operations, runs faster on a CPU, has higher GPU throughput and reaches its best checkpoint about four times sooner. We complement this with calibration analysis (three ECE binning schemes, class-wise ECE, Brier score and negative log-likelihood, with and without label smoothing), positive predictive values at realistic prevalence, and a multi-method interpretability assessment (Grad-CAM, LIME, SHAP and attention rollout) that includes lesion-level localization against expert polyp masks.
-
We test robustness beyond the curated benchmark. An occlusion experiment shows that an edge-oriented transformer (MobileViT-S), the most accurate model on the test split, depends on an acquisition artefact (the ScopeGuide inset) far more than ResNet50, and an evaluation on a de-duplicated external subset of GastroVision shows a 13–17 point accuracy drop for all models. We translate these findings into deployment-oriented guidance and delineate the limitations that bound them.
The remainder of this paper is organized as follows: Section 2 reviews the related literature; Section 3 details the dataset, model architectures, and training and evaluation methodology; Section 4 presents and discusses the experimental results including classification performance, statistical significance testing, computational efficiency, calibration, interpretability, robustness to an acquisition artefact and external evaluation, together with the limitations of the study; and Section 5 concludes with directions for future research.
2.1 Early Approaches: Handcrafted Features and Classical Methods
Initial efforts in automated gastrointestinal diagnosis relied heavily on classical machine learning techniques coupled with manually engineered features. Pogorelov et al. [17] introduced the Kvasir dataset and evaluated several machine learning classifiers using global features such as texture, color histograms, and Local Binary Patterns (LBP). Among their evaluated methods, the Logistic Model Tree classifier achieved a test accuracy of 93.7% and an F1-score of 0.747. While promising, these handcrafted approaches lacked generalization ability and struggled with visual variability inherent in endoscopic data.
2.2 Deep Learning and CNN-Based Methods
The advent of deep learning, particularly CNNs, revolutionized medical image analysis by enabling automatic feature learning from raw pixel data. CNNs like AlexNet, VGG, ResNet, and Inception have been widely applied to tasks such as polyp detection, bleeding identification, and disease classification [7, 8, 18]. Jha et al.[19] introduced the Kvasir-SEG dataset for polyp segmentation and proposed a ResUNet architecture, achieving a Dice coefficient of 0.788 and mean Intersection over Union (IoU) of 0.778. Although their model performed well in binary segmentation, it was not evaluated on multi-class classification, limiting its clinical scope. Jha et al. [20] introduced the Kvasir-Instrument dataset for GI tool segmentation and benchmarked it using U-Net, achieving a Dice score of 0.9158 and IoU of 0.8578. While effective overall, the model struggled with specular highlights and multiple instruments, highlighting the need for more robust methods.
Varalaxmi et al. [21] utilized ResNet50 CNN for diagnosing gastrointestinal diseases from endoscopy images. Their model, evaluated on the Kvasir dataset, achieved 88.05% accuracy, 87.05% sensitivity, and 92.33% specificity, demonstrating efficient and accurate diagnosis.
Hannan et al. [22] achieved 98.9% accuracy in gastrointestinal disorder diagnosis by combining DenseNet-201 deep feature extraction with a kernel SVM classifier using Kvasir dataset.
Mary et al. [23] proposed a CNN-based framework for classifying gastrointestinal diseases using VGG-19 and ResNet-50 on a subset of the Kvasir dataset with 3,500 images across seven classes. ResNet-50 achieved the highest validation accuracy of 96.81%, while VGG-19 reached 94.21%. Similarly, Siddiqui et al. [24] proposed a deep ensemble learning framework for classifying endoscopic gastrointestinal images by combining two state-of-the-art models, NasNet-Mobile and EfficientNet. Trained on the HyperKvasir dataset and evaluated on the Kvasir v1 and Kvasir v2 datasets (containing images across eight classes), the proposed model achieved an accuracy of 97.83% on Kvasir v1 and 98.45% on Kvasir v2.
Demirbaş et al. [6] proposed a Spatial-Attention ConvMixer (SAC) architecture for classifying gastrointestinal diseases, enhancing the ConvMixer model with a spatial attention mechanism. Evaluated on the Kvasir dataset (containing images across eight classes), the proposed SAC model achieved an accuracy of 93.37%, outperforming other architectures like Vanilla ViT, Swin Transformer, and the original ConvMixer. Lafraxo and El Ansari [25] developed “GastroNet,” a custom CNN that achieved 96.89% accuracy on the KVASIR dataset for automated gastrointestinal abnormality detection from endoscopic images.
2.3 Vision Transformers and Attention-Based Models
More recently, transformer-based architectures have entered the field of medical imaging, with Vision Transformers (ViTs) showing competitive or superior performance to CNNs on large-scale natural image benchmarks [15]. Dosovitskiy et al. [26] proposed the original ViT model, demonstrating that when trained on sufficient data, ViTs could match CNNs in classification accuracy while offering improved attention-based interpretability.
Varam et al. [14] proposed the on-edge deployment of Vision Transformers (ViTs) for medical diagnostics, applying quantization techniques to optimize model size without compromising performance on the Kvasir-Capsule dataset. Evaluating seven ViT models, including EfficientFormerV2S2 and MobileViT_V2, they showed that MobileViT_V2_175 with F16 quantization achieved the highest F1-score of 0.9534, while MobileViT_V2_050 with QAT offered the smallest size (1.70 MB) and best performance-to-size ratio (41.25). Similarly, Regmi et al. [27] proposed a study comparing Vision Transformers (ViTs) and Convolutional Neural Networks (CNNs) for efficient medical image classification across three datasets: Chest X-ray, Kvasir, and Kvasir-Capsule. Utilizing various ViT models (e.g., ViT-L/16, ViT-B/16) and data augmentation, they demonstrated that ViT-L/16 achieved the highest F1-scores of 0.9532 for Chest X-ray and 0.9436 for Kvasir. For the Kvasir-Capsule dataset, ViT-B/16 achieved a weighted F1-score of 0.7156.
Lima et al [28] proposed using Visual Transformers (ViTs) to classify Video Capsule Endoscopy (VCE) images, aiming to assist in the diagnosis of gastrointestinal tract abnormalities. Evaluating their ViT-based model on the Kvasir-Capsule dataset (11 classes), they reported a high average accuracy of 99.70%, with a precision of 99.64%, sensitivity of 99.86%, and an F1-score of 99.54%.
Vu et al. [29] proposed PyBoFormer, a novel deep neural network architecture for polyp segmentation. This model enhances the task by integrating a Transformer encoder (MViT) and a stage-wise feature pyramid decoder structure with a Global-Local Context Aggregation (GLCA) module. Evaluated on multiple polyp datasets, including Kvasir-SEG and ClinicDB, PyBoFormer achieved state-of-the-art performance, with Dice scores of 93.4% on Kvasir and 96.0% on ClinicDB.
Gautam et al. [30] introduced Kvasir-VQA-x1, a large-scale multimodal dataset for medical visual question answering (MedVQA) in gastrointestinal (GI) endoscopy, featuring 159,549 complex QA pairs stratified by reasoning difficulty. Designed to test clinical reasoning and robustness, the dataset includes weakly augmented images and supports both standard and perturbed evaluation tracks. Fine-tuned models like Qwen2.5-VL and MedGemma achieved up to 90% accuracy, but performance declined on higher complexity levels, indicating challenges in multi-hop clinical reasoning. Wang et al. [31] introduced a Vision Transformer with Hybrid Shifted Windows (HSW Transformer) for gastrointestinal endoscopy image classification. This model addresses the challenge of capturing long-range dependencies in images with widely distributed features, a limitation of prior ViTs like Swin Transformer. Tested on Kvasir v2 and HyperKvasir datasets, HSW Transformer achieved accuracies of 95.42% and 86.81% respectively, showcasing its improved ability to capture both short and long-range dependencies.
Geetha et al. [32] proposed a hierarchical Vision Transformer for polyp segmentation, replacing CNN backbones. Their model, with a multi-stage transformer encoder, achieved mean Dice and IoU scores of 74% and 73% on the Kvasir-SEG dataset, demonstrating strong performance even on smaller datasets.
2.4 Beyond White-Light RGB Imaging
The studies above, like the present work, operate on conventional white-light RGB endoscopic images. A complementary line of research seeks to enrich the information available to the classifier at the imaging stage. Wang et al. [38] combined hyperspectral imaging with YOLO-based detection to classify superficial esophageal neoplasms (normal esophagus, squamous dysplasia, and squamous cell carcinoma) in white-light and narrow-band images. Huang et al. [39] proposed the Spectrum-Aided Vision Enhancer (SAVE), a calibrated software transformation that converts white-light images into hyperspectral-like and narrow-band-like representations without dedicated hardware, and reported higher four-class accuracy with SAVE images than with the original images across five CNNs trained on images drawn from Kvasir and the ETIS-Larib polyp database. Chou et al. [40] applied SAVE to four Kvasir classes (normal mucosa, ulcerative colitis, polyps, and esophagitis) and found that the benefit depended on the architecture: accuracy rose from 85% to 91% for VGG16 and from 79% to 89% for YOLOv8x, but was unchanged at 94% for InceptionV3. These approaches seek to expose tissue characteristics that are not visible in RGB and are therefore relevant to the question of clinically meaningful feature extraction examined in Section 4.6. The present study deliberately restricts itself to RGB images, which remain the output of standard endoscopy systems and the modality of public benchmarks such as Kvasir. Whether the accuracy–efficiency conclusions reported here transfer to spectrally enhanced inputs, which add a pre-processing stage and, for hyperspectral inputs, increase input dimensionality and computational cost, remains an open question.
2.5 Research Gap and Positioning of This Study
While these transformer- and CNN-based approaches have advanced automated GI disease diagnosis, many focus on narrower tasks such as binary classification or polyp segmentation, and the studies that do compare CNNs and transformers for multi-class GI classification (for instance, Regmi et al. [27], Wang et al. [31], and Demirbaş et al. [6]) typically emphasize raw accuracy or propose new architectures rather than jointly characterizing the accuracy–efficiency–interpretability trade-off relevant to deployment. The contribution here is a controlled, deployment-oriented benchmark of an off-the-shelf ResNet50 and ViT-B/16 under an identical, reproducible protocol, in which the comparison is (i) made on a fixed, stratified, seeded test split and replicated with stratified group 5-fold cross-validation; (ii) tested for both difference and equivalence (McNemar's test, the TOST procedure and confidence intervals) rather than reported as bare point estimates; (iii) characterized in terms of computational cost (MACs, parameters, memory, throughput) alongside accuracy, so that the practical cost of any accuracy difference is explicit; and (iv) accompanied by multi-method attribution analysis, a test for reliance on an acquisition artefact, and an external evaluation. The intended scientific contribution is therefore not a new architecture or a new state-of-the-art number, but evidence about whether, once efficiency and statistical uncertainty are considered, a lightweight CNN remains a defensible default for resource-constrained GI screening relative to a standard ViT, a question of direct relevance to low-resource clinical settings.
3 Methodology
This section describes the dataset, the experimental pipeline, the model architectures compared, the training and evaluation protocol, and the statistical and interpretability methods used. A central design goal of this study is reproducibility: the primary results are derived from a single, fixed, stratified, seeded data split that is shared identically by all models, and are replicated with stratified group 5-fold cross-validation using identical folds for ResNet50 and ViT-B/16, so that any observed difference is attributable to the architectures themselves rather than to differences in data partitioning or training conditions. An overview of the complete pipeline is shown in Figure 1.

Figure 1: Overview of the revised benchmarking pipeline: provenance and near-duplicate screening, preprocessing, the primary stratified split and stratified group 5-fold cross-validation, the three architectures trained under an identical protocol, and the evaluation of accuracy, equivalence, calibration, efficiency, interpretability, shortcut reliance and external generalization.
3.1 Dataset
For our experiments, we utilized the Kvasir dataset [17], a publicly available collection of verified and annotated endoscopic images of the gastrointestinal tract developed to aid computer-aided diagnosis (CADx) in gastrointestinal endoscopy. We used the original public release (Kvasir v1, obtained from its Kaggle mirror), which comprises 4,000 images with resolutions from to pixels distributed across eight clinically relevant classes: dyed-lifted-polyps, dyed-resection-margins, esophagitis, normal-cecum, normal-pylorus, normal-z-line, polyps, and ulcerative-colitis; which include anatomical landmarks, pathological findings, and procedural scenes: (1) Anatomical landmarks: normal-cecum, normal-pylorus, normal-z-line (2) Pathological findings: esophagitis, polyps, ulcerative-colitis (3) Procedural classes: dyed-lifted-polyps, dyed-resection-margins. Each class contains exactly 500 images (Table 1). Representative example images from each class are shown in Figure 2, illustrating the visual variability across anatomical landmarks and pathological findings. The near-balanced distribution mitigates the risk of the models being biased toward a majority class, although, as discussed in Sections 4.5 and 4.9, it does not reflect the true clinical prevalence of these conditions.
Provenance and independence of observations: Kvasir images were retrieved from routine gastroscopy and colonoscopy examinations at Bærum Hospital (Vestre Viken Hospital Trust, Norway) and labelled by medical experts; this release contains the first 4,000 labelled images and was later extended in Kvasir v2 and HyperKvasir [4, 17]. The release organises images by class but provides no patient, examination or video identifiers and no EXIF metadata, so a patient- or procedure-level split cannot be constructed. The accessible metadata are summarised in Table 1. Upper-GI classes (esophagitis, normal-pylorus, normal-z-line) were mostly acquired at 1280 × 1024 pixels, whereas lower-GI and procedural classes were mostly 720 × 576. Many lower-GI images contain a green picture-in-picture inset from the ScopeGuide endoscope-position system (Figure 3). Detected automatically, it occurs in 96.6% of normal-cecum, 71.2% of dyed-lifted-polyps, 70.2% of dyed-resection-margins, 50.2% of polyps and 22.0% of ulcerative-colitis images, and in none of the upper-GI images. Because the inset is strongly class-dependent but carries no pathological information, it is a candidate shortcut; Section 4.6 tests whether the models rely on it. To limit leakage through visually near-identical images, we screened all image pairs with 64-bit perceptual hashes (Hamming distance ≤ 6) and cosine similarity of ImageNet-pretrained ResNet50 embeddings (≥ 0.97), inspected the highest-scoring pairs visually, which confirmed that they are identical images stored under different file names (Figure 4), and merged near-duplicates into groups (connected components) that were kept within a single cross-validation fold. Because the combined criterion produced a cluster larger than 1% of the dataset, only the perceptual-hash criterion was used for grouping, giving 3,771 groups (118 with more than one image; largest 43 images).
Table 1: Class distribution and accessible provenance metadata of the Kvasir dataset used in this study (no EXIF metadata were present in any image).
| Class | Images (%) | Most common resolution | Distinct resolutions | ScopeGuide inset (%) |
|---|---|---|---|---|
| dyed-lifted-polyps | 500 (12.5) | 720 × 576 | 2 | 71.2 |
| dyed-resection-margins | 500 (12.5) | 720 × 576 | 1 | 70.2 |
| esophagitis | 500 (12.5) | 1280 × 1024 | 3 | 0.0 |
| normal-cecum | 500 (12.5) | 720 × 576 | 1 | 96.6 |
| normal-pylorus | 500 (12.5) | 1280 × 1024 | 3 | 0.0 |
| normal-z-line | 500 (12.5) | 1280 × 1024 | 3 | 0.0 |
| polyps | 500 (12.5) | 720 × 576 | 3 | 50.2 |
| ulcerative-colitis | 500 (12.5) | 720 × 576 | 4 | 22.0 |
| Total | 4,000 (100) | — | 4 | 38.8 |
Representative Kvasir images per class (N = 4000)
dyed-lifted-polyps

dyed-resection-margins

esophagitis

normal-cecum

normal-pylorus

normal-z-line

polyps

ulcerative-colitis

Figure 2: Representative endoscopic images (four per class) from each of the eight Kvasir classes.
ScopeGuide overlay detector check (top: detected, red box = occlusion region; bottom: not detected)

Figure 3: The ScopeGuide picture-in-picture inset, an acquisition artefact that occurs only in lower-GI and procedural classes. Top row: images in which the inset was detected automatically (red box: the region blacked out in the shortcut test, Section 4.6); bottom row: images without the inset.
Hamming 0. cosine 0.0000
train | uterative-collis

Hamming 0. cosine 0.0000
val | esophagitis

Hamming 0. cosine 0.0000
val | dyed-lifted-polyps

val | dyed-lifted-polyps
Hamming 0. cosine 0.0000
val | normal-cecum
Hamming 2. cosine 0.0000
train | esophagitis

Hamming 2. cosine 0.0000
train | polyps
Figure 4: The six highest-ranked near-duplicate image pairs that cross the training, validation and test subsets of the primary split, with their perceptual-hash Hamming distance and embedding cosine similarity. These pairs are identical images stored under different file names. All candidate pairs were merged into groups that were kept within a single cross-validation fold, and the 37 affected test images were removed in a sensitivity analysis (Section 4.3).
3.2 Image Preprocessing and Augmentation and Data Splitting
All images were resized to 224 x 224 pixels to match the input dimensions expected by both ResNet50 and ViT-B/16, and pixel intensities were normalized using the ImageNet channel means (0.485, 0.456, 0.406) and standard deviations (0.229, 0.224, 0.225) under which the pretrained backbones were trained. To improve generalization without altering the validation or test distributions, data augmentation was applied to the training subset only and consisted of random horizontal flipping and random rotations of up to plus or minus 15 degrees. The validation and test subsets received no augmentation; they used only resizing and normalization. The identical preprocessing and augmentation configuration was applied to both models.
The dataset was partitioned once into training (80%), validation (10%), and test (10%) subsets using stratified sampling, producing 3,200 training, 400 validation and 400 test images (50 test images per class). The split was generated with a fixed random seed (seed = 42) applied to the Python, NumPy and PyTorch random number generators, with cuDNN in deterministic mode, saved to disk, and reused without modification for every model, so that all models were evaluated on exactly the same test images; this is what makes the paired comparisons in Section 4.3 valid.
Cross-validation: To determine whether conclusions depend on this particular partition, we additionally performed stratified group 5-fold cross-validation over all 4,000 images, with the near-duplicate groups of Section 3.1 never split across folds. In each fold the held-out fold (777–842 images) served as the test set and the remaining images were divided 8:1 into training and validation subsets, again stratified and group-aware. ResNet50 and ViT-B/16 were trained on identical folds with the protocol of Section 3.3 and a fold-specific seed (42 + fold index). Pooling the out-of-fold predictions yields one paired prediction per image for each model (n = 4,000), the basis of the confirmatory analyses in Section 4.3.
3.3 Model Architectures and Training Configuration
Convolutional neural networks (CNNs) were among the earliest deep learning architectures to achieve clinically meaningful performance in medical image classification and segmentation [33–35]. We compare two representative, widely used architectures, each initialized with ImageNet-pretrained weights (torchvision IMAGENET1K_V2 for ResNet50 and IMAGENET1K_V1 for ViT-B/16) so that both benefit from large-scale natural-image features before fine-tuning on the gastrointestinal data. The two backbones embody fundamentally different inductive biases local convolution versus global self-attention which is precisely the contrast this study sets out to evaluate.
ResNet50 (convolutional neural network). ResNet50 [36, 37] is a 50-layer convolutional neural network organized into a stem (a convolution followed by max pooling) and four sequential stages of bottleneck residual blocks, with progressively increasing channel depth and decreasing spatial resolution. Each residual block applies a sequence of , , and convolutions and adds the block's input back to its output through an identity skip connection; these skip connections mitigate the vanishing-gradient problem and allow stable optimization of very deep networks. Because convolutions operate over local receptive fields with shared weights, the network learns hierarchical, locally biased spatial features — edges and textures in early stages, and larger structures and object-level patterns in deeper stages while remaining comparatively lightweight (23.5M parameters). After the final stage, a global average-pooling layer collapses the feature maps into a single feature vector that is passed to the classifier. For our 8-class task, the original 1000-way
ImageNet head was replaced with an 8-way fully connected layer, and all layers were fine-tuned end-to-end. The overall architecture is illustrated in Figure 5.
ResNet50 — Convolutional Neural Network

Feature maps shrink spatially and grow in channel depth across the four residual stages.
Figure 5: ResNet50 architecture — convolutional stem, four stages of bottleneck residual blocks with identity skip connections, global average pooling, and an 8-way classification head.
ViT-B/16 (Vision Transformer). ViT-B/16 [26] is the base Vision Transformer operating on image patches. The input is divided into a grid of non-overlapping patches (196 patches in total); each patch is flattened and linearly projected into a token embedding, a learnable position embedding is added to retain spatial order, and a special classification token is prepended to the sequence. The resulting token sequence is processed by a stack of twelve transformer encoder blocks, each consisting of multi-head self-attention followed by a feed-forward multilayer perceptron, with layer normalization and residual connections around both sub-layers. Unlike convolution, self-attention lets every patch attend to every other patch from the very first layer, so the model can capture global, long-range dependencies directly rather than building them up gradually through depth; this expressiveness comes at a higher computational and parameter cost (85.8M parameters). Classification is performed from the final-layer classification token through an MLP head. We used the torchvision ViT-B/16 model, replaced its head with an 8-way linear layer, and fine-tuned the network end-to-end under the same protocol as ResNet50. The overall architecture is illustrated in Figure 6.
Both models were trained under an identical optimization protocol to ensure a fair comparison. Training used the AdamW optimizer with an initial learning rate of and weight decay of , a cosine-annealing learning-rate schedule, a batch size of 32, and cross-entropy loss with label smoothing of 0.05. Models were trained for up to 30 epochs with early stopping (patience of 7 epochs) monitoring the validation macro-averaged F1-score; the checkpoint achieving the best validation macro-F1 was retained for all subsequent evaluation. Under this policy ResNet50 reached its best validation macro-F1 (0.935) at epoch 8 and stopped at epoch 15 (39 s per epoch, 10.1 min in total), whereas ViT-B/16 reached its best value (0.935) at epoch 20 and stopped at epoch 27 (118 s per epoch, 55.2 min). All experiments were run in PyTorch 2.10 on a single NVIDIA Tesla T4 GPU (16 GB) in a Kaggle notebook; images were decoded and resized once and cached in memory, and data loading used no worker processes.
Label-smoothing ablation: Because label smoothing affects calibration [41], both models were also retrained on the primary split with label smoothing disabled ( ), all other settings unchanged (Section 4.5). Edge-optimized transformer: To examine whether a transformer designed for resource-constrained devices changes the picture, we also fine-tuned MobileViT-S [42]
ViT-B/16 — Vision Transformer

Every patch attends to every other patch from the first layer, capturing global context directly.
Figure 6: ViT-B/16 architecture — patch embedding of patches with positional encoding, twelve transformer encoder blocks (multi-head self-attention and MLP), and a classification-token MLP head producing the 8-way output.
(timm implementation, ImageNet-pretrained, 4.9M parameters) on the primary split under the same protocol. ViT-B/16 was retained as the main transformer baseline because it is the canonical and most widely reported vision transformer, including in prior Kvasir benchmarks [27], so the main comparison answers the question practitioners most often face: whether a standard pretrained transformer should replace a standard pretrained CNN.
3.4 Evaluation Metrics
Model performance was assessed exclusively on the held-out test set of 400 images, which contains no image seen during training or validation, so that all reported figures reflect generalization rather than memorization. We report overall accuracy, and per-class precision, recall, and F1-score, together with macro-averaged values. Precision is the fraction of predicted positives that are correct; recall (sensitivity) is the fraction of true positives that are correctly identified; and the F1-score is their harmonic mean. We additionally report multi-class ROC curves with per-class and micro-averaged area under the curve (AUC), and we summarize discriminative confusion structure using confusion matrices. To quantify uncertainty, 95% confidence intervals are reported for overall accuracy (Wilson score interval) and for per-class F1 (non-parametric bootstrap with 10,000 resamples).
Formally, for each class these metrics are defined in terms of the counts of true positives (TP), true negatives (TN), false positives (FP), and false negatives (FN) as given in Equations (1)–(5). Accuracy is the proportion of all predictions that are correct; precision is the proportion of positive predictions that are correct; recall (sensitivity) is the proportion of actual positives that are recovered; specificity is the proportion of actual negatives correctly identified; and the F1-score is the harmonic mean of precision and recall. For the multi-class setting, the macro-averaged F1 is the unweighted mean of the per-class F1-scores over the C = 8 classes (Equation (6)), which weights every class equally regardless of its support. Model calibration is quantified by the expected calibration error (ECE; Equation (7)), which bins the n test predictions into M = 15 equal-width confidence bins and accumulates the weighted gap between the accuracy and the mean confidence within each bin [43]. Because ECE depends on the binning scheme, we also report ECE with 10 equal-width and 15 equal-mass bins, class-wise ECE [44], the multi-class Brier score [45] and the negative log-likelihood
(NLL), defined in Equations (8) and (9), each with a 95% bootstrap confidence interval (10,000 resamples), and paired bootstrap intervals for the difference between models
where is the number of classes (); is the F1-score of class ; is the number of confidence bins; is the set of predictions in bin ; is the total number of test samples; and and are, respectively, the mean accuracy and mean predicted confidence of the predictions in bin .
where is the predicted probability of class k for image i, equals 1 if image i belongs to class k and 0 otherwise, and is the probability assigned to the true class of image i.
3.5 Statistical Comparison
Because the two models were evaluated on the same fixed test set, their predictions are paired and can be compared with McNemar's test, the standard paired test for two classifiers on a shared sample. McNemar's test is computed on the contingency table of cases where the two models agree or disagree, using the discordant pairs (cases correct for one model but not the other). We report both the continuity-corrected chi-square statistic and the exact binomial p-value, along with a 95% confidence interval for the difference in accuracy obtained by paired bootstrap resampling.
This allows us to test whether any observed accuracy difference is statistically meaningful rather than attributable to sampling variation.
Absence of a significant difference does not demonstrate equivalence. We therefore tested equivalence explicitly with the two one-sided tests (TOST) procedure [46] applied to the paired accuracy difference . Equivalence is declared at when the 90% confidence interval for lies entirely within . We set percentage points, i.e. we regard accuracy differences smaller than three images per hundred as not clinically meaningful for an eight-class decision-support tool whose outputs are reviewed by an endoscopist. The margin was fixed before the cross-validation was run, which is therefore the confirmatory analysis. So that readers can apply a different margin, we also report the smallest margin at which equivalence would be declared (the larger absolute bound of the 90% CI). TOST p-values use the paired standard error of Equation (10), where b and c are the numbers of images classified correctly by only one of the two models and n is the number of test images.
3.6 Computational Efficiency Profiling
To characterize deployment cost, we profiled each model's number of trainable parameters, multiply-accumulate operations (MACs) for a single 224 x 224 input, and inference latency, throughput and peak memory on GPU and CPU under the standardized protocol described below. These metrics quantify the practical price of each architecture independently of accuracy and are central to the model-selection question this study addresses.
Every measurement ran in a fresh process with the model in evaluation mode, gradients disabled (torch.inference_mode), random input tensors, and image decoding and pre-processing excluded. On the GPU (NVIDIA Tesla T4, 16 GB, CUDA 12.8) we ran 50 warm-up iterations followed by 200 timed iterations, repeated 5 times, in FP32 and FP16 (autocast), with torch.cuda.synchronize() around every timed call. On the CPU (Intel Xeon 2.0 GHz, 4 threads, 33.7 GB RAM) we used 10 warm-up and 50 timed iterations × 3 repeats at batch size 1, and 2 warm-up and 5 timed iterations × 3 repeats at batch size 32. We report single-image latency (batch size 1; median and interquartile range), throughput at batch size 32, peak GPU memory (torch.cuda.max_memory_allocated) and CPU inference memory, measured as the peak resident memory sampled every 2 ms during inference minus the resident memory immediately before it. Parameters and multiply-accumulate operations were counted with ptflops. Training cost (seconds per epoch and time to the best checkpoint) was taken from the cross-validation runs.
3.7 Interpretability Analysis
We examined model decision-making using Gradient-weighted Class Activation Mapping (Grad-CAM), which produces class-discriminative heatmaps highlighting the image regions most influential to a prediction. For ResNet50, Grad-CAM was computed at the final convolutional block; for ViT, it was computed at the final transformer block with an appropriate token-to-grid reshape. The maps are interpreted qualitatively; the energy-in-field-of-view score used in the original submission was dropped, because it only measures whether attribution avoids dark borders and overlays, and was replaced by the lesion-level analysis below.
To triangulate these findings, we additionally generated LIME (superpixel-based) and SHAP (gradient-based) attributions for both models and attention-rollout maps for ViT. Consistent with Section 4.9, these maps are treated as exploratory evidence of clinical plausibility rather than as proof of clinically valid reasoning.
Lesion-level localization: To test whether attribution falls on disease-associated mucosa rather than merely inside the field of view, we used Kvasir-SEG [19], which provides pixel masks, drawn by a medical doctor and verified by an experienced gastroenterologist, for 1,000 polyp images from Kvasir v2. Few of these images are in the Kvasir v1 release used here (9 near-identical by perceptual hash), so we evaluated localization on Kvasir-SEG images not seen in training: the 107 images within Hamming distance 10 of any training or validation image were excluded, leaving 893 eligible images, of which a random sample of 500 was analysed. The class polyps was explained with Grad-CAM (both models) and ViT attention rollout on all 500 images, and with SHAP GradientExplainer and LIME (both models) on 50 of them, because these two methods are computationally expensive. We computed the pointing-game hit rate [47] (whether the attribution maximum lies inside the lesion), the energy-in-lesion fraction (Equation (11), where A is the non-negative attribution map, M the binary lesion mask and ⊙ element-wise multiplication; its chance level equals the lesion's area fraction), and the IoU of the top-20% attribution region with the mask. Shortcut test. To test whether models rely on the ScopeGuide inset (Section 3.1), we blacked out the inset in every test image containing it and compared each model's predictions before and after occlusion with McNemar's test. For 40 of these images we also measured the share of attribution mass that each method placed on the inset, compared with the inset's area fraction.
3.8 External Evaluation and Prevalence Analysis
External evaluation: GastroVision [48] contains 8,000 endoscopic images in 27 classes acquired at Bærum Hospital (Norway) and Karolinska University Hospital (Sweden). Seven of its classes correspond to Kvasir classes (cecum, pylorus, gastroesophageal junction/normal Z-line, esophagitis, colon polyps, dyed-lifted polyps and dyed-resection margins; it has no ulcerative-colitis class), giving 2,150 images. Because part of GastroVision comes from the same hospital as Kvasir, we removed the 152 images within Hamming distance 6 of any Kvasir image, leaving 1,998 images. The primary-split models were applied unchanged. GastroVision is therefore a partially independent, naturally imbalanced external set rather than a fully independent validation.
Prevalence: To examine behaviour at clinical prevalence, we computed positive predictive values (PPV) at prevalences of 1–20% from each model's cross-validated sensitivity and false-positive rate, and compared calibration on the out-of-fold predictions re-weighted to an illustrative screening-like class prior (75% normal landmarks), with and without prior-shift correction of the softmax outputs.
4 Results and Discussion
This section reports the outcomes on the shared, stratified test set of 400 images and in cross-validation. We present classification performance (Section 4.1), confusion and ROC analysis (4.2), the statistical comparison including the cross-validation (4.3), computational efficiency, training cost and convergence (4.4), calibration and predictive values under prevalence shift (4.5), interpretability and the shortcut test (4.6), and the external evaluation (4.7), followed by the discussion (4.8) and limitations (4.9).
4.1 Classification Performance
On the held-out test set, ResNet50 achieved an overall accuracy of 93.75% (375 of 400 images) and ViT-B/16 92.25% (369 of 400), a difference of six images; macro-averaged F1 was 0.937 and 0.922. MobileViT-S reached 95.50% (382 of 400; macro-F1 0.955). The training and validation curves of the two main models are shown in Figure 7. ResNet50 reached its best validation macro-F1 at epoch 8, whereas ViT required 20 epochs and its validation curve fluctuated more (for example, validation accuracy dropped to 85.3% at epoch 10). Both models approached 100% training accuracy, with a train–validation gap of about 5–7 percentage points that the early-stopping and best-checkpoint policy controls. The per-class precision, recall, and F1-scores are reported in Table 2 (ViT) and Table 3 (ResNet50).
ViT-B/16: loss

ViT-B/16: accuracy
ResNet50: loss
ResNet50: accuracy

Figure 7: Training and validation loss and accuracy curves of ViT-B/16 (upper panels; best validation macro-F1 0.935 at epoch 20, early stopping at epoch 27) and ResNet50 (lower panels; best validation macro-F1 0.935 at epoch 8, early stopping at epoch 15).
As shown in Table 2, ViT attained perfect recall for normal-cecum and normal-pylorus; its lowest recall and F1 were for esophagitis (recall 84.0%, F1 0.848) and normal-z-line (F1 0.851). As shown in Table 3, ResNet50 attained perfect recall for dyed-resection-margins, normal-cecum and normal-pylorus and perfect precision for dyed-lifted-polyps and ulcerative-colitis; its lowest recall was for esophagitis (84.0%) and dyed-lifted-polyps (86.0%). For both models the weakest classes were esophagitis and normal-z-line (F1 0.85–0.86), whereas the normal landmarks exceeded 0.97.
Table 2: ViT-B/16 per-class classification report on the held-out test set.
| Class | Precision | Recall | F1-score | Support |
|---|---|---|---|---|
| dyed-lifted-polyps | 0.936 | 0.880 | 0.907 | 50 |
| dyed-resection-margins | 0.889 | 0.960 | 0.923 | 50 |
| esophagitis | 0.857 | 0.840 | 0.848 | 50 |
| normal-cecum | 0.980 | 1.000 | 0.990 | 50 |
| normal-pylorus | 0.962 | 1.000 | 0.980 | 50 |
| normal-z-line | 0.843 | 0.860 | 0.851 | 50 |
| polyps | 0.978 | 0.880 | 0.926 | 50 |
| ulcerative-colitis | 0.941 | 0.960 | 0.950 | 50 |
| Macro avg | 0.923 | 0.922 | 0.922 | 400 |
| Accuracy | 0.922 | 400 |
Table 3: ResNet50 per-class classification report on the held-out test set.
| Class | Precision | Recall | F1-score | Support |
|---|---|---|---|---|
| dyed-lifted-polyps | 1.000 | 0.860 | 0.925 | 50 |
| dyed-resection-margins | 0.877 | 1.000 | 0.935 | 50 |
| esophagitis | 0.875 | 0.840 | 0.857 | 50 |
| normal-cecum | 0.962 | 1.000 | 0.980 | 50 |
| normal-pylorus | 0.980 | 1.000 | 0.990 | 50 |
| normal-z-line | 0.846 | 0.880 | 0.863 | 50 |
| polyps | 0.979 | 0.940 | 0.959 | 50 |
| ulcerative-colitis | 1.000 | 0.980 | 0.990 | 50 |
| Macro avg | 0.940 | 0.938 | 0.937 | 400 |
| Accuracy | 0.938 | 400 |
4.2 Confusion Matrices and ROC Analysis
The confusion matrices are shown in Figure 8. Both are strongly diagonal. For both models, most errors fall in two clinically adjacent class pairs: esophagitis versus normal-z-line (14 of 25 ResNet50 errors and 15 of 31 ViT errors) and dyed-lifted-polyps versus dyed-resection-margins (7 and 8 errors). Together these pairs account for 84% of ResNet50 errors and 74% of ViT errors on the test split, and for 70% of the errors of both models in the cross-validation (Section 4.3). Mild esophagitis at the gastro-esophageal junction can resemble a normal Z-line, and endoscopists themselves agree poorly on low-grade esophagitis in this region ( among 91 endoscopists [49]); the two dyed classes share the same chromoendoscopic appearance and differ mainly in procedural context. The residual errors therefore reflect intrinsically ambiguous distinctions more than architecture-specific failures. The multi-class ROC curves (Figure 9) show micro-averaged AUCs of 0.990 (ResNet50) and 0.991 (ViT), with per-class AUCs between 0.96 and 1.00 for both models.

Figure 8: Confusion matrices of ViT-B/16 (left) and ResNet50 (right) on the held-out test set (n = 400).

Figure 9: Multi-class ROC curves of ViT-B/16 (left) and ResNet50 (right) with per-class and micro-averaged AUC.
4.3 Statistical Significance Analysis
To compare the two models rigorously rather than by point estimates alone, we computed a complete set of statistics on the shared 400-image test set: overall accuracy with 95% Wilson score confidence intervals; macro-averaged F1 with 95% non-parametric bootstrap confidence intervals (10,000 resamples); McNemar's paired test (both the continuity-corrected chi-square statistic and the exact binomial p-value) on the discordant predictions; a 95% paired-bootstrap confidence interval for the difference in accuracy; and per-class F1 with 95% bootstrap confidence intervals. The overall-performance statistics and the paired comparison are summarized in Table 4, the McNemar contingency table is given in Table 5, and the per-class confidence intervals in Table 6.
Table 4: Overall test-set performance of ResNet50 and ViT-B/16 with 95% confidence intervals and the paired statistical comparison (n = 400).
| Metric | ResNet50 [95% CI] | ViT-B/16 [95% CI] |
|---|---|---|
| Correct predictions | 375 / 400 | 369 / 400 |
| Overall accuracy (Wilson CI) | 93.75% [90.94, 95.73] | 92.25% [89.21, 94.49] |
| Macro-averaged F1 (bootstrap CI) | 0.937 [0.913, 0.960] | 0.922 [0.895, 0.947] |
| Accuracy difference (R50 – ViT), 95% paired bootstrap CI | +1.50 pp [-0.50, +3.50] | (paired) |
| 90% CI for the difference / TOST p (3 pp) | [0.00, +3.25] / 0.066 | (paired) |
| McNemar exact p / (continuity-corrected) | p = 0.21 |
Because the accuracy difference between the two models is small (1.50 percentage points), we tested both whether it is significant and whether the models are equivalent. Of the 400 test images, both models were correct on 364, both were wrong on 20, ResNet50 alone was correct on 11 and ViT alone on 5 (Table 5). McNemar's test on the 16 discordant pairs gave a continuity-corrected chi-square of 1.56 and an exact p-value of 0.21, and the 95% paired-bootstrap interval for the difference (ResNet50 minus ViT) was [-0.50%, +3.50%].
Table 5: McNemar's paired contingency table comparing ResNet50 and ViT on the shared test set.
| Models | ViT correct | ViT incorrect |
|---|---|---|
| ResNet50 correct | 364 | 11 |
| ResNet50 incorrect | 5 | 20 |
| McNemar's test | exact p = 0.21 |
The difference is therefore not statistically significant, but a non-significant result does not establish equivalence. With 400 test images the 90% confidence interval for the difference was [0.00, +3.25] percentage points, so equivalence within points could not be shown on this split (TOST p = 0.066; the smallest margin at which equivalence would be declared is 3.25 points). At the class level (Table 6) the bootstrap intervals for per-class F1 overlap for every class; overlapping intervals are not a formal test, and with 50 test images per class the split is not powered to detect or exclude class-level differences. Removing the 37 test images that had a candidate near-duplicate in the training or validation data left the result unchanged (ResNet50 vs. ViT , n = 363, McNemar p = 0.18).
Table 6: Per-class F1-score with bootstrap confidence intervals for both models on the test set.
| Class | ResNet50 F1 [95% CI] | ViT-B/16 F1 [95% CI] |
|---|---|---|
| dyed-lifted-polyps | 0.92 [0.86, 0.98] | 0.91 [0.84, 0.96] |
| dyed-resection-margins | 0.93 [0.88, 0.98] | 0.92 [0.86, 0.97] |
| esophagitis | 0.86 [0.78, 0.93] | 0.85 [0.76, 0.92] |
| normal-cecum | 0.98 [0.95, 1.00] | 0.99 [0.97, 1.00] |
| normal-pylorus | 0.99 [0.97, 1.00] | 0.98 [0.95, 1.00] |
| normal-z-line | 0.86 [0.78, 0.93] | 0.85 [0.77, 0.92] |
| polyps | 0.96 [0.91, 0.99] | 0.93 [0.86, 0.97] |
| ulcerative-colitis | 0.99 [0.97, 1.00] | 0.95 [0.90, 0.99] |
Cross-validation (confirmatory analysis). Stratified group 5-fold cross-validation (Table 7) gave fold-wise accuracies of for ResNet50 and for ViT, and pooled out-of-fold accuracies of [91.25, 92.92] and [90.80, 92.52] over all 4,000 images. The pooled difference was percentage points ( CI to ; McNemar p = 0.39 on 178 vs. 161 discordant images), well inside the -point margin (TOST p < 0.001); equivalence would hold for any margin of 1.2 points or more. The mean fold-wise difference was also points ( t-interval to ). Cross-validated accuracy was about 1.5 points lower than on the primary split for both models, consistent with the smaller training sets and with the group-aware folds, which keep candidate near-duplicates out of the test folds. The out-of-fold confusion matrices (Figure 10) show the same error structure as the primary split.
4.4 Computational Efficiency
The models differ markedly in computational cost (Table 8 summarizes all metrics; Table 9 gives the standardized benchmark). ResNet50 has 23.52 million parameters and requires 4.13 GMACs per image, whereas ViT-B/16 has 85.80 million parameters and requires 17.61 GMACs, roughly 3.6 times more parameters and 4.3 times more computation. On the T4 GPU, ResNet50's single-image latency was 5.4 ms versus 13.1 ms for ViT, and its throughput at batch size 32 was 337 versus 88 images per second in FP32 (763 vs. 289 in FP16). On the CPU, single-image latency was 69 ms versus 177 ms and throughput 10.8 versus 5.2 images per second. Peak GPU memory at batch size 32 was 436 MB versus 595 MB. The efficiency gap extends to training: in cross-validation ResNet50
Table 7: Stratified group 5-fold cross-validation of ResNet50 and ViT-B/16 (n = 4,000 pooled out-of-fold predictions per model).
| Metric | ResNet50 | ViT-B/16 |
|---|---|---|
| Fold-wise accuracy, mean SD (%) | ||
| Fold-wise macro-F1, mean SD () | ||
| Pooled out-of-fold accuracy [95% Wilson CI] (%) | ||
| Pooled accuracy (R50 – ViT) [90% bootstrap CI] (pp) | (paired) | |
| McNemar exact p (pooled; discordant 178 / 161) | (paired) | |
| TOST p ( pp) / smallest equivalence margin (pp) | (paired) | |
| Fold-wise , mean [90% t-CI] (pp) | (paired) | |
| Best epoch, mean SD | ||
| Epoch time, mean (s) | ||
| Time to best checkpoint, mean (min) |

Figure 10: Out-of-fold confusion matrices of ResNet50 (left) and ViT-B/16 (right) from the 5-fold cross-validation (n = 4,000).
needed 35 s per epoch and reached its best checkpoint after 3.8 min on average, against 106 s and 15.8 min for ViT.
Table 8: Summary comparison of ResNet50, ViT-B/16 and MobileViT-S across accuracy, efficiency, calibration and robustness.
| Metric | ResNet50 | ViT-B/16 | MobileViT-S |
|---|---|---|---|
| Test accuracy, primary split (%) | 93.75 | 92.25 | 95.50 |
| Macro-F1, primary split | 0.937 | 0.922 | 0.955 |
| Cross-validated accuracy (%) | 92.12 | 91.70 | — |
| External accuracy, GastroVision (%) | 78.08 | 79.63 | 78.33 |
| Parameters (M) / MACs (G) | 23.52 / 4.13 | 85.80 / 17.61 | 4.94 / 1.24 |
| GPU throughput, batch 32, FP32 (img/s) | 336.5 | 87.9 | 444.4 |
| CPU latency, batch 1 (ms) | 69.4 | 176.6 | 53.5 |
| ECE, 15 bins: primary split / cross-validation | 0.025 / 0.021 | 0.039 / 0.023 | 0.032 / — |
| Accuracy change when the ScopeGuide inset is occluded (pp) | -1.3 (p = 0.69) | -4.0 (p = 0.15) | -9.4 (p < 0.001) |
Convergence: Across the five folds, ResNet50 reached its best validation macro-F1 at epoch 6.2 ± 1.5 and 99% of that value after 5.0 ± 1.6 epochs (2.9 ± 0.9 min), whereas ViT's best epoch varied widely (8.6 ± 7.5; range 2–21) and it needed 6.2 ± 4.6 epochs (11.0 ± 8.2 min) to reach 99% of its best value (Figure 11). The later best epoch of ViT on the primary split (20 vs. 8) is therefore not a stable property of the architecture: ViT's validation curve is noisier, so its best checkpoint occurs at an unpredictable epoch, and each epoch costs three times as much. The best validation macro-F1 values were similar (0.94 ± 0.01 vs. 0.93 ± 0.01).
MobileViT-S: MobileViT-S has 4.94 million parameters and 1.24 GMACs (a ptflops estimate that may undercount its attention operations). It had the lowest CPU latency (53.5 ms), the highest CPU throughput (13.1 images per second) and the highest FP32 GPU throughput (444 images per second), although its single-image GPU latency (7.6 ms) was higher than ResNet50's. At batch size 1, GPU latency is dominated by kernel-launch overhead, so FP16 did not reduce latency for ResNet50 or MobileViT-S. MobileViT-S's large early feature maps made it the most memory-hungry model on the CPU at batch size 32 (711 MB, against 445 MB for ResNet50 and 343 MB for ViT).
4.5 Calibration
Calibration results are reported in Table 10 and Figure 12. On the primary split, ResNet50 and ViT-B/16 had ECEs of 0.025 [0.017, 0.050] and 0.039 [0.023, 0.065] with 15 equal-width bins. The ranking, however, depended on the binning: with 10 equal-width bins ViT appeared better calibrated (0.020 vs. 0.025), whereas with 15 equal-mass bins ResNet50 was better (0.032 vs. 0.060;
Table 9: Standardized inference benchmark and training cost (Tesla T4 GPU; Intel Xeon 2.0 GHz CPU, 4 threads; PyTorch 2.10). Latencies are medians, with the interquartile range in brackets, over 1,000 timed GPU or 150 timed CPU iterations. Training cost is the cross-validation mean for ResNet50 and ViT-B/16 and the primary run for MobileViT-S.
| Metric | ResNet50 | ViT-B/16 | MobileViT-S |
|---|---|---|---|
| Parameters (M) | 23.52 | 85.80 | 4.94 |
| MACs (G) | 4.13 | 17.61 | 1.24 |
| GPU latency, batch 1, FP32 (ms) | 5.4 [5.3–5.5] | 13.1 [13.1–13.4] | 7.6 [7.5–7.8] |
| GPU latency, batch 1, FP16 (ms) | 5.8 [5.7–5.9] | 5.9 [5.8–6.1] | 10.0 [9.9–10.2] |
| GPU throughput, batch 32, FP32 (img/s) | 336.5 | 87.9 | 444.4 |
| GPU throughput, batch 32, FP16 (img/s) | 762.8 | 288.6 | 662.5 |
| Peak GPU memory, batch 32, FP32 (MB) | 436 | 595 | 512 |
| CPU latency, batch 1 (ms) | 69.4 [67.7–71.7] | 176.6 [173.3–182.5] | 53.5 [52.8–55.0] |
| CPU throughput, batch 32 (img/s) | 10.77 | 5.22 | 13.10 |
| CPU inference memory, batch 1 / 32 (MB) | 43 / 445 | 37 / 343 | 44 / 711 |
| Training time per epoch (s) | 35 | 106 | 30 |
| Time to best checkpoint (min) | 3.8 | 15.8 | 6.2 |

Figure 11: Convergence across the five cross-validation folds. Left: validation macro-F1 per epoch (mean ± SD); right: wall-clock minutes needed to reach 99% of each fold's best validation macro-F1.
paired difference -0.027 [-0.047, -0.001]. Class-wise ECE (0.017 for both), the Brier score (0.107 vs. 0.127) and NLL (0.248 vs. 0.291) did not differ significantly. In cross-validation, where 4,000 predictions give much tighter intervals, the models were indistinguishable (ECE 0.021 vs. 0.023, paired difference -0.001 [-0.011, +0.007]; Brier 0.122 vs. 0.128; NLL 0.265 vs. 0.272). Per-class ECE was highest for esophagitis and normal-z-line (0.023–0.029 on the primary split) and at most 0.017 for every class in cross-validation (Table 11 and Figure 13). The primary-split ECE ranking is therefore fragile; the reliability diagrams show why, as almost all predictions fall in the top confidence bin and the remaining bins hold only a handful of images each (Figure 12).
Reliability diagram, (numbers = images per bin)

Reliability diagram, (numbers = images per bin)
Figure 12: Reliability diagrams (15 equal-width bins; numbers are images per bin) for ResNet50 and ViT-B/16 trained with (left) and without (right) label smoothing.
Per-class (one-vs-rest) reliability diagrams, original split,

normal-pylorus
normal-z-line
polyps
ulcerative-collitis
Figure 13: Per-class (one-vs-rest) reliability diagrams of ResNet50 and ViT-B/16 on the primary split ( ), with per-class ECE (15 equal-width bins) in the legends.
Effect of label smoothing: Without label smoothing ( ), both models reached 93.75% on the primary split (8 vs. 8 discordant images; equivalent within points, TOST p = 0.001). ECE increased for both (ResNet50 0.025 → 0.045, ViT 0.039 → 0.050), consistent with the regularizing effect of smoothing on over-confidence [41]. The ResNet50 – ViT ECE difference was -0.014 [-0.036, +0.015] with smoothing and -0.005 [-0.024, +0.016] without, so label smoothing did not artificially narrow the calibration gap between the architectures; in both settings the gap was small and not significant.
Table 10: Calibration metrics with 95% bootstrap confidence intervals: primary split with () and without () label smoothing, MobileViT-S, and cross-validation (CV) out-of-fold predictions.
| Metric | ResNet50 | ViT-B/16 | ResNet50 | ViT-B/16 | Mobile-ViT-S | ResNet50 CV | ViT-B/16 CV |
|---|---|---|---|---|---|---|---|
| Accuracy | [,] | [,] | [,] | [,] | [,] | [,] | [,] |
| ECE, 15 equal-width bins | [,] | [,] | [,] | [,] | [,] | [,] | [,] |
| ECE, 10 equal-width bins | [,] | [,] | [,] | [,] | [,] | [,] | [,] |
| ECE, 15 equal-mass bins | [,] | [,] | [,] | [,] | [,] | [,] | [,] |
| Class-wise ECE | [,] | [,] | [,] | [,] | [,] | [,] | [,] |
| Brier score | [,] | [,] | [,] | [,] | [,] | [,] | [,] |
| NLL | [,] | [,] | [,] | [,] | [,] | [,] | [,] |
Table 11: Per-class (one-vs-rest) expected calibration error (15 equal-width bins) with 95% bootstrap confidence intervals. = label smoothing; CV = cross-validation out-of-fold predictions (n = 4,000).
| Class | ResNet50 | ViT-B/16 | ResNet50 | ViT-B/16 | Mobile-ViT-S | ResNet50 CV | ViT-B/16 CV |
|---|---|---|---|---|---|---|---|
| dyed-lifted-polyps | [,] | [,] | [,] | [,] | [,] | [,] | [,] |
| dyed-resection-margins | [,] | [,] | [,] | [,] | [,] | [,] | [,] |
| esophagitis | [,] | [,] | [,] | [,] | [,] | [,] | [,] |
| normal-cecum | [,] | [,] | [,] | [,] | [,] | [,] | [,] |
| normal-pylorus | [,] | [,] | [,] | [,] | [,] | [,] | [,] |
| normal-z-line | [,] | [,] | [,] | [,] | [,] | [,] | [,] |
| polyps | [,] | [,] | [,] | [,] | [,] | [,] | [,] |
| ulcerative-colitis | [,] | [,] | [,] | [,] | [,] | [,] | [,] |
Predictive values under prevalence shift: Kvasir is balanced, whereas pathological findings are much rarer in routine endoscopy. Using cross-validated sensitivities and false-positive rates (Figure 14; Table 12), the positive predictive value for esophagitis would fall from 0.87–0.89 at the 12.5% prevalence of the dataset to 0.70 (ResNet50) and 0.75 (ViT) at 5% prevalence and to 0.48 and 0.54 at 2%. For polyps, ViT's lower false-positive rate (0.4% vs. 1.1%) gives a higher PPV at 2% prevalence (0.82 vs. 0.63), whereas for ulcerative colitis the advantage is reversed (0.83 for ResNet50 vs. 0.59 for ViT). Class-level differences that are invisible in balanced accuracy can therefore translate into materially different predictive values at low prevalence. Re-weighting the out-of-fold predictions to an illustrative screening-like prior (75% normal landmarks; Table 13) left calibration low for both models (ECE 0.025 and 0.026), and prior-shift correction of the softmax outputs improved accuracy, Brier score and NLL for both (for example, Brier score 0.105 → 0.094 for ResNet50 and 0.102 → 0.090 for ViT).
Table 12: Positive predictive values (PPV) at 1–20% prevalence, computed from cross-validated sensitivity and false-positive rate (FPR); “precision at 12.5%” is the observed precision at the dataset prevalence.
| Model | Class | Sensitivity | FPR | Precision at 12.5% | PPV 1% | PPV 2% | PPV 5% | PPV 10% | PPV 20% |
|---|---|---|---|---|---|---|---|---|---|
| ResNet50 | esophagitis | 0.818 | 0.018 | 0.865 | 0.311 | 0.477 | 0.702 | 0.833 | 0.918 |
| ResNet50 | polyps | 0.948 | 0.011 | 0.924 | 0.462 | 0.635 | 0.817 | 0.904 | 0.955 |
| ResNet50 | ulcerative-colitis | 0.934 | 0.004 | 0.971 | 0.702 | 0.827 | 0.925 | 0.963 | 0.983 |
| ViT-B/16 | esophagitis | 0.812 | 0.014 | 0.892 | 0.369 | 0.542 | 0.753 | 0.866 | 0.935 |
| ViT-B/16 | polyps | 0.886 | 0.004 | 0.969 | 0.691 | 0.819 | 0.921 | 0.961 | 0.982 |
| ViT-B/16 | ulcerative-colitis | 0.972 | 0.014 | 0.910 | 0.417 | 0.591 | 0.789 | 0.887 | 0.947 |
PPV vs prevalence (shaded: down to the upper 95% bound of the false-positive rate)

Figure 14: Positive predictive value as a function of prevalence for esophagitis, polyps and ulcerative colitis, computed from cross-validated sensitivity and false-positive rate (shaded: down to the upper 95% bound of the false-positive rate).
4.6 Interpretability and Reliance on an Acquisition Artefact
Grad-CAM heatmaps for representative test images are shown in Figure 15, LIME and SHAP attributions in Figure 16, and ViT attention rollout in Figure 17. For most classes, the maps of
Table 13: Calibration of the cross-validated predictions re-weighted to an illustrative screening-like class prior (normal landmarks 25% each; esophagitis and polyps 8% each; ulcerative colitis and the two dyed classes 3% each), without and with prior-shift correction of the softmax outputs; 95% bootstrap confidence intervals.
| Metric | ResNet50 unadjusted | ResNet50 prior-shift corrected | ViT-B/16 unadjusted | ViT-B/16 prior-shift corrected |
|---|---|---|---|---|
| Accuracy | 0.930 [0.922, 0.938] | 0.944 [0.937, 0.951] | 0.934 [0.927, 0.942] | 0.948 [0.940, 0.954] |
| ECE, 15 equal-width bins | 0.025 [0.020, 0.033] | 0.021 [0.015, 0.028] | 0.026 [0.023, 0.033] | 0.023 [0.019, 0.029] |
| ECE, 10 equal-width bins | 0.021 [0.017, 0.029] | 0.020 [0.014, 0.027] | 0.027 [0.022, 0.034] | 0.021 [0.016, 0.028] |
| ECE, 15 equal-mass bins | 0.025 [0.020, 0.032] | 0.022 [0.018, 0.030] | 0.024 [0.020, 0.031] | 0.022 [0.019, 0.030] |
| Class-wise ECE | 0.016 [0.015, 0.018] | 0.012 [0.012, 0.015] | 0.016 [0.015, 0.018] | 0.010 [0.010, 0.013] |
| Brier score | 0.105 [0.095, 0.117] | 0.094 [0.084, 0.105] | 0.102 [0.093, 0.113] | 0.090 [0.080, 0.100] |
| NLL | 0.231 [0.211, 0.252] | 0.213 [0.192, 0.234] | 0.224 [0.206, 0.243] | 0.202 [0.184, 0.222] |
both models concentrate on the central mucosal field. The figures also reveal a potential shortcut: in the normal-cecum example, ResNet50's Grad-CAM concentrates on the green ScopeGuide inset in the lower-left corner rather than on the mucosa.
Lesion-level localization: On 500 unseen Kvasir-SEG polyp images (Table 14, Figure 18), both models concentrated attribution on the lesion well above chance. With Grad-CAM, the energy-in-lesion fraction was 0.553 [0.533, 0.573] for ResNet50 and 0.575 [0.552, 0.599] for ViT, against a chance level of 0.154 (the mean lesion area), and the attribution maximum fell inside the lesion in 86.8% and 72.8% of images. ResNet50's peak was therefore more often on the polyp (102 vs. 32 discordant images; exact p < 0.001), whereas ViT placed slightly more of its total attribution inside it (Wilcoxon p = 0.002). LIME favoured ResNet50 (energy-in-lesion 0.431 vs. 0.325, p < 0.001; n = 50), SHAP was the least localized method and did not differ between the models (0.270 vs. 0.252, p = 0.10), and ViT attention rollout was less focused than Grad-CAM (0.325). Both models also classified these unseen images correctly as polyps (97.8% and 95.8%), although the ScopeGuide region is blacked out in Kvasir-SEG. These findings agree with earlier work: Grad-CAM has been used to make polyp segmentation on Kvasir images transparent [50], and in diabetic foot ulcer segmentation a quantitative comparison against expert masks found Grad-CAM more lesion-localized than attention rollout, whereas attention rollout was more faithful to the model's computation [51]. ViT showed the same localization ordering here (energy-in-lesion 0.575 for Grad-CAM vs. 0.325 for attention rollout).
Reliance on the ScopeGuide inset. The inset was present in 149 of the 400 test images (normal-cecum 49, dyed-resection-margins 38, dyed-lifted-polyps 29, polyps 26, ulcerative-colitis 7). Blacking it out (Table 15) did not significantly affect ResNet50 (95.3% → 94.0%; 4 images lost, 2 gained; McNemar p = 0.69), reduced ViT's accuracy by 4.0 points (93.3% → 89.3%; p = 0.15),
Table 14: Lesion-level localization of the class polyps on unseen Kvasir-SEG images (mean [95% bootstrap CI]). The chance level of energy-in-lesion equals the lesion's area fraction.
| Method | n | Pointing-game hit rate | Energy-in-lesion | Chance level (lesion area) | IoU (top-20% map) |
|---|---|---|---|---|---|
| ResNet50 Grad-CAM | 500 | 0.868 [0.838, 0.896] | 0.553 [0.533, 0.573] | 0.154 [0.143, 0.165] | 0.396 [0.380, 0.412] |
| ViT-B/16 Grad-CAM | 500 | 0.728 [0.688, 0.766] | 0.575 [0.552, 0.599] | 0.154 [0.143, 0.165] | 0.350 [0.333, 0.367] |
| ViT-B/16 attention rollout | 500 | 0.624 [0.582, 0.666] | 0.325 [0.309, 0.340] | 0.154 [0.142, 0.165] | 0.337 [0.323, 0.350] |
| ResNet50 SHAP | 50 | 0.500 [0.360, 0.640] | 0.270 [0.221, 0.323] | 0.161 [0.122, 0.204] | 0.207 [0.179, 0.235] |
| ViT-B/16 SHAP | 50 | 0.500 [0.360, 0.640] | 0.252 [0.206, 0.301] | 0.161 [0.124, 0.203] | 0.173 [0.150, 0.197] |
| ResNet50 LIME | 50 | 0.600 [0.460, 0.740] | 0.431 [0.365, 0.495] | 0.161 [0.123, 0.203] | 0.301 [0.255, 0.349] |
| ViT-B/16 LIME | 50 | 0.580 [0.440, 0.720] | 0.325 [0.276, 0.376] | 0.161 [0.125, 0.204] | 0.244 [0.202, 0.285] |
and reduced MobileViT-S's accuracy by 9.4 points (96.6% → 87.2%; 14 images lost, none gained; p < 0.001). MobileViT-S's advantage on the primary split is therefore at least partly explained by reliance on an acquisition artefact rather than on pathology, and ResNet50 was the least sensitive of the three models. Because the inset occurs only in lower-GI and procedural classes, any model can use it to separate these from the upper-GI classes; the occlusion test is a simple, reproducible check that we recommend for any Kvasir benchmark.
Table 15: Shortcut test: accuracy on the 149 test images containing the ScopeGuide inset, before and after blacking out the inset.
| Model | n | Accuracy, original (%) | Accuracy, inset occluded (%) | Prediction flips (%) | Lost / gained | McNemar exact p |
|---|---|---|---|---|---|---|
| ResNet50 | 149 | 95.30 | 93.96 | 4.7 | 4 / 2 | 0.69 |
| ViT-B/16 | 149 | 93.29 | 89.26 | 8.1 | 9 / 3 | 0.15 |
| MobileViT-S | 149 | 96.64 | 87.25 | 10.7 | 14 / 0 | < 0.001 |
Attribution on the inset. In 40 of the test images containing the inset, ResNet50's maps placed slightly more attribution on the inset than its area fraction (0.183) would predict: 1.19 times chance for Grad-CAM, 1.32 for LIME and 1.36 for SHAP (Table 16). ViT's Grad-CAM and SHAP maps placed less than chance on it (0.73 and 0.82 times), whereas its attention rollout placed more (1.31 times). Attribution mass alone therefore does not show which model depends on the artefact:
ResNet50 attends to the inset to some extent, yet its predictions were the least affected by removing it (Table 15).
Table 16: Share of attribution mass falling on the ScopeGuide inset (mean over 40 test images containing the inset), compared with the inset's area fraction, the level expected for a map that ignores the inset.
| Method | Attribution mass on the inset | Inset area fraction (chance level) | Ratio to chance |
|---|---|---|---|
| ResNet50 Grad-CAM | 0.217 | 0.183 | 1.19 |
| ResNet50 LIME | 0.242 | 0.183 | 1.32 |
| ResNet50 SHAP | 0.248 | 0.183 | 1.36 |
| ViT-B/16 Grad-CAM | 0.133 | 0.183 | 0.73 |
| ViT-B/16 LIME | 0.203 | 0.183 | 1.11 |
| ViT-B/16 SHAP | 0.151 | 0.183 | 0.82 |
| ViT-B/16 attention rollout | 0.239 | 0.183 | 1.31 |
4.7 External Evaluation on GastroVision
On the 1,998 de-duplicated GastroVision images (Table 17), accuracy fell to 78.08% for ResNet50, 79.63% for ViT and 78.33% for MobileViT-S, 13–17 points below the internal results. ViT was 1.55 points more accurate than ResNet50 (95% CI −3.45 to +0.35; McNemar p = 0.12), and equivalence within ±3 points was narrowly missed (90% CI −3.10 to +0.05; TOST p = 0.067). MobileViT-S was equivalent to ResNet50 (+0.25 points; TOST p = 0.001), so its advantage on the internal split did not transfer, consistent with the shortcut test. Per-class sensitivity varied much more between models than overall accuracy did: ViT was more sensitive for normal-pylorus (0.87 vs. 0.67) and dyed-lifted-polyps (0.92 vs. 0.84), ResNet50 for polyps (0.82 vs. 0.76) and normal-z-line (0.71 vs. 0.67), and esophagitis remained the weakest class for all models (0.57–0.68). The external set is naturally imbalanced (polyps 37%, esophagitis 5%), so it also illustrates the prevalence effects discussed in Section 4. Specifically, this severe class imbalance exposes the vulnerabilities of models trained on artificially balanced data; model calibration and class-wise performance degraded sharply on minority classes like esophagitis (sensitivity of 0.57–0.68). This highlights how models can become systematically under-sensitive or miscalibrated when encountering the skewed prior probabilities characteristic of real-world clinical distributions. The confusion matrices (Figure 19) show that the external errors follow the same pattern as on Kvasir: esophagitis and normal-z-line were confused in both directions (35 and 86 images for ResNet50; 31 and 99 for ViT). ResNet50 labelled 61 pylorus images as normal-z-line, which explains its low pylorus sensitivity, and mislabelled polyps mainly as normal-cecum (60) and ulcerative colitis (47), whereas ViT labelled 106 polyps as ulcerative colitis, a class that does not occur in GastroVision.
vit: Grad-CAM per class (test)
dyed-lifted-polyps

dyed-resection-margins
normal-pylorus

esophagitis
normal-z-line

polyps
normal-cecum

ulcerative-colitis
resnet50: Grad-CAM per class (test)
dyed-lifted-polyps
dyed-resection-margins

normal-pylorus
esophagitis

normal-z-line

polyps
normal-cecum

ulcerative-colitis
Figure 15: Grad-CAM heatmaps of ViT-B/16 (top) and ResNet50 (bottom) for the first test image of each class. Note the ResNet50 activation on the ScopeGuide inset in the normal-cecum example.
resnet50: LIME per class (test)

normal-pylorus

normal-z-line

polys

ulcerative-collis
vit: LIME per class (test)
normal-pylorus
normal-z-line
polys
ulcerative-collis
resnet50: SHAP (GradientExplainer) per class (test)

normal-pylorus

normal-z-line

polys

ulcerative-collis
vit: SHAP (GradientExplainer) per class (test)
normal-pylorus
normal-z-line
polys
ulcerative-collis
Figure 16: LIME attributions (first image; ResNet50 above ViT-B/16) and SHAP GradientExplainer attributions (second image; ResNet50 above ViT-B/16) for the first test image of each class.
ViT: attention rollout per class (test)
dyed-lifted-polyps

dyed-resection-margins
normal-pylorus

normal-z-line
esophagitis

polyps
normal-cecum

ulcerative-colitis
Figure 17: ViT-B/16 attention-rollout maps for the first test image of each class.
image + mask
resnet50 Grad-CAM
vit Grad-CAM
vit attention rollout
resnet50 SHAP
vit SHAP
resnet50 LIME
vit LIME
image + mask
resnet50 Grad-CAM
vit Grad-CAM
vit attention rollout
resnet50 SHAP
vit SHAP
resnet50 LIME
vit LIME
image + mask
resnet50 Grad-CAM
vit Grad-CAM
vit attention rollout
resnet50 SHAP
vit SHAP
resnet50 LIME
vit LIME
image + mask
resnet50 Grad-CAM
vit Grad-CAM
vit attention rollout
resnet50 SHAP
vit SHAP
resnet50 LIME
vit LIME
image + mask
resnet50 Grad-CAM
vit Grad-CAM
vit attention rollout
resnet50 SHAP
vit SHAP
resnet50 LIME
vit LIME
Figure 18: Lesion-level localization on unseen Kvasir-SEG polyp images. First column: image with the expert polyp mask (green contour); remaining columns: Grad-CAM (ResNet50, ViT-B/16), ViT-B/16 attention rollout, SHAP (ResNet50, ViT-B/16) and LIME (ResNet50, ViT-B/16) maps for the class polyps, with the mask outlined in white. The black square is the ScopeGuide region, which is removed in Kvasir-SEG.
Table 17: External evaluation on GastroVision (seven classes shared with Kvasir; 1,998 images after removing 152 near-duplicates of Kvasir images): per-class sensitivity and overall performance.
| Class | n (prevalence) | ResNet50 | ViT-B/16 | MobileViT-S |
|---|---|---|---|---|
| dyed-lifted-polyps | 137 (6.9%) | 0.839 | 0.920 | 0.920 |
| dyed-resection-margins | 233 (11.7%) | 0.927 | 0.923 | 0.914 |
| esophagitis | 102 (5.1%) | 0.647 | 0.677 | 0.569 |
| normal-cecum | 103 (5.2%) | 0.825 | 0.864 | 0.786 |
| normal-pylorus | 365 (18.3%) | 0.671 | 0.871 | 0.836 |
| normal-z-line | 313 (15.7%) | 0.713 | 0.671 | 0.744 |
| polyps | 745 (37.3%) | 0.819 | 0.757 | 0.737 |
| Overall accuracy (%) | 1,998 | 78.08 | 79.63 | 78.33 |
| Macro-averaged recall | 0.777 | 0.812 | 0.787 | |
| Δ vs. ResNet50 [95% CI](pp); McNemar p | — | +1.55 [-0.35, +3.45]; 0.12 | +0.25 [-1.55, +2.00]; 0.83 |

Figure 19: Confusion matrices of ResNet50 (left) and ViT-B/16 (right) on the de-duplicated GastroVision subset (n = 1,998). GastroVision has no ulcerative-colitis images, so that row is empty and every prediction of ulcerative colitis is an error.
4.8 Discussion
The central finding is that, under a controlled and reproducible protocol, ResNet50 and ViT-B/16 are equivalent in accuracy for 8-class GI classification on Kvasir: in cross-validation over all 4,000 images the difference was 0.43 points with a 90% CI of -0.33 to +1.18, well inside a ±3-point margin. The single 400-image split, by contrast, could show neither a difference nor equivalence, which illustrates why a non-significant test on one split should not be read as evidence of equivalence. Much of the literature frames the CNN-versus-transformer question in terms of which architecture is more accurate; in this common transfer-learning regime on a moderately sized, curated dataset, the accuracy difference between the two is small.
Once accuracy is set aside as non-discriminating, efficiency decides, and here the architectures differ substantially: ResNet50 delivers equivalent accuracy with 3.6 times fewer parameters and 4.3 times fewer operations, 2.5 times lower CPU latency, 3.8 times higher GPU throughput, and about a quarter of the training time to its best checkpoint. For the resource-constrained settings that motivate this work, where compute, memory, energy and latency are genuine constraints, this makes the CNN the more defensible default relative to ViT-B/16. While our study positions MobileViT-S as the primary edge-optimized baseline to evaluate the transformer paradigm, future evaluations incorporating modern lightweight CNN architectures, such as EfficientNet or MobileNetV3, would further clarify whether the efficiency-accuracy trade-off can be optimized even further without relying on transformer components. ViT remains a reasonable choice where larger and more diverse training data are available, and it was slightly, though not significantly, more accurate on the external data.
Two further results qualify this conclusion. First, robustness to the ScopeGuide inset differed sharply between architectures. MobileViT-S, the most accurate and most CPU-efficient model on the primary split, lost 9.4 points when the inset was occluded and lost its advantage on external data, whereas ResNet50 was not significantly affected. Accuracy on a curated benchmark can therefore reward shortcut learning, and an edge-optimized model should not be selected on benchmark accuracy alone. To mitigate this, future training pipelines must proactively integrate targeted augmentation techniques such as applying random Cutout or explicitly masking the green ScopeGuide box during training to prevent models from exploiting non-pathological features. The interpretability analyses point the same way: both models localized polyps well above chance on unseen images, and attribution mass on the inset did not predict which model depended on it, so attribution maps alone did not separate the architectures, whereas the occlusion test did. Second, every model lost 13–17 points on partially independent external data, an order of magnitude more than the differences between architectures, and predictive values change substantially when prevalence shifts. Architecture choice should therefore be driven by deployment cost and explicit robustness checks, and no model should be deployed without local validation.
Our findings are broadly consistent with the subset of prior comparative studies that report similar accuracies for CNNs and transformers on Kvasir-family data (for example, the high but comparable accuracies reported by Regmi et al. [27], Wang et al. [31], and Demirbaş et al. [6]), while adding equivalence testing, cross-validation, a standardized efficiency benchmark, a shortcut test and an external evaluation, which those studies generally do not report. Rather than introducing a new architecture or claiming a new state-of-the-art number, the contribution here is methodological and practical: a reproducible, statistically tested, efficiency-aware benchmark that yields actionable model-selection guidance.
4.9 Limitations
This study has several limitations. First, the external evaluation is only partly independent: GastroVision shares a hospital (Bærum) with Kvasir, covers seven of the eight classes, and does not record the centre of each image, so it cannot replace a genuinely independent, ideally prospective, multi-centre validation. Second, Kvasir provides no patient, examination or video identifiers, so a patient-level split was impossible; perceptual-hash grouping limits but cannot eliminate correlated images across folds, and it is deliberately conservative (130 of the 255 candidate pairs crossed class boundaries, indicating that frame layout and the inset also drive hash similarity, although visual inspection confirmed that the top-ranked pairs are identical images). Third, we used the public 4,000-image Kvasir v1 release, which is balanced, so predictive values and calibration do not transfer directly to screening populations (Section 4.5). Fourth, the comparison uses standard matched training configurations rather than exhaustively tuned ones, MobileViT-S was evaluated only on the primary split, and the equivalence finding may shift under other training regimes or larger datasets. Fifth, the interpretability analyses remain partly qualitative: lesion-level annotations exist only for polyps, and the attribution maps have not yet been rated by endoscopists. A blinded rating package (randomised, model- and method-anonymised Grad-CAM, SHAP, LIME and attention-rollout maps) has been prepared for evaluation by gastroenterologists. Finally, efficiency was measured on one GPU and one cloud CPU and should be re-measured on the intended deployment device.
5 Conclusion
This study presented a controlled, reproducible benchmark of ResNet50 and ViT-B/16 for 8-class GI classification on the public Kvasir dataset (4,000 images). On a fixed 400-image test split the models did not differ significantly (93.75% vs. 92.25%; McNemar p = 0.21), and stratified group 5-fold cross-validation over all images showed them to be equivalent within ±3 percentage points (92.12% vs. 91.70%; 90% CI for the difference -0.33 to +1.18; TOST p < 0.001), with similar calibration. They differed substantially in cost: ResNet50 used 3.6 times fewer parameters and 4.3 times fewer operations, ran 2.5 times faster on a CPU with 3.8 times higher GPU throughput, and reached its best checkpoint about four times sooner. An edge-oriented transformer, MobileViT-S, was most accurate on the test split but depended strongly on an acquisition artefact, and all models lost 13–17 points on external data. The Grad-CAM maps of both CNN and transformer localized polyps on unseen images at about 3.6 times the chance level. Accuracy differences between architectures were thus small compared with the effects of shortcut learning and domain shift, while efficiency differences were large. ResNet50 is a defensible default for resource-constrained GI screening, provided that models are checked for artefact reliance and validated locally.
Future work should prioritise: (1) prospective, multi-centre external validation with patient-level data and realistic prevalence; (2) completion of the blinded expert rating of attribution maps and lesion-level annotations for all pathological classes; (3) training strategies that proactively remove artefact shortcuts, such as applying random Cutout or explicitly masking the ScopeGuide inset during training pipelines; (4) evaluation of edge-optimized and quantized models on target hardware; and (5) prior-shift recalibration for deployment at local prevalence.
Acknowledgements
The authors would like to express their gratitude to the creators and maintainers of the Kvasir dataset for providing a high-quality, publicly available benchmark that has facilitated significant advancements in gastrointestinal disease detection research. We also extend our appreciation to colleagues and collaborators whose constructive feedback and insights supported the development of this work.
During the revision, the authors used Claude (Anthropic) to help draft revised text, the response to reviewers, and analysis code. The authors reviewed, verified and edited all AI-assisted content, ran all experiments, and take full responsibility for the manuscript.
Data Availability
The dataset employed in this study, Kvasir, is openly accessible to the research community. The release used here contains 4,000 annotated endoscopic images across eight clinically relevant classes and can be freely obtained through its official publication [17] and the hosting platform: https://datasets.simula.no/kvasir/; the copy analysed in this study was obtained from https://www.kaggle.com/datasets/meetnagadia/kvasir-dataset. Kvasir-SEG and GastroVision are publicly available from their authors [19, 48]. The analysis notebook, fixed data split, cross-validation fold assignments and result tables are available from the corresponding author on request.
Ethical Statement
All images used in this study were anonymized before release in compliance with data privacy and ethical guidelines. Since the Kvasir dataset is publicly available and fully de-identified, no additional institutional ethical approval was required. This research was conducted in accordance with established standards for ethical medical imaging research and data protection.
Conflict of Interest
The authors declare no conflicts of interest regarding the publication of this study.
Funding
This work did not receive any external funding. The study was conducted using institutional resources and the computational facilities available to the authors.
Patient Consent Statement
Patient consent was not required because the study used a publicly available, de-identified dataset containing anonymized endoscopic images.
Permission to Reproduce Material from Other Sources
Not applicable. No figures, tables, images, or other copyrighted materials from external sources were reproduced in this manuscript.
Clinical Trial Registration
Not applicable. This study does not involve a clinical trial.
References
[1] Alwafi H, Alsharif A. Trends in hospital admissions and prescribing due to diseases of the digestive system in England and Wales between 1999 and 2019: An ecological study. Medicine. 2024 Apr 12;103(15):e37673. doi:10.1097/MD.0000000000037673
[2] Jardim SR, de Souza LMP, de Souza HSP. The Rise of Gastrointestinal Cancers as a Global Phenomenon: Unhealthy Behavior or Progress? Int J Environ Res Public Health. 2023 Feb 18;20(4):3640. doi:10.3390/ijerph20043640
[3] Singh A. Global burden of five major types of gastrointestinal cancer. Gastroenterology Review. 2024;19(3):236–54. doi:10.5114/pg.2024.141834
[4] Borgli H, Thambawita V, Smedsrud PH, Hicks S, Jha D, Eskeland SL, et al. HyperKvasir, a comprehensive multi-class image and video dataset for gastrointestinal endoscopy. Sci Data. 2020 Aug 28;7(1):283. doi:10.1038/s41597-020-00622-y
[5] Haile MB, Salau AO, Enyew B, Belay AJ. Detection and classification of gastrointestinal disease using convolutional neural network and SVM. Cogent Eng. 2022 Dec 31;9(1). doi:10.1080/23311916.2022.2084878
[6] Demirbaş AA, Üzen H, Firat H. Spatial-attention ConvMixer architecture for classification and detection of gastrointestinal diseases using the Kvasir dataset. Health Inf Sci Syst. 2024 Apr 28;12(1):32. doi:10.1007/s13755-024-00290-x
[7] Asare A, Gookyi DAN, Boateng D, Wulnye FA. Deploying and Evaluating Multiple Deep Learning Models on Edge Devices for Diabetic Retinopathy Detection. 2025 Jun 14.
[8] Mienye ID, Swart TG, Obaido G, Jordan M, Ilono P. Deep Convolutional Neural Networks in Medical Image Analysis: A Review. Information. 2025 Mar 3;16(3):195. doi:10.3390/info16030195
[9] Mall PK, Singh PK, Srivastav S, Narayan V, Paprzycki M, Jaworska T, et al. A comprehensive review of deep neural networks for medical image processing: Recent developments and future opportunities. Healthcare Analytics. 2023 Dec;4:100216. doi:10.1016/j.health.2023.100216
[10] Wu H, Zhao Z, Wang Z. META-Unet: Multi-Scale Efficient Transformer Attention Unet for Fast and High-Accuracy Polyp Segmentation. IEEE Transactions on Automation Science and Engineering. 2024 Jul;21(3):4117–28. doi:10.1109/TASE.2023.3292373
[11] Cuevas-Rodriguez EO, Galvan-Tejada CE, Maeda-Gutiérrez V, Moreno-Chávez G, Galván-Tejada JI, Gamboa-Rosales H, et al. Comparative study of convolutional neural network architectures for gastrointestinal lesions classification. PeerJ. 2023 Mar 16;11:e14806. doi:10.7717/peerj.14806
[12] Bbouzidi S, Hcini G, Jdey I, Drira F. Convolutional Neural Networks and Vision Transformers for Fashion MNIST Classification: A Literature Review. 2024 Jun 5.
[13] Yuan F, Zhang Z, Fang Z. An effective CNN and Transformer complementary network for medical image segmentation. Pattern Recognit. 2023 Apr;136:109228. doi:10.1016/j.patcog.2022.109228
[14] Varam D, Khalil L, Shanableh T. On-Edge Deployment of Vision Transformers for Medical Diagnostics Using the Kvasir-Capsule Dataset. Applied Sciences. 2024 Sep 10;14(18):8115. doi:10.3390/app14188115
[15] Palanisamy B, Hassija V, Chatterjee A, Mandal A, Chakraborty D, Pandey A, et al. Transformers for Vision: A Survey on Innovative Methods for Computer Vision. IEEE Access. 2025;13:95496–523. doi:10.1109/ACCESS.2025.3571735
[16] Takahashi S, Sakaguchi Y, Kouno N, Takasawa K, Ishizu K, Akagi Y, et al. Comparison of Vision Transformers and Convolutional Neural Networks in Medical Image Analysis: A Systematic Review. J Med Syst. 2024 Sep 12;48(1):84. doi:10.1007/s10916-024-02105-8
[17] Pogorelov K, Randel KR, Griwodz C, Eskeland SL, de Lange T, Johansen D, et al. KVASIR. In: Proceedings of the 8th ACM on Multimedia Systems Conference. New York, NY, USA: ACM; 2017. p. 164–9. doi:10.1145/3083187.3083212
[18] Asare A, Senkyire IB, Freeman E, Sagoe M, Hilary S, Aluze-Ele A, et al. PerceptronCARE: A Deep Learning-Based Intelligent Teleophthalmology Application for Diabetic Retinopathy Diagnosis. Accra; 2025 Sep. doi:10.48550/arXiv.2509.18160
[19] Jha D, Smedsrud PH, Riegler MA, Halvorsen P, de Lange T, Johansen D, et al. Kvasir-SEG: A Segmented Polyp Dataset. In. 2020. p. 451–62. doi:10.1007/978-3-030-37734-2_37
[20] Jha D, Ali S, Emanuelsen K, Hicks SA, Thambawita V, Garcia-Ceja E, et al. Kvasir-Instrument: Diagnostic and Therapeutic Tool Segmentation Dataset in Gastrointestinal Endoscopy. In. 2021. p. 218–29. doi:10.1007/978-3-030-67835-7_19
[21] Varalaxmi G, Baddam SR, Yalamarthi ES, Swaraja K, Madhavi KR, Sujatha Cn. Diagnosis of Gastrointestinal Diseases Using Modern CNN Techniques. In: 2023 IEEE 8th International Conference for Convergence in Technology (I2CT). IEEE; 2023. p. 1–6. doi:10.1109/I2CT57861.2023.10126259
[22] Hannan A, Ondus NA, Faraz M, Hassan Naqvi SZ. Gastrointestinal Disease Diagnosis through Deep Features Extracted from Endoscopic Imaging. In: 2024 19th International Conference on Emerging Technologies (ICET). IEEE; 2024. p. 1–6. doi:10.1109/ICET63392.2024.10935018
[23] Mary XA, Raj APW, Evangeline CS, Neebha TM, Kumaravelu VB, Manimegalai P. Multi-Class Classification of Gastrointestinal Diseases using Deep Learning Techniques. Open Biomed Eng J. 2023 Feb 15;17(1). doi:10.2174/18741207-v17-e230215-2022-HT27-3589-11
[24] Siddiqui S, Khan JA, Algamdi S. Deep ensemble learning for gastrointestinal diagnosis using endoscopic image classification. PeerJ Comput Sci. 2025 Apr 22;11:e2809. doi:10.7717/peerj-cs.2809
[25] Lafraxo S, El Ansari M. GastroNet: Abnormalities Recognition in Gastrointestinal Tract through Endoscopic Imagery using Deep Learning Techniques. In: 2020 8th International Conference on Wireless Networks and Mobile Communications (WINCOM). IEEE; 2020. p. 1–5. doi:10.1109/WINCOM50532.2020.9272456
[26] Dosovitskiy A, Beyer L, Kolesnikov A, Weissenborn D, Zhai X, Unterthiner T, et al. An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale. 2021 Jun 3.
[27] Regmi S, Subedi A, Tomar NK, Bagci U, Jha D. Vision transformer for efficient chest x-ray and gastrointestinal image classification. In: Astley SM, Wismüller A, editors. Medical Imaging 2025: Computer-Aided Diagnosis. SPIE; 2025. p. 111. doi:10.1117/12.3045810
[28] Soares Lima DL, Pinto Pessoa AC, De Paiva AC, Trigueiros da Silva Cunha AM, Junior GB, De Almeida JDS. Classification of Video Capsule Endoscopy Images Using Visual Transformers. In: 2022 IEEE-EMBS International Conference on Biomedical and Health Informatics (BHI). IEEE; 2022. p. 1–4. doi:10.1109/BHI56158.2022.9926791
[29] Vu NT, Pham VT, Tran TT, Pham VT. PyBoFormer: Pyramid Selected Boundary Transformer for Polyp Segmentation. In: 2023 12th International Conference on Control, Automation and Information Sciences (ICCAIS). IEEE; 2023. p. 194–9. doi:10.1109/ICCAIS59597.2023.10382322
[30] Gautam S, Riegler MA, Halvorsen P. Kvasir-VQA-x1: A Multimodal Dataset for Medical Reasoning and Robust MedVQA in Gastrointestinal Endoscopy. 2025 Jun 11.
[31] Wang W, Yang X, Tang J. Vision Transformer With Hybrid Shifted Windows for Gastrointestinal Endoscopy Image Classification. IEEE Transactions on Circuits and Systems for Video Technology. 2023 Sep;33(9):4452–61. doi:10.1109/TCSVT.2023.3277462
[32] S. G, C. G, Vinod V. Hierarchical vision transformer model for polyp segmentation. In: 2023 International Conference on Advances in Intelligent Computing and Applications (AICAPS). IEEE; 2023. p. 1–5. doi:10.1109/AICAPS57044.2023.10074447
[33] Asare A, Adjei Broni A, Asare Dickson AK, Sagoe M, Cudjoe JM. Performance of ResNet-18 and InceptionResNetV2 in Automated Detection of Diabetic Retinopathy. Medicine Advances. 2025 Sep 15;3(3):231–41. doi:10.1002/med4.70023
[34] Asare A, Asare JW, Ujakpa MM, Kyei EA, Mutasa LS, Freeman E, et al. Enhanced Ensemble Model-Based Approach from Deep Learning for MonkeyPox Detection Using Medical Images. In. 2026. p. 166–89. doi:10.1007/978-3-032-13056-3_14
[35] Asare JW, Asare A, Ujakpa MM, Kyei EA, Mutasa LS, Brown-Acquaye WL, et al. A Hybrid Three-Layer Convolutional Neural Network Architecture for Detecting Anemia Using Clinical Images. In. 2026. p. 144–56. doi:10.1007/978-3-032-13056-3_12
[36] He K, Zhang X, Ren S, Sun J. Deep Residual Learning for Image Recognition. In: 2016 IEEE Conference on Computer Vision and Pattern Recognition (CVPR). IEEE; 2016. p. 770–8. doi:10.1109/CVPR.2016.90
[37] Shafiq M, Gu Z. Deep Residual Learning for Image Recognition: A Survey. Applied Sciences. 2022 Sep 7;12(18):8972. doi:10.3390/app12188972
[38] Wang YK, Karmakar R, Mukundan A, Men TC, Tsao YM, Lu SC, et al. Computer-aided endoscopic diagnostic system modified with hyperspectral imaging for the classification of esophageal neoplasms. Front Oncol. 2024;14:1423405. doi:10.3389/fonc.2024.1423405
[39] Huang CW, Su CC, Chou CK, Mukundan A, Karmakar R, Chen TH, et al. Software-Based Transformation of White Light Endoscopy Images to Hyperspectral Images for Improved Gastrointestinal Disease Detection. Diagnostics. 2025;15(13):1664. doi:10.3390/diagnostics15131664
[40] Chou CK, Lee KH, Karmakar R, Mukundan A, Chen TH, Kumar A, et al. Integrating AI with Advanced Hyperspectral Imaging for Enhanced Classification of Selected Gastrointestinal Diseases. Bioengineering. 2025;12(8):852. doi:10.3390/bioengineering12080852
[41] Müller R, Kornblith S, Hinton GE. When Does Label Smoothing Help? In: Advances in Neural Information Processing Systems 32 (NeurIPS); 2019.
[42] Mehta S, Rastegari M. MobileViT: Light-weight, General-purpose, and Mobile-friendly Vision Transformer. In: International Conference on Learning Representations (ICLR); 2022.
[43] Guo C, Pleiss G, Sun Y, Weinberger KQ. On Calibration of Modern Neural Networks. In: Proceedings of the 34th International Conference on Machine Learning (ICML). PMLR; 2017. p. 1321–30.
[44] Nixon J, Dusenberry MW, Zhang L, Jerfel G, Tran D. Measuring Calibration in Deep Learning. In: IEEE/CVF Conference on Computer Vision and Pattern Recognition Workshops (CVPRW); 2019. p. 38–41.
[45] Brier GW. Verification of forecasts expressed in terms of probability. Mon Weather Rev. 1950;78(1):1–3.
[46] Schuirmann DJ. A comparison of the two one-sided tests procedure and the power approach for assessing the equivalence of average bioavailability. J Pharmacokinet Biopharm. 1987;15(6):657–80. doi:10.1007/BF01068419
[47] Zhang J, Bargal SA, Lin Z, Brandt J, Shen X, Sclaroff S. Top-down neural attention by excitation backprop. Int J Comput Vis. 2018;126(10):1084–102. doi:10.1007/s11263-017-1059-x
[48] Jha D, et al. GastroVision: A Multi-class Endoscopy Image Dataset for Computer Aided Gastrointestinal Disease Detection. In: Machine Learning for Multimodal Healthcare Data (ML4MHD 2023). Lecture Notes in Computer Science, vol. 14315. Cham: Springer; 2024. doi:10.1007/978-3-031-47679-2_10
[49] Miwa H, Yokoyama T, Hori K, Sakagami T, Oshima T, Tomita T, et al. Interobserver agreement in endoscopic evaluation of reflux esophagitis using a modified Los Angeles classification incorporating grades N and M: a validation study in a cohort of Japanese endoscopists. Dis Esophagus. 2008;21(4):355–63. doi:10.1111/j.1442-2050.2007.00788.x
[50] Asare A, Nguyen TH, Bagci U. Improved Segmentation of Polyps and Visual Explainability Analysis. In: 2026 International Conference on Artificial Intelligence, Computer, Data Sciences and Applications (ACDSA). IEEE; 2026. p. 1–8. doi:10.1109/ACDSA67686.2026.11467629
[51] Asare A, Sagoe M, Asare JW, et al. TransUNet-GradCAM: a hybrid transformer-U-Net with self-attention and explainable visualizations for foot ulcer segmentation. BMC Med Imaging. 2026;26:474. doi:10.1186/s12880-026-02793-3