@@ -25,15 +25,15 @@ And Classic - create model from function with parameters.
2525
2626First import constructor class, then create model constructor oject.
2727
28- ``` python
28+ ```
2929from model_constructor.net import *
3030```
3131
32- ``` python
32+ ```
3333model = Net()
3434```
3535
36- ``` python
36+ ```
3737model
3838```
3939
4949
5050Now we have model consructor, default setting as xresnet18. And we can get model after call it.
5151
52- ``` python
52+ ```
5353model.c_in
5454```
5555
@@ -60,7 +60,7 @@ model.c_in
6060
6161
6262
63- ``` python
63+ ```
6464model.c_out
6565```
6666
@@ -71,7 +71,7 @@ model.c_out
7171
7272
7373
74- ``` python
74+ ```
7575model.stem_sizes
7676```
7777
@@ -82,7 +82,7 @@ model.stem_sizes
8282
8383
8484
85- ``` python
85+ ```
8686model.layers
8787```
8888
@@ -93,7 +93,7 @@ model.layers
9393
9494
9595
96- ``` python
96+ ```
9797model.expansion
9898```
9999
@@ -104,7 +104,7 @@ model.expansion
104104
105105
106106
107- ``` python
107+ ```
108108%nbdev_collapse_output
109109model()
110110```
@@ -285,14 +285,14 @@ model()
285285If you want to change model, just change constructor parameters.
286286Lets create xresnet50.
287287
288- ``` python
288+ ```
289289model.expansion = 4
290290model.layers = [3,4,6,3]
291291```
292292
293293Now we can look at model body and if we call constructor - we have pytorch model!
294294
295- ``` python
295+ ```
296296%nbdev_collapse_output
297297model.body
298298```
@@ -640,7 +640,7 @@ model.body
640640
641641</details >
642642
643- ``` python
643+ ```
644644model.block_szs
645645```
646646
@@ -661,25 +661,25 @@ But now lets create model as mxresnet50 from fastai forums tread https://forums.
661661
662662Lets create mxresnet constructor.
663663
664- ``` python
664+ ```
665665model = Net(name='MxResNet')
666666```
667667
668668Then lets modify stem.
669669
670- ``` python
670+ ```
671671model.stem_sizes = [3,32,64,64]
672672```
673673
674674Now lets change activation function to Mish.
675675Here is link to forum disscussion https://forums.fast.ai/t/meet-mish-new-activation-function-possible-successor-to-relu
676676Mish is in model_constructor.layer.
677677
678- ``` python
678+ ```
679679model.act_fn = Mish()
680680```
681681
682- ``` python
682+ ```
683683model
684684```
685685
@@ -693,7 +693,7 @@ model
693693
694694
695695
696- ``` python
696+ ```
697697%nbdev_collapse_output
698698model()
699699```
@@ -875,7 +875,7 @@ model()
875875
876876Now lets make MxResNet50
877877
878- ``` python
878+ ```
879879model.expansion = 4
880880model.layers = [3,4,6,3]
881881model.name = 'mxresnet50'
@@ -885,7 +885,7 @@ Now we have mxresnet50 constructor.
885885We can inspect every parts of it.
886886And after call it we got model.
887887
888- ``` python
888+ ```
889889model
890890```
891891
@@ -899,7 +899,7 @@ model
899899
900900
901901
902- ``` python
902+ ```
903903%nbdev_collapse_output
904904model.stem.conv_1
905905```
@@ -919,7 +919,7 @@ model.stem.conv_1
919919
920920</details >
921921
922- ``` python
922+ ```
923923%nbdev_collapse_output
924924model.body.l_0.bl_0
925925```
@@ -961,17 +961,17 @@ model.body.l_0.bl_0
961961
962962Now lets change Resblock to YaResBlock (Yet another ResNet, former NewResBlock) is in lib from version 0.1.0
963963
964- ``` python
964+ ```
965965from model_constructor.yaresnet import YaResBlock
966966```
967967
968- ``` python
968+ ```
969969model.block = YaResBlock
970970```
971971
972972That all. Now we have YaResNet constructor
973973
974- ``` python
974+ ```
975975model.name = 'YaResNet'
976976model
977977```
@@ -1146,7 +1146,7 @@ model
11461146
11471147Let see what we have.
11481148
1149- ``` python
1149+ ```
11501150%nbdev_collapse_output
11511151model.body.l_1.bl_0
11521152```
@@ -1189,43 +1189,43 @@ model.body.l_1.bl_0
11891189
11901190Usual way to get model - call constructor with parametrs.
11911191
1192- ``` python
1192+ ```
11931193from model_constructor.constructor import *
11941194```
11951195
11961196Default is resnet18.
11971197
1198- ``` python
1198+ ```
11991199model = Net()
12001200```
12011201
12021202You cant modify model after call constructor, so define model with parameters.
12031203For example, resnet34:
12041204
1205- ``` python
1205+ ```
12061206resnet34 = Net(block=BasicBlock, blocks=[3, 4, 6, 3])
12071207```
12081208
12091209## Predefined Resnet models - 18, 34, 50.
12101210
1211- ``` python
1211+ ```
12121212from model_constructor.resnet import *
12131213```
12141214
1215- ``` python
1215+ ```
12161216model = resnet34(num_classes=10)
12171217```
12181218
1219- ``` python
1219+ ```
12201220%nbdev_hide_output
12211221model
12221222```
12231223
1224- ``` python
1224+ ```
12251225model = resnet50(num_classes=10)
12261226```
12271227
1228- ``` python
1228+ ```
12291229%nbdev_hide_output
12301230model
12311231```
@@ -1234,15 +1234,15 @@ model
12341234
12351235This 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+ ```
12381238from model_constructor.xresnet import *
12391239```
12401240
1241- ``` python
1241+ ```
12421242model = xresnet50()
12431243```
12441244
1245- ``` python
1245+ ```
12461246%nbdev_hide_output
12471247model
12481248```
@@ -1258,11 +1258,11 @@ Here is some examples:
12581258
12591259Stem with 3 conv layers
12601260
1261- ``` python
1261+ ```
12621262model = Net(stem=partial(Stem, stem_sizes=[32, 32]))
12631263```
12641264
1265- ``` python
1265+ ```
12661266%nbdev_collapse_output
12671267model.stem
12681268```
@@ -1296,11 +1296,11 @@ model.stem
12961296
12971297</details >
12981298
1299- ``` python
1299+ ```
13001300model = Net(stem_sizes=[32, 64])
13011301```
13021302
1303- ``` python
1303+ ```
13041304%nbdev_collapse_output
13051305model.stem
13061306```
@@ -1336,11 +1336,11 @@ model.stem
13361336
13371337### Activation function before Normalization
13381338
1339- ``` python
1339+ ```
13401340model = Net(bn_1st=False)
13411341```
13421342
1343- ``` python
1343+ ```
13441344model.stem
13451345```
13461346
@@ -1362,15 +1362,15 @@ model.stem
13621362
13631363### Change activation function
13641364
1365- ``` python
1365+ ```
13661366new_act_fn = nn.LeakyReLU(inplace=True)
13671367```
13681368
1369- ``` python
1369+ ```
13701370model = Net(act_fn=new_act_fn)
13711371```
13721372
1373- ``` python
1373+ ```
13741374%nbdev_collapse_output
13751375model.stem
13761376```
@@ -1394,7 +1394,7 @@ model.stem
13941394
13951395</details >
13961396
1397- ``` python
1397+ ```
13981398%nbdev_collapse_output
13991399model.body.layer_0.block_0
14001400```
0 commit comments