Dynamic self-ensemble on multi-exit residual vision transformer for small-data image classification
Organizations: aDepartment of Electrical Engineering and Computer Science, National Yang Ming Chiao Tung University, Hsinchu, 30010, Taiwan · bDepartment of Computer Science, National Yang Ming Chiao Tung University, Hsinchu, 30010, Taiwan · cDepartment of Computer Science and Information Engineering, National Taiwan University, Taipei, 10617, Taiwan · dCollege of Engineering and Computer Science, VinUniversity, Hanoi, Vietnam ·
Abstract
Vision Transformer (ViT) has garnered increased attention for image classification in recent years. However, ViT is notorious for its data-hungry problem as it achieves high-performance results when only trained on large-size datasets. In this paper, we study how ViT specifically works on small-scale datasets with limited data where the availability of image data is often constrained in practice, especially in fields such as medical imaging. To mitigate the issue, we designed a multi-stage residual ViT, dubbed ReSEViT, with the self-ensemble method to utilize multi-level information from intermediate features. Due to the complex decision boundaries for classifications, relying on a single classifier can lead to prediction errors. Hence, we propose a new learning method for ViT, named self-ensemble learning, which ensembles multi-stage classifiers in a single model. Our self-ensemble comprises a novel approach, Dynamic Learner Selection (DLS), to adaptively select the importance of different stages. ReSEViT incorporates residual token embeddings which is a ResNet-like block to model effective local structures alongside with transformer blocks in each stage. The integration of residual tokens and self-ensemble learning into a multi-stage ViT highlights the reduction in redundancy, prediction error and variance while maintaining an efficient model size for small-scale image datasets.
Figures & tables
| Method | Pos. Emb. | Token Emb. | Projections | Multi-Stage | Small-Scale | Efficient Training |
| ViT [ vit ] | yes | standard | linear | no | no | no |
| DeiT [ deit ] | yes | standard | linear | no | no | distillation |
| CvT [ cvt ] | no | convolution | convolution | yes | no | no |
| CCT [ cct ] | optional | convolution | linear | no | yes | no |
| NesT [ nest ] | yes | convolution | linear | yes | yes | no |
| TransXNet [ transxnet ] | yes | convolution | linear | yes | no | no |
| Method | Training Losses | Inference Phase | Stage Classifier Design | Purpose |
| BranchyNet [ branchynet ] | (w/ fixed weight) | Extra convolution layers | faster inference | |
| Self-distill [ selfdistillation ] | Extra attention module & layers | knowledge distillation | ||
| Self-ensemble (Ours) | (w/ dynamic weight) | No extra layer | ensemble |
| Small Resolution (32 32) | Large Resolution (224 224) | ||||
| Output | Layer Name | ReSEViT-T | ReSEViT-S | Output | ReSEViT-L |
| 32×32 | Conv. Stem | 3×3, 64, =1 | 3×3, 64, =1 | 56×56 | 7×7, 64, =4 |
| 32×32 | Res. Token 1 | 3×3, 64, =1 3×3, 64, =1 | 3×3, 64, =1 3×3, 64, =1 | 56×56 | 3×3, 64, =1 3×3, 64, =1 |
| 32×32 | Transformer Block 1 | 3×3, 64, =2 =32, =4 | 3×3, 64, =1 =32, =8 | 56×56 | 3×3, 64, =2 =56, =1 |
| 16×16 | Res. Token 2 | 3×3, 128, =2 3×3, 128, =1 | 3×3, 128, =2 3×3, 128, =1 | 28×28 | 3×3, 192, =2 3×3, 192, =1 |
| 16×16 | Transformer Block 2 | 3×3, 128, =2 =16, =4 | 3×3, 128, =1 =16, =8 | 28×28 | 3×3, 192, =2 =28, =3 |
| Dataset | Train | Test | Dimension | # Classes |
| General Datasets | ||||
| CIFAR10 [ cifar ] | 50,000 | 10,000 | 32 32 | 10 |
| CIFAR100 [ cifar ] | 50,000 | 10,000 | 32 32 | 100 |
| Tiny-ImageNet [ tinyimagenet ] | 100,000 | 10,000 | 64 64 | 200 |
| ImageNet100 [ cmc ] | 130,000 | 5,000 | 224 224 | 100 |
| Medical Datasets | ||||
| Method | CIFAR10 | CIFAR100 | Tiny-ImageNet | Avg. Acc | Params. | FLOPs | GPU | Throughput |
| Convolution Networks | ||||||||
| ResNet18 † [ resnet ] | 94.37% | 75.41% | 52.47% | 74.08% | 11.22M | 0.56G | 2045M | 10351 |
| ResNet34 † [ resnet ] | 95.26% | 77.08% | 54.87% | 75.74% | 21.33M | 1.16G | 2081M | 7360 |
| DenseNet 100-12 [ densenet ] | 95.90% | 79.80% | 54.81% | 76.84% | 7.00M | 1.85G | 5347M | 1251 |
| WRN-40-4 [ wideresnet ] | 95.47% | 78.90% | 56.86% | 77.08% | 8.98M | 1.42G | 2035M | 5812 |
| ConvNeXt-T † [ convnext ] | 94.55% | 74.02% | 51.15% | 73.24% | 27.94M | 1.45G | 4446M | 3455 |
| Method | Top-1 | Params. | FLOPs | Throughput |
| ViT-B (ICLR’21) [ vit ] | 71.38% | 85.85M | 16.85G | 605 |
| T2T-ViT-14 (ICCV’21) [ t2t ] | 78.48% | 21.12M | 4.33G | 1170 |
| Swin-T (ICCV’21) [ swin ] | 80.66% | 27.60M | 4.35G | 930 |
| CvT-13 (ICCV’21) [ cvt ] | 81.57% | 19.69M | 4.05G | 1034 |
| EfficientFormer-L3 (NeurIPS’22) [ efficientformer ] | 79.21% | 30.48M | 3.95G | 916 |
| PoolFormer-S36 (CVPR’22) [ poolformer ] | 81.25% | 30.40M | 4.99G | 680 |
| Datasets | Metrics | CvT-13 † | CCT-7/3 1 | NesT-T | ReSEViT-T |
| PathMNIST | AUC | 0.9951 | 0.9953 | 0.9956 | 0.9958 |
| Top-1 | 0.9560 | 0.9554 | 0.9620 | 0.9692 | |
| ChestMNIST | AUC | 0.5742 | 0.4764 | 0.5679 | 0.5849 |
| Top-1 | 0.9496 | 0.9493 | 0.9495 | 0.9496 | |
| DermaMNIST | AUC | 0.7356 | 0.7619 | 0.6591 | 0.7645 |
| Top-1 | 0.7292 | 0.7360 | 0.6686 | 0.7399 |
| Metrics | ViT-B | CvT-13 | CCT-14/7 2 | NesT-T | ReSEViT-L | ||
| SL | ML | ML+DLS | |||||
| AUC | 0.8410 | 0.8766 | 0.7728 | 0.8798 | 0.8972 | 0.9113 | 0.9176 |
| Top-1 | 0.5837 | 0.6407 | 0.6733 | 0.6483 | 0.6707 | 0.6895 | 0.7066 |
| Ensemble Method | Acc | Params. | Train | Test | |
| Baseline | 1 | 78.65% | 4.11M | 1.00 | 1.00 |
| Model Avg. | 2 | 79.89% | 13.74M ⧫ | 1.05 | 1.02 |
| Bagging [ bagging ] | 2 | 78.76% | 8.22M ⧫ | 2.41 | 1.05 |
| SSE [ snapshot ] | 4 | 79.41% | 4.11M | 1.00 | 1.17 |
| FGE [ fastgeometric ] | 12 | 79.51% | 4.11M | 1.00 | 2.86 |
| FiLM [ filmensemble ] | 2 | 80.07% | 4.12M | 2.18 | 1.6 |
| Method | CIFAR100 | ImageNet100 | |
| Conv. Token (Baseline) | ✗ | 77.28% | 82.60% |
| ✓ | 78.62% (+1.34) | 83.23% (+0.63) | |
| Residual Token | ✗ | 78.65% | 83.31% |
| ✓ | 81.05% (+2.40) | 85.23% (+1.92) |
| Method | Stage 1 | Stage 2 | Stage 3 | Ensemble |
| CIFAR100 | ||||
| SL | 12.22% | 34.17% | 78.65% | 76.62% |
| ML | 65.96% | 76.38% | 78.22% | 80.33% |
| ML+DLS | 65.01% | 76.70% | 78.59% | 81.05% |
| ImageNet100 | ||||
| SL | 4.31% | 13.39% | 83.31% | 82.52% |
| Method | Training | Inference | CIFAR100 | ImageNet100 |
| ML | ✗ | ✗ | 80.33% | 84.12% |
| ML+BT | ✓ | ✗ | 80.75% | 84.85% |
| ML+BI | ✗ | ✓ | 80.71% | 84.44% |
| ML+DLS | ✓ | ✓ | 81.05% | 85.23% |
| Num. of cls. | Stage 1 | Stage 2 | Stage 3 | CIFAR100 | ImageNet100 |
| ✓ | ✗ | ✗ | 68.49% | 65.70% | |
| 1 | ✗ | ✓ | ✗ | 76.41% | 82.67% |
| ✗ | ✗ | ✓ | 78.65% | 83.31% | |
| ✓ | ✓ | ✗ | 77.60% | 82.63% | |
| 2 | ✓ | ✗ | ✓ | 79.66% | 83.82% |
| ✗ | ✓ | ✓ | 80.80% | 84.81% |
Appendix figures & tables12 assets
Supplementary material from the paper’s appendix.
Appendix
| Output | Layer Name | ReSEViT-L | Layer Name | CvT-13 |
| 56×56 | Conv. Stem | 7×7, 64, =4 | Conv. Token 1 | 7×7, 64, =4 |
| 56×56 | Res. Token 1 | 3×3, 64, =1 3×3, 64, =1 | ||
| 56×56 | Transformer 1 | 3×3, 64, =2 =56, =1 | Transformer 1 | 3×3, 64, =2 =56, =1 |
| 28×28 | Res. Token 2 | 3×3, 192, =2 3×3, 192, =1 | Conv. Token 2 | 3×3, 192, =2 |
| 28×28 | Transformer 2 | 3×3, 192, =2 =28, =3 | Transformer 2 | 3×3, 192, =2 =28, =3 |
| 14×14 | Res. Token 3 | 3×3, 384, =2 3×3, 384, =1 | Conv. Token 3 | 3×3, 384, =2 |
| ReSEViT-S | [CLS] | GAP | SeqPool |
| CIFAR100 Top-1 | 78.65 / 81.05% | 77.99 / 80.47 | 78.83% / 80.63 |
| Method | CIFAR-100 | |||||
| ( 0.01) | ( 0.1) | ( 1.0) | ||||
| Top-1 | ECE | Top-1 | ECE | Top-1 | ECE | |
| ResNet18 † [ resnet ] | 36.82 | 0.145 | 56.71 | 0.144 | 75.41 | 0.158 |
| ResNet34 † [ resnet ] | 38.67 | 0.168 | 58.36 | 0.141 | 77.08 | 0.126 |
| ConvNeXt-T † [ convnext ] | 34.45 | 0.221 | 54.96 | 0.199 | 74.02 | 0.113 |
| CvT-13 † [ cvt ] | 38.45 | 0.221 | 56.77 | 0.151 | 73.56 | 0.115 |
| Roadmap | CvT-13 | patchify ”stem” | stage ratio | res. token (ResNet) | ReSEViT-T | ||||
| Note | (large resolution setting) | (small resolution setting) | (base form) | (wide conv. ⋆ / residual block) | (final form) | ||||
| Accuracy ( ) | 58.48% | 73.56% | 67.69% | 75.86% ⋆ / 77.65% | 79.49% | ||||
| Throughput ( ) | 2781 | 2560 | 7130 | 4254 ⋆ / 4841 | 4832 | ||||
| Params. ( ) | 19.66M | 19.65M | 1.57M | 5.85M ⋆ / 3.86M | 3.88M | ||||
| FLOPs ( ) | 0.10G | 1.32G | 0.22G | 0.84G ⋆ / 0.56G | 0.56G | ||||
| Roadmap | ResNet18 | patchify ”stem” | w/o 4 th stage | transformer | ReSEViT-T |
| Model | Top-1 (%) | Params. (M) | FLOPs. (G) | |
| SqueezeNet [ squeezenet ] | 4 | 58.08 | 0.78 | 0.05 |
| SE-SqueezeNet | 66.48 (+8.40) | 0.90 (+0.12) | 0.07 (+0.02) | |
| ResNet18 † [ resnet ] | 4 | 75.41 | 11.22 | 0.56 |
| SE-ResNet18 † | 77.05 (+1.64) | 11.27 (+0.05) | 0.56 | |
| ResNet34 † [ resnet ] | 4 | 77.08 | 21.33 | 1.16 |
| SE-ResNet34 † | 78.43 (+1.35) | 21.37 (+0.04) | 1.16 |
| Method | Training set | |||
| 10 | 100 | |||
| Top-1 | Top-5 | Top-1 | Top-5 | |
| ViT-B | 33.68 | 61.04 | 83.74 | 95.42 |
| CvT-13 | 56.66 | 81.28 | 89.70 | 97.72 |
| ReSEViT-L | 64.20 | 86.46 | 90.02 | 98.18 |
| Method | 56 56 | 112 112 | 224 224 | ||||||
| Param. | FLOPs | FPS | Param. | FLOPs | FPS | Param. | FLOPs | FPS | |
| ViT-B [ vit ] | 85.29M | 16.74G | 595 | 85.41M | 16.76G | 592 | 85.85M | 16.85G | 605 |
| CvT-13 [ cvt ] | 19.65M | 4.02G | 990 | 19.65M | 4.02G | 988 | 19.69M | 4.05G | 1034 |
| ReSeViT-L | 12.42M | 4.06G | 866 | 12.42M | 4.06G | 870 | 12.43M | 4.08G | 890 |
| Dataset | CIFAR (32 32), Tiny-ImageNet (64 64), | ImageNet100 | ISIC 2018 |
| MedMNIST (28 28) | |||
| optimizer | AdamW | AdamW | AdamW |
| init lr | 5e-4 | 5e-4 | 5e-4 |
| batch size | 64 | 64 | 64 |
| weight decay | 3e-2 | 3e-2 | 3e-2 |
| momentum | (0.9, 0.999) | (0.9, 0.999) | (0.9, 0.999) |
Vision Transformer
Vision Transformers (ViTs) use self-attention over image patches to learn visual representations for recognition, segmentation, and other tasks.
See all 370 papers