Image Classification
timm
PyTorch
rdnet
DongHyunKim commited on
Commit
854f200
1 Parent(s): 38447c7

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +127 -0
README.md ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ datasets:
3
+ - imagenet-1k
4
+ library_name: timm
5
+ tags:
6
+ - image-classification
7
+ - timm
8
+ - rdnet
9
+ ---
10
+ # Model card for rdnet_tiny.nv_in1k
11
+
12
+ A RDNet image classification model. Trained on ImageNet-1k, original torchvision weights.
13
+
14
+ ## Model Details
15
+ - **Model Type:** Image classification / feature backbone
16
+ - **Model Stats:**
17
+ - Imagenet-1k validation top-1 accuracy: 82.8%
18
+ - Params (M): 24
19
+ - GMACs: 5.0
20
+ - Image size: 224 x 224
21
+ - **Papers:**
22
+ - DenseNets Reloaded: Paradigm Shift Beyond ResNets and ViTs: https://arxiv.org/abs/2403.19588
23
+ - **Dataset:** ImageNet-1k
24
+
25
+ ## Model Usage
26
+ ### Image Classification
27
+ ```python
28
+ from urllib.request import urlopen
29
+ from PIL import Image
30
+ import timm
31
+ import torch
32
+ import rdnet # register rdnet models to timm
33
+
34
+ img = Image.open(urlopen(
35
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
36
+ ))
37
+
38
+ model = timm.create_model('rdnet_tiny.nv_in1k', pretrained=True)
39
+ model = model.eval()
40
+
41
+ # get model specific transforms (normalization, resize)
42
+ data_config = timm.data.resolve_model_data_config(model)
43
+ transforms = timm.data.create_transform(**data_config, is_training=False)
44
+
45
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
46
+
47
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
48
+ ```
49
+
50
+ ### Feature Map Extraction
51
+ ```python
52
+ from urllib.request import urlopen
53
+ from PIL import Image
54
+ import timm
55
+ import rdnet # register rdnet models to timm
56
+
57
+ img = Image.open(urlopen(
58
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
59
+ ))
60
+
61
+ model = timm.create_model(
62
+ 'rdnet_tiny.nv_in1k',
63
+ pretrained=True,
64
+ features_only=True,
65
+ )
66
+ model = model.eval()
67
+
68
+ # get model specific transforms (normalization, resize)
69
+ data_config = timm.data.resolve_model_data_config(model)
70
+ transforms = timm.data.create_transform(**data_config, is_training=False)
71
+
72
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
73
+
74
+ for o in output:
75
+ # print shape of each feature map in output
76
+ # e.g.:
77
+ # torch.Size([1, 256, 56, 56])
78
+ # torch.Size([1, 440, 28, 28])
79
+ # torch.Size([1, 744, 14, 14])
80
+ # torch.Size([1, 1040, 7, 7])
81
+
82
+ print(o.shape)
83
+ ```
84
+
85
+ ### Image Embeddings
86
+ ```python
87
+ from urllib.request import urlopen
88
+ from PIL import Image
89
+ import timm
90
+ import rdnet # register rdnet models to timm
91
+
92
+ img = Image.open(urlopen(
93
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
94
+ ))
95
+
96
+ model = timm.create_model(
97
+ 'rdnet_tiny.nv_in1k',
98
+ pretrained=True,
99
+ num_classes=0, # remove classifier nn.Linear
100
+ )
101
+ model = model.eval()
102
+
103
+ # get model specific transforms (normalization, resize)
104
+ data_config = timm.data.resolve_model_data_config(model)
105
+ transforms = timm.data.create_transform(**data_config, is_training=False)
106
+
107
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
108
+
109
+ # or equivalently (without needing to set num_classes=0)
110
+
111
+ output = model.forward_features(transforms(img).unsqueeze(0))
112
+ # output is unpooled, a (1, 1040, 7, 7) shaped tensor
113
+
114
+ output = model.forward_head(output, pre_logits=True)
115
+ # output is a (1, num_features) shaped tensor
116
+ ```
117
+
118
+ ### Citation
119
+ ```
120
+ @misc{kim2024densenets,
121
+ title={DenseNets Reloaded: Paradigm Shift Beyond ResNets and ViTs},
122
+ author={Donghyun Kim and Byeongho Heo and Dongyoon Han},
123
+ year={2024},
124
+ eprint={2403.19588},
125
+ archivePrefix={arXiv},
126
+ }
127
+ ```