Skip to content

Commit 667d387

Browse files
author
ayasyrev
committed
fix docs
1 parent 27db61b commit 667d387

File tree

2 files changed

+47
-49
lines changed

2 files changed

+47
-49
lines changed

README.md

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ And by creating constructor object, then modify it and then create model.
2323

2424
First import constructor class, then create model constructor oject.
2525

26-
```python
26+
```
2727
from model_constructor.net import *
2828
```
2929

30-
```python
30+
```
3131
model = Net()
3232
```
3333

34-
```python
34+
```
3535
model
3636
```
3737

@@ -44,7 +44,7 @@ model
4444

4545
Now we have model consructor, defoult setting as xresnet18. And we can get model after call it.
4646

47-
```python
47+
```
4848
model.c_in
4949
```
5050

@@ -55,7 +55,7 @@ model.c_in
5555

5656

5757

58-
```python
58+
```
5959
model.c_out
6060
```
6161

@@ -66,7 +66,7 @@ model.c_out
6666

6767

6868

69-
```python
69+
```
7070
model.stem_sizes
7171
```
7272

@@ -77,7 +77,7 @@ model.stem_sizes
7777

7878

7979

80-
```python
80+
```
8181
model.layers
8282
```
8383

@@ -88,7 +88,7 @@ model.layers
8888

8989

9090

91-
```python
91+
```
9292
model.expansion
9393
```
9494

@@ -99,7 +99,7 @@ model.expansion
9999

100100

101101

102-
```python
102+
```
103103
model()
104104
```
105105

@@ -275,14 +275,14 @@ model()
275275
If you want to change model, just change constructor parameters.
276276
Lets create xresnet50.
277277

278-
```python
278+
```
279279
model.expansion = 4
280280
model.layers = [3,4,6,3]
281281
```
282282

283283
Now we can look at model body and if we call constructor - we have pytorch model!
284284

285-
```python
285+
```
286286
model.body
287287
```
288288

@@ -621,7 +621,7 @@ model.body
621621

622622

623623

624-
```python
624+
```
625625
model.block_szs
626626
```
627627

@@ -642,20 +642,20 @@ But now lets create model as mxresnet50 from fastai forums tread https://forums.
642642

643643
Lets create mxresnet constructor.
644644

645-
```python
645+
```
646646
mxresnet = Net()
647647
```
648648

649649
Then lets modify stem.
650650

651-
```python
651+
```
652652
mxresnet.stem_sizes = [3,32,64,64]
653653
```
654654

655655
Now lets change activation function to Mish.
656656
Here is link to forum disscussion https://forums.fast.ai/t/meet-mish-new-activation-function-possible-successor-to-relu
657657

658-
```python
658+
```
659659
class 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+
```
668668
mxresnet.expansion = 4
669669
mxresnet.layers = [3,4,6,3]
670670
mxresnet.act_fn = Mish()
@@ -675,7 +675,7 @@ Now we have mxresnet50 constructor.
675675
We can inspect some parts of it.
676676
And after call it we got model.
677677

678-
```python
678+
```
679679
mxresnet
680680
```
681681

@@ -686,7 +686,7 @@ mxresnet
686686

687687

688688

689-
```python
689+
```
690690
mxresnet.stem.conv_1
691691
```
692692

@@ -701,7 +701,7 @@ mxresnet.stem.conv_1
701701

702702

703703

704-
```python
704+
```
705705
mxresnet.body.l_0.bl_0
706706
```
707707

@@ -736,13 +736,13 @@ mxresnet.body.l_0.bl_0
736736

737737
Now lets change Resblock. NewResBlock (stiil not own name yet) is in lib from version 0.1.0
738738

739-
```python
739+
```
740740
mxresnet.block = NewResBlock
741741
```
742742

743743
That all. Let see what we have.
744744

745-
```python
745+
```
746746
mxresnet.body.l_1.bl_0
747747
```
748748

@@ -780,46 +780,46 @@ mxresnet.body.l_1.bl_0
780780

781781
Usual way to get model - call constructor with parametrs.
782782

783-
```python
783+
```
784784
from model_constructor.constructor import *
785785
```
786786

787787
Default is resnet18.
788788

789-
```python
789+
```
790790
model = Net()
791791
```
792792

