Views
No views yet
| Steps | Connection | Top-1 Accuracy (%) | Top-5 Accuracy (%) | Link |
|---|---|---|---|---|
| 90k | Orthogonal | 74.62 | 92.26 | link |
| 90k | Linear | 71.23 | 90.29 | here |


1import torch
2import torchvision.transforms as transforms
3from datasets import load_dataset
4from torch.utils.data import DataLoader
5from transformers import AutoModelForImageClassification
6from tqdm import tqdm
7import argparse
8from typing import Tuple, List
9
10def accuracy_counts(
11 logits: torch.Tensor,
12 target: torch.Tensor,
13 topk: Tuple[int, ...] = (1, 5),
14) -> List[int]:
15 """
16 Given model outputs and targets, return a list of correct-counts
17 for each k in topk.
18 """
19 maxk = max(topk)
20 _, pred = logits.topk(maxk, dim=1, largest=True, sorted=True)
21 pred = pred.t()
22 correct = pred.eq(target.view(1, -1).expand_as(pred))
23
24 res = []
25 for k in topk:
26 correct_k = correct[:k].reshape(-1).float().sum(0, keepdim=True)
27 res.append(correct_k.item())
28 return res
29
30def evaluate_model():
31 device = torch.device("cuda" if torch.cuda.is_available() and not args.cpu else "cpu")
32 print(f"Using device: {device}")
33
34 model = AutoModelForImageClassification.from_pretrained(
35 "BootsofLagrangian/ortho-vit-b-imagenet1k-hf",
36 trust_remote_code=True
37 )
38 model.to(device)
39 model.eval()
40
41 img_size = 224
42 mean = [0.485, 0.456, 0.406]
43 std = [0.229, 0.224, 0.225]
44
45 transform_eval = transforms.Compose([
46 transforms.Lambda(lambda img: img.convert("RGB")),
47 transforms.Resize(img_size, interpolation=transforms.InterpolationMode.BICUBIC),
48 transforms.CenterCrop(img_size),
49 transforms.ToTensor(),
50 transforms.Normalize(mean, std),
51 ])
52 val_dataset = load_dataset("timm/imagenet-1k-wds", split="validation")
53
54 def collate_fn(batch):
55 images = torch.stack([transform_eval(item['jpg']) for item in batch])
56 labels = torch.tensor([item['cls'] for item in batch])
57 return images, labels
58
59 val_loader = DataLoader(
60 val_dataset,
61 batch_size=32,
62 shuffle=False,
63 num_workers=4,
64 collate_fn=collate_fn,
65 pin_memory=True
66 )
67 total_samples, correct_top1, correct_top5 = 0, 0, 0
68
69 with torch.no_grad():
70 for images, labels in tqdm(val_loader, desc="Evaluating"):
71 images = images.to(device)
72 labels = labels.to(device)
73
74 outputs = model(pixel_values=images)
75 logits = outputs.logits
76
77 counts = accuracy_counts(logits, labels, topk=(1, 5))
78 correct_top1 += counts[0]
79 correct_top5 += counts[1]
80 total_samples += images.size(0)
81
82 top1_accuracy = (correct_top1 / total_samples) * 100
83 top5_accuracy = (correct_top5 / total_samples) * 100
84
85 print("\n--- Evaluation Results ---")
86 print(f"Total samples evaluated: {total_samples}")
87 print(f"Top-1 Accuracy: {top1_accuracy:.2f}%")
88 print(f"Top-5 Accuracy: {top5_accuracy:.2f}%")1@article{oh2025revisitingresidualconnectionsorthogonal,
2 title={Revisiting Residual Connections: Orthogonal Updates for Stable and Efficient Deep Networks},
3 author={Giyeong Oh and Woohyun Cho and Siyeol Kim and Suhwan Choi and Younjae Yu},
4 year={2025},
5 journal={arXiv preprint arXiv:2505.11881},
6 eprint={2505.11881},
7 archivePrefix={arXiv},
8 primaryClass={cs.CV},
9 url={https://arxiv.org/abs/2505.11881}
10}
11