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