@@ -23,15 +23,15 @@ And by creating constructor object, then modify it and then create model.
2323
2424First import constructor class, then create model constructor oject.
2525
26- ``` python
26+ ```
2727from model_constructor.net import *
2828```
2929
30- ``` python
30+ ```
3131model = Net()
3232```
3333
34- ``` python
34+ ```
3535model
3636```
3737
4444
4545Now we have model consructor, defoult setting as xresnet18. And we can get model after call it.
4646
47- ``` python
47+ ```
4848model.c_in
4949```
5050
@@ -55,7 +55,7 @@ model.c_in
5555
5656
5757
58- ``` python
58+ ```
5959model.c_out
6060```
6161
@@ -66,7 +66,7 @@ model.c_out
6666
6767
6868
69- ``` python
69+ ```
7070model.stem_sizes
7171```
7272
@@ -77,7 +77,7 @@ model.stem_sizes
7777
7878
7979
80- ``` python
80+ ```
8181model.layers
8282```
8383
@@ -88,7 +88,7 @@ model.layers
8888
8989
9090
91- ``` python
91+ ```
9292model.expansion
9393```
9494
@@ -99,7 +99,7 @@ model.expansion
9999
100100
101101
102- ``` python
102+ ```
103103model()
104104```
105105
@@ -275,14 +275,14 @@ model()
275275If you want to change model, just change constructor parameters.
276276Lets create xresnet50.
277277
278- ``` python
278+ ```
279279model.expansion = 4
280280model.layers = [3,4,6,3]
281281```
282282
283283Now we can look at model body and if we call constructor - we have pytorch model!
284284
285- ``` python
285+ ```
286286model.body
287287```
288288
@@ -621,7 +621,7 @@ model.body
621621
622622
623623
624- ``` python
624+ ```
625625model.block_szs
626626```
627627
@@ -642,20 +642,20 @@ But now lets create model as mxresnet50 from fastai forums tread https://forums.
642642
643643Lets create mxresnet constructor.
644644
645- ``` python
645+ ```
646646mxresnet = Net()
647647```
648648
649649Then lets modify stem.
650650
651- ``` python
651+ ```
652652mxresnet.stem_sizes = [3,32,64,64]
653653```
654654
655655Now lets change activation function to Mish.
656656Here is link to forum disscussion https://forums.fast.ai/t/meet-mish-new-activation-function-possible-successor-to-relu
657657
658- ``` python
658+ ```
659659class Mish(nn.Module):
660660 def __init__(self):
661661 super().__init__()
@@ -664,7 +664,7 @@ class Mish(nn.Module):
664664 return x *( torch.tanh(F.softplus(x)))
665665```
666666
667- ``` python
667+ ```
668668mxresnet.expansion = 4
669669mxresnet.layers = [3,4,6,3]
670670mxresnet.act_fn = Mish()
@@ -675,7 +675,7 @@ Now we have mxresnet50 constructor.
675675We can inspect some parts of it.
676676And after call it we got model.
677677
678- ``` python
678+ ```
679679mxresnet
680680```
681681
@@ -686,7 +686,7 @@ mxresnet
686686
687687
688688
689- ``` python
689+ ```
690690mxresnet.stem.conv_1
691691```
692692
@@ -701,7 +701,7 @@ mxresnet.stem.conv_1
701701
702702
703703
704- ``` python
704+ ```
705705mxresnet.body.l_0.bl_0
706706```
707707
@@ -736,13 +736,13 @@ mxresnet.body.l_0.bl_0
736736
737737Now lets change Resblock. NewResBlock (stiil not own name yet) is in lib from version 0.1.0
738738
739- ``` python
739+ ```
740740mxresnet.block = NewResBlock
741741```
742742
743743That all. Let see what we have.
744744
745- ``` python
745+ ```
746746mxresnet.body.l_1.bl_0
747747```
748748
@@ -780,46 +780,46 @@ mxresnet.body.l_1.bl_0
780780
781781Usual way to get model - call constructor with parametrs.
782782
783- ``` python
783+ ```
784784from model_constructor.constructor import *
785785```
786786
787787Default is resnet18.
788788
789- ``` python
789+ ```
790790model = Net()
791791```
792792
793793You cant modify model after call constructor, so define model with parameters.
794794For example, resnet34:
795795
796- ``` python
796+ ```
797797resnet34 = Net(block=BasicBlock, blocks=[3, 4, 6, 3])
798798```
799799
800800## Predefined Resnet models - 18, 34, 50.
801801
802- ``` python
802+ ```
803803from model_constructor.resnet import *
804804```
805805
806- ``` python
806+ ```
807807model = resnet34(num_classes=10)
808808```
809809
810- ``` python
810+ ```
811811model = resnet50(num_classes=10)
812812```
813813
814814## Predefined Xresnet from fastai 1.
815815
816816This 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.
817817
818- ``` python
818+ ```
819819from model_constructor.xresnet import *
820820```
821821
822- ``` python
822+ ```
823823model = xresnet50()
824824```
825825
@@ -834,11 +834,11 @@ Here is some examples:
834834
835835Stem with 3 conv layers
836836
837- ``` python
837+ ```
838838model = Net(stem=partial(Stem, stem_sizes=[32, 32]))
839839```
840840
841- ``` python
841+ ```
842842model.stem
843843```
844844
@@ -867,11 +867,11 @@ model.stem
867867
868868
869869
870- ``` python
870+ ```
871871model = Net(stem_sizes=[32, 64])
872872```
873873
874- ``` python
874+ ```
875875model.stem
876876```
877877
@@ -902,11 +902,11 @@ model.stem
902902
903903### Activation function before Normalization
904904
905- ``` python
905+ ```
906906model = Net(bn_1st=False)
907907```
908908
909- ``` python
909+ ```
910910model.stem
911911```
912912
@@ -928,15 +928,15 @@ model.stem
928928
929929### Change activation function
930930
931- ``` python
931+ ```
932932new_act_fn = nn.LeakyReLU(inplace=True)
933933```
934934
935- ``` python
935+ ```
936936model = Net(act_fn=new_act_fn)
937937```
938938
939- ``` python
939+ ```
940940model.stem
941941```
942942
@@ -955,7 +955,7 @@ model.stem
955955
956956
957957
958- ``` python
958+ ```
959959model.body.layer_0.block_0
960960```
961961
0 commit comments