793793
You cant modify model after call constructor, so define model with parameters.
794794
For example, resnet34:
795795

796-
```python
796+
```
797797
resnet34 = Net(block=BasicBlock, blocks=[3, 4, 6, 3])
798798
```
799799

800800
## Predefined Resnet models - 18, 34, 50.
801801

802-
```python
802+
```
803803
from model_constructor.resnet import *
804804
```
805805

806-
```python
806+
```
807807
model = resnet34(num_classes=10)
808808
```
809809

810-
```python
810+
```
811811
model = resnet50(num_classes=10)
812812
```
813813

814814
## Predefined Xresnet from fastai 1.
815815

816816
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.
817817

818-
```python
818+
```
819819
from model_constructor.xresnet import *
820820
```
821821

822-
```python
822+
```
823823
model = xresnet50()
824824
```
825825

@@ -834,11 +834,11 @@ Here is some examples:
834834

835835
Stem with 3 conv layers
836836

837-
```python
837+
```
838838
model = Net(stem=partial(Stem, stem_sizes=[32, 32]))
839839
```
840840

841-
```python
841+
```
842842
model.stem
843843
```
844844

@@ -867,11 +867,11 @@ model.stem
867867

868868

869869

870-
```python
870+
```
871871
model = Net(stem_sizes=[32, 64])
872872
```
873873

874-
```python
874+
```
875875
model.stem
876876
```
877877

@@ -902,11 +902,11 @@ model.stem
902902

903903
### Activation function before Normalization
904904

905-
```python
905+
```
906906
model = Net(bn_1st=False)
907907
```
908908

909-
```python
909+
```
910910
model.stem
911911
```
912912

@@ -928,15 +928,15 @@ model.stem
928928

929929
### Change activation function
930930

931-
```python
931+
```
932932
new_act_fn = nn.LeakyReLU(inplace=True)
933933
```
934934

935-
```python
935+
```
936936
model = Net(act_fn=new_act_fn)
937937
```
938938

939-
```python
939+
```
940940
model.stem
941941
```
942942

@@ -955,7 +955,7 @@ model.stem
955955

956956

957957

958-
```python
958+
```
959959
model.body.layer_0.block_0
960960
```
961961

model_constructor/_nbdev.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
"Body": "00_constructor.ipynb",
88
"Head": "00_constructor.ipynb",
99
"init_model": "00_constructor.ipynb",
10-
"Net": "81_Net.ipynb",
10+
"Net": "04_Net.ipynb",
1111
"ConvLayer": "01_layers.ipynb",
12-
"act_fn": "81_Net.ipynb",
12+
"act_fn": "04_Net.ipynb",
1313
"Flatten": "01_layers.ipynb",
1414
"noop": "01_layers.ipynb",
1515
"Noop": "01_layers.ipynb",
@@ -22,24 +22,22 @@
2222
"SimpleSelfAttention": "01_layers.ipynb",
2323
"ConvBlockBasic": "01_layers.ipynb",
2424
"ConvBlockBottle": "01_layers.ipynb",
25-
"ResBlock": "81_Net.ipynb",
25+
"ResBlock": "04_Net.ipynb",
2626
"resnet18": "02_resnet.ipynb",
2727
"resnet34": "02_resnet.ipynb",
2828
"resnet50": "02_resnet.ipynb",
2929
"xresnet18": "03_xresnet.ipynb",
3030
"xresnet34": "03_xresnet.ipynb",
31-
"xresnet50": "81_Net.ipynb",
32-
"init_cnn": "81_Net.ipynb",
33-
"NewResBlock": "81_Net.ipynb",
34-
"me": "81_Net.ipynb",
35-
"NewConvLayer": "81_Net.ipynb"}
31+
"xresnet50": "04_Net.ipynb",
32+
"init_cnn": "04_Net.ipynb",
33+
"NewResBlock": "04_Net.ipynb",
34+
"me": "04_Net.ipynb"}
3635

3736
modules = ["constructor.py",
3837
"layers.py",
3938
"resnet.py",
4039
"xresnet.py",
41-
"net.py",
42-
"tst_net_2.py"]
40+
"net.py"]
4341

4442
doc_url = "https://ayasyrev.github.io/model_constructor/"
4543

0 commit comments

Comments
 (0)