Skip to content

Commit 4eae75c

Browse files
author
ayasyrev
committed
groups fixed
1 parent b8d7160 commit 4eae75c

File tree

8 files changed

+91
-107
lines changed

8 files changed

+91
-107
lines changed

README.md

+46-46
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ And Classic - create model from function with parameters.
2525

2626
First import constructor class, then create model constructor oject.
2727

28-
```python
28+
```
2929
from model_constructor.net import *
3030
```
3131

32-
```python
32+
```
3333
model = Net()
3434
```
3535

36-
```python
36+
```
3737
model
3838
```
3939

@@ -49,7 +49,7 @@ model
4949

5050
Now we have model consructor, default setting as xresnet18. And we can get model after call it.
5151

52-
```python
52+
```
5353
model.c_in
5454
```
5555

@@ -60,7 +60,7 @@ model.c_in
6060

6161

6262

63-
```python
63+
```
6464
model.c_out
6565
```
6666

@@ -71,7 +71,7 @@ model.c_out
7171

7272

7373

74-
```python
74+
```
7575
model.stem_sizes
7676
```
7777

@@ -82,7 +82,7 @@ model.stem_sizes
8282

8383

8484

85-
```python
85+
```
8686
model.layers
8787
```
8888

@@ -93,7 +93,7 @@ model.layers
9393

9494

9595

96-
```python
96+
```
9797
model.expansion
9898
```
9999

@@ -104,7 +104,7 @@ model.expansion
104104

105105

106106

107-
```python
107+
```
108108
%nbdev_collapse_output
109109
model()
110110
```
@@ -285,14 +285,14 @@ model()
285285
If you want to change model, just change constructor parameters.
286286
Lets create xresnet50.
287287

288-
```python
288+
```
289289
model.expansion = 4
290290
model.layers = [3,4,6,3]
291291
```
292292

293293
Now we can look at model body and if we call constructor - we have pytorch model!
294294

295-
```python
295+
```
296296
%nbdev_collapse_output
297297
model.body
298298
```
@@ -640,7 +640,7 @@ model.body
640640

641641
</details>
642642

643-
```python
643+
```
644644
model.block_szs
645645
```
646646

@@ -661,25 +661,25 @@ But now lets create model as mxresnet50 from fastai forums tread https://forums.
661661

662662
Lets create mxresnet constructor.
663663

664-
```python
664+
```
665665
model = Net(name='MxResNet')
666666
```
667667

668668
Then lets modify stem.
669669

670-
```python
670+
```
671671
model.stem_sizes = [3,32,64,64]
672672
```
673673

674674
Now lets change activation function to Mish.
675675
Here is link to forum disscussion https://forums.fast.ai/t/meet-mish-new-activation-function-possible-successor-to-relu
676676
Mish is in model_constructor.layer.
677677

678-
```python
678+
```
679679
model.act_fn = Mish()
680680
```
681681

682-
```python
682+
```
683683
model
684684
```
685685

@@ -693,7 +693,7 @@ model
693693

694694

695695

696-
```python
696+
```
697697
%nbdev_collapse_output
698698
model()
699699
```
@@ -875,7 +875,7 @@ model()
875875

876876
Now lets make MxResNet50
877877

878-
```python
878+
```
879879
model.expansion = 4
880880
model.layers = [3,4,6,3]
881881
model.name = 'mxresnet50'
@@ -885,7 +885,7 @@ Now we have mxresnet50 constructor.
885885
We can inspect every parts of it.
886886
And after call it we got model.
887887

888-
```python
888+
```
889889
model
890890
```
891891

@@ -899,7 +899,7 @@ model
899899

900900

901901

902-
```python
902+
```
903903
%nbdev_collapse_output
904904
model.stem.conv_1
905905
```
@@ -919,7 +919,7 @@ model.stem.conv_1
919919

920920
</details>
921921

922-
```python
922+
```
923923
%nbdev_collapse_output
924924
model.body.l_0.bl_0
925925
```
@@ -961,17 +961,17 @@ model.body.l_0.bl_0
961961

962962
Now lets change Resblock to YaResBlock (Yet another ResNet, former NewResBlock) is in lib from version 0.1.0
963963

964-
```python
964+
```
965965
from model_constructor.yaresnet import YaResBlock
966966
```
967967

968-
```python
968+
```
969969
model.block = YaResBlock
970970
```
971971

972972
That all. Now we have YaResNet constructor
973973

974-
```python
974+
```
975975
model.name = 'YaResNet'
976976
model
977977
```
@@ -1146,7 +1146,7 @@ model
11461146

11471147
Let see what we have.
11481148

1149-
```python
1149+
```
11501150
%nbdev_collapse_output
11511151
model.body.l_1.bl_0
11521152
```
@@ -1189,43 +1189,43 @@ model.body.l_1.bl_0
11891189

11901190
Usual way to get model - call constructor with parametrs.
11911191

1192-
```python
1192+
```
11931193
from model_constructor.constructor import *
11941194
```
11951195

11961196
Default is resnet18.
11971197

1198-
```python
1198+
```
11991199
model = Net()
12001200
```
12011201

12021202
You cant modify model after call constructor, so define model with parameters.
12031203
For example, resnet34:
12041204

1205-
```python
1205+
```
12061206
resnet34 = Net(block=BasicBlock, blocks=[3, 4, 6, 3])
12071207
```
12081208

12091209
## Predefined Resnet models - 18, 34, 50.
12101210

1211-
```python
1211+
```
12121212
from model_constructor.resnet import *
12131213
```
12141214

1215-
```python
1215+
```
12161216
model = resnet34(num_classes=10)
12171217
```
12181218

1219-
```python
1219+
```
12201220
%nbdev_hide_output
12211221
model
12221222
```
12231223

1224-
```python
1224+
```
12251225
model = resnet50(num_classes=10)
12261226
```
12271227

1228-
```python
1228+
```
12291229
%nbdev_hide_output
12301230
model
12311231
```
@@ -1234,15 +1234,15 @@ model
12341234

12351235
This ie simplified version from fastai v1. I did refactoring for better understand and experiment with models. For example, it's very simple to change activation funtions, different stems, batchnorm and activation order etc. In v2 much powerfull realisation.
12361236

1237-
```python
1237+
```
12381238
from model_constructor.xresnet import *
12391239
```
12401240

1241-
```python
1241+
```
12421242
model = xresnet50()
12431243
```
12441244

1245-
```python
1245+
```
12461246
%nbdev_hide_output
12471247
model
12481248
```
@@ -1258,11 +1258,11 @@ Here is some examples:
12581258

12591259
Stem with 3 conv layers
12601260

1261-
```python
1261+
```
12621262
model = Net(stem=partial(Stem, stem_sizes=[32, 32]))
12631263
```
12641264

1265-
```python
1265+
```
12661266
%nbdev_collapse_output
12671267
model.stem
12681268
```
@@ -1296,11 +1296,11 @@ model.stem
12961296

12971297
</details>
12981298

1299-
```python
1299+
```
13001300
model = Net(stem_sizes=[32, 64])
13011301
```
13021302

1303-
```python
1303+
```
13041304
%nbdev_collapse_output
13051305
model.stem
13061306
```
@@ -1336,11 +1336,11 @@ model.stem
13361336

13371337
### Activation function before Normalization
13381338

1339-
```python
1339+
```
13401340
model = Net(bn_1st=False)
13411341
```
13421342

1343-
```python
1343+
```
13441344
model.stem
13451345
```
13461346

@@ -1362,15 +1362,15 @@ model.stem
13621362

13631363
### Change activation function
13641364

1365-
```python
1365+
```
13661366
new_act_fn = nn.LeakyReLU(inplace=True)
13671367
```
13681368

1369-
```python
1369+
```
13701370
model = Net(act_fn=new_act_fn)
13711371
```
13721372

1373-
```python
1373+
```
13741374
%nbdev_collapse_output
13751375
model.stem
13761376
```
@@ -1394,7 +1394,7 @@ model.stem
13941394

13951395
</details>
13961396

1397-
```python
1397+
```
13981398
%nbdev_collapse_output
13991399
model.body.layer_0.block_0
14001400
```

0 commit comments

Comments
 (0)