Views
No views yet
1import torch
2from transformers import AutoModelForImageClassification, AutoImageProcessor
3from PIL import Image
4import requests
5
6# Load image
7url = "http://images.cocodataset.org/val2017/000000039769.jpg"
8image = Image.open(requests.get(url, stream=True).raw)
9
10# Load processor and model
11processor = AutoImageProcessor.from_pretrained(
12 "XAFT/SM-Selective-ViT-Tiny-224",
13 trust_remote_code=True,
14)
15
16model = AutoModelForImageClassification.from_pretrained(
17 "XAFT/SM-Selective-ViT-Tiny-224",
18 trust_remote_code=True,
19)
20model = model.half() # Cast to FP16 to enable FlashAttention
21
22# Preprocess
23inputs = processor(
24 images=image,
25 return_tensors="pt",
26)
27inputs = inputs.to(torch.half) # Cast to FP16
28
29# Forward pass
30outputs = model(**inputs)
31logits = outputs.logits
32predicted_class = logits.argmax(-1).item()
33
34print("Predicted class index:", predicted_class)| Model | Top-1 Acc. | Top-5 Acc. | # Params | Avg. GFLOPs |
|---|---|---|---|---|
| Base | 80.350% | 94.980% | 86.60M | 9.61 |
| Base (distilled) | 80.990% | 95.386% | 87.37M | 9.21 |
| Small | 78.662% | 94.454% | 22.06M | 3.12 |
| Small (distilled) | 79.000% | 94.494% | 22.45M | 3.05 |
| Tiny tall | 74.802% | 92.794% | 11.07M | 1.64 |
| Tiny tall (distilled) | 75.676% | 92.988% | 11.26M | 1.64 |
| Tiny | 71.056% | 90.192% | 5.72M | 0.95 |
| Tiny (distilled) | 72.618% | 91.338% | 5.92M | 0.93 |
1@article{TOULAOUI2026115151,
2 title = {Efficient vision transformers via patch selective soft-masked attention and knowledge distillation},
3 journal = {Applied Soft Computing},
4 pages = {115151},
5 year = {2026},
6 issn = {1568-4946},
7 doi = {https://doi.org/10.1016/j.asoc.2026.115151},
8 url = {https://www.sciencedirect.com/science/article/pii/S1568494626005995},
9 author = {Abdelfattah Toulaoui and Hamza Khalfi and Imad Hafidi},
10 keywords = {Vision transformer, Patch selection, Soft masking, Efficient inference}
11}