commit files to HF hub
Browse files
README.md
CHANGED
@@ -1,52 +1,52 @@
|
|
1 |
Implementation of ResNet proposed in [Deep Residual Learning for Image
|
2 |
Recognition](https://arxiv.org/abs/1512.03385)
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
1 |
Implementation of ResNet proposed in [Deep Residual Learning for Image
|
2 |
Recognition](https://arxiv.org/abs/1512.03385)
|
3 |
|
4 |
+
``` python
|
5 |
+
ResNet.resnet18()
|
6 |
+
ResNet.resnet26()
|
7 |
+
ResNet.resnet34()
|
8 |
+
ResNet.resnet50()
|
9 |
+
ResNet.resnet101()
|
10 |
+
ResNet.resnet152()
|
11 |
+
ResNet.resnet200()
|
12 |
+
|
13 |
+
Variants (d) proposed in `Bag of Tricks for Image Classification with Convolutional Neural Networks <https://arxiv.org/pdf/1812.01187.pdf`_
|
14 |
+
|
15 |
+
ResNet.resnet26d()
|
16 |
+
ResNet.resnet34d()
|
17 |
+
ResNet.resnet50d()
|
18 |
+
# You can construct your own one by chaning `stem` and `block`
|
19 |
+
resnet101d = ResNet.resnet101(stem=ResNetStemC, block=partial(ResNetBottleneckBlock, shortcut=ResNetShorcutD))
|
20 |
+
```
|
21 |
+
|
22 |
+
Examples:
|
23 |
+
|
24 |
+
``` python
|
25 |
+
# change activation
|
26 |
+
ResNet.resnet18(activation = nn.SELU)
|
27 |
+
# change number of classes (default is 1000 )
|
28 |
+
ResNet.resnet18(n_classes=100)
|
29 |
+
# pass a different block
|
30 |
+
ResNet.resnet18(block=SENetBasicBlock)
|
31 |
+
# change the steam
|
32 |
+
model = ResNet.resnet18(stem=ResNetStemC)
|
33 |
+
change shortcut
|
34 |
+
model = ResNet.resnet18(block=partial(ResNetBasicBlock, shortcut=ResNetShorcutD))
|
35 |
+
# store each feature
|
36 |
+
x = torch.rand((1, 3, 224, 224))
|
37 |
+
# get features
|
38 |
+
model = ResNet.resnet18()
|
39 |
+
# first call .features, this will activate the forward hooks and tells the model you'll like to get the features
|
40 |
+
model.encoder.features
|
41 |
+
model(torch.randn((1,3,224,224)))
|
42 |
+
# get the features from the encoder
|
43 |
+
features = model.encoder.features
|
44 |
+
print([x.shape for x in features])
|
45 |
+
#[torch.Size([1, 64, 112, 112]), torch.Size([1, 64, 56, 56]), torch.Size([1, 128, 28, 28]), torch.Size([1, 256, 14, 14])]
|
46 |
+
```
|
47 |
+
|
48 |
+
Args:
|
49 |
+
|
50 |
+
: in\_channels (int, optional): Number of channels in the input
|
51 |
+
Image (3 for RGB and 1 for Gray). Defaults to 3. n\_classes (int,
|
52 |
+
optional): Number of classes. Defaults to 1000.
|