rwightman HF staff commited on
Commit
85ecde7
1 Parent(s): 9ea7ed5
Files changed (4) hide show
  1. README.md +149 -0
  2. config.json +41 -0
  3. model.safetensors +3 -0
  4. pytorch_model.bin +3 -0
README.md ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - image-classification
4
+ - timm
5
+ library_tag: timm
6
+ license: apache-2.0
7
+ datasets:
8
+ - imagenet-1k
9
+ ---
10
+ # Model card for resnet61q.ra2_in1k
11
+
12
+ A ResNet image classification model. This model features a 4-layer (quad) stem without pooling and SiLU activations. Trained on ImageNet-1k by Ross Wightman in `timm`.
13
+
14
+ This model architecture is implemented using `timm`'s flexible [BYOBNet (Bring-Your-Own-Blocks Network)](https://github.com/huggingface/pytorch-image-models/blob/main/timm/models/byobnet.py).
15
+
16
+ BYOBNet allows configuration of:
17
+ * block / stage layout
18
+ * stem layout
19
+ * output stride (dilation)
20
+ * activation and norm layers
21
+ * channel and spatial / self-attention layers
22
+
23
+ ...and also includes `timm` features common to many other architectures, including:
24
+ * stochastic depth
25
+ * gradient checkpointing
26
+ * layer-wise LR decay
27
+ * per-stage feature extraction
28
+
29
+
30
+ ## Model Details
31
+ - **Model Type:** Image classification / feature backbone
32
+ - **Model Stats:**
33
+ - Params (M): 36.8
34
+ - GMACs: 7.8
35
+ - Activations (M): 17.0
36
+ - Image size: train = 256 x 256, test = 288 x 288
37
+ - **Papers:**
38
+ - @: a
39
+ - **Dataset:** ImageNet-1k
40
+ - **Original:** https://github.com/huggingface/pytorch-image-models
41
+
42
+ ## Model Usage
43
+ ### Image Classification
44
+ ```python
45
+ from urllib.request import urlopen
46
+ from PIL import Image
47
+ import timm
48
+
49
+ img = Image.open(urlopen(
50
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
51
+ ))
52
+
53
+ model = timm.create_model('resnet61q.ra2_in1k', pretrained=True)
54
+ model = model.eval()
55
+
56
+ # get model specific transforms (normalization, resize)
57
+ data_config = timm.data.resolve_model_data_config(model)
58
+ transforms = timm.data.create_transform(**data_config, is_training=False)
59
+
60
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
61
+
62
+ top5_probabilities, top5_class_indices = torch.topk(output.softmax(dim=1) * 100, k=5)
63
+ ```
64
+
65
+ ### Feature Map Extraction
66
+ ```python
67
+ from urllib.request import urlopen
68
+ from PIL import Image
69
+ import timm
70
+
71
+ img = Image.open(urlopen(
72
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
73
+ ))
74
+
75
+ model = timm.create_model(
76
+ 'resnet61q.ra2_in1k',
77
+ pretrained=True,
78
+ features_only=True,
79
+ )
80
+ model = model.eval()
81
+
82
+ # get model specific transforms (normalization, resize)
83
+ data_config = timm.data.resolve_model_data_config(model)
84
+ transforms = timm.data.create_transform(**data_config, is_training=False)
85
+
86
+ output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 1
87
+
88
+ for o in output:
89
+ # print shape of each feature map in output
90
+ # e.g.:
91
+ # torch.Size([1, 64, 128, 128])
92
+ # torch.Size([1, 256, 64, 64])
93
+ # torch.Size([1, 512, 32, 32])
94
+ # torch.Size([1, 1536, 16, 16])
95
+ # torch.Size([1, 2048, 8, 8])
96
+
97
+ print(o.shape)
98
+ ```
99
+
100
+ ### Image Embeddings
101
+ ```python
102
+ from urllib.request import urlopen
103
+ from PIL import Image
104
+ import timm
105
+
106
+ img = Image.open(urlopen(
107
+ 'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png'
108
+ ))
109
+
110
+ model = timm.create_model(
111
+ 'resnet61q.ra2_in1k',
112
+ pretrained=True,
113
+ num_classes=0, # remove classifier nn.Linear
114
+ )
115
+ model = model.eval()
116
+
117
+ # get model specific transforms (normalization, resize)
118
+ data_config = timm.data.resolve_model_data_config(model)
119
+ transforms = timm.data.create_transform(**data_config, is_training=False)
120
+
121
+ output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor
122
+
123
+ # or equivalently (without needing to set num_classes=0)
124
+
125
+ output = model.forward_features(transforms(img).unsqueeze(0))
126
+ # output is unpooled, a (1, 2048, 8, 8) shaped tensor
127
+
128
+ output = model.forward_head(output, pre_logits=True)
129
+ # output is a (1, num_features) shaped tensor
130
+ ```
131
+
132
+ ## Model Comparison
133
+ Explore the dataset and runtime metrics of this model in timm [model results](https://github.com/huggingface/pytorch-image-models/tree/main/results).
134
+
135
+ ## Citation
136
+ ```bibtex
137
+ @misc{rw2019timm,
138
+ author = {Ross Wightman},
139
+ title = {PyTorch Image Models},
140
+ year = {2019},
141
+ publisher = {GitHub},
142
+ journal = {GitHub repository},
143
+ doi = {10.5281/zenodo.4414861},
144
+ howpublished = {\url{https://github.com/huggingface/pytorch-image-models}}
145
+ }
146
+ ```
147
+ ```bibtex
148
+ r
149
+ ```
config.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architecture": "resnet61q",
3
+ "num_classes": 1000,
4
+ "num_features": 2048,
5
+ "pretrained_cfg": {
6
+ "tag": "ra2_in1k",
7
+ "custom_load": false,
8
+ "input_size": [
9
+ 3,
10
+ 256,
11
+ 256
12
+ ],
13
+ "test_input_size": [
14
+ 3,
15
+ 288,
16
+ 288
17
+ ],
18
+ "fixed_input_size": false,
19
+ "interpolation": "bicubic",
20
+ "crop_pct": 0.9,
21
+ "test_crop_pct": 1.0,
22
+ "crop_mode": "center",
23
+ "mean": [
24
+ 0.485,
25
+ 0.456,
26
+ 0.406
27
+ ],
28
+ "std": [
29
+ 0.229,
30
+ 0.224,
31
+ 0.225
32
+ ],
33
+ "num_classes": 1000,
34
+ "pool_size": [
35
+ 8,
36
+ 8
37
+ ],
38
+ "first_conv": "stem.conv1.conv",
39
+ "classifier": "head.fc"
40
+ }
41
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:13a276d6f19edf3500e40ffc3f7978ccfe27c106af30121450e8642749ec1674
3
+ size 147836586
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ae141e5607a058ae26ad497455fc532cc97fe11789955404a7e8b9374c3bedcb
3
+ size 147941405