diff --git a/00_core.ipynb b/00_core.ipynb deleted file mode 100644 index 6c17de9..0000000 --- a/00_core.ipynb +++ /dev/null @@ -1,48 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# default_exp core" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# module name here\n", - "\n", - "> API details." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#hide\n", - "from nbdev.showdoc import *" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/Nbs/00_ModelConstructor.ipynb b/Nbs/00_ModelConstructor.ipynb new file mode 100644 index 0000000..ecf9ee5 --- /dev/null +++ b/Nbs/00_ModelConstructor.ipynb @@ -0,0 +1,1597 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Model constructor.\n", + "\n", + "> Create and tune pytorch model." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "#hide" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "ExecuteTime": { + "end_time": "2021-10-11T11:11:43.985194Z", + "start_time": "2021-10-11T11:11:43.178837Z" + } + }, + "outputs": [], + "source": [ + "#hide\n", + "import torch\n", + "import torch.nn as nn\n", + "\n", + "from nbdev.showdoc import show_doc\n", + "from IPython.display import Markdown, display" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "ExecuteTime": { + "end_time": "2021-10-11T11:11:46.969707Z", + "start_time": "2021-10-11T11:11:46.964854Z" + } + }, + "outputs": [], + "source": [ + "# hide\n", + "def print_doc(func_name):\n", + " doc = show_doc(func_name, title_level=4, disp=False)\n", + " display(Markdown(doc))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## ResBlock" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "ExecuteTime": { + "end_time": "2021-10-11T11:12:51.179027Z", + "start_time": "2021-10-11T11:12:51.175828Z" + } + }, + "outputs": [], + "source": [ + "#hide\n", + "from model_constructor.model_constructor import ResBlock" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "ExecuteTime": { + "end_time": "2021-10-11T11:13:16.700317Z", + "start_time": "2021-10-11T11:13:16.692963Z" + } + }, + "outputs": [ + { + "data": { + "text/markdown": [ + "
class
ResBlock
[source]ResBlock
(**`expansion`**, **`ni`**, **`nh`**, **`stride`**=*`1`*, **`conv_layer`**=*`ConvLayer`*, **`act_fn`**=*`ReLU(inplace=True)`*, **`zero_bn`**=*`True`*, **`bn_1st`**=*`True`*, **`pool`**=*`AvgPool2d(kernel_size=2, stride=2, padding=0)`*, **`sa`**=*`False`*, **`sym`**=*`False`*, **`groups`**=*`1`*, **`dw`**=*`False`*, **`div_groups`**=*`None`*, **`se_module`**=*`SEModule`*, **`se`**=*`False`*, **`se_reduction`**=*`16`*) :: `Module`\n",
+ "\n",
+ "Resnet block"
+ ],
+ "text/plain": [
+ "_make_layer
[source]_make_layer
(**`expansion`**, **`ni`**, **`nf`**, **`blocks`**, **`stride`**, **`sa`**)\n",
+ "\n"
+ ],
+ "text/plain": [
+ "_make_stem
[source]_make_stem
()\n",
+ "\n"
+ ],
+ "text/plain": [
+ "_make_body
[source]_make_body
()\n",
+ "\n"
+ ],
+ "text/plain": [
+ "_make_head
[source]_make_head
()\n",
+ "\n"
+ ],
+ "text/plain": [
+ "class
ModelConstructor
[source]ModelConstructor
(**`name`**=*`'MC'`*, **`c_in`**=*`3`*, **`c_out`**=*`1000`*, **`block`**=*`ResBlock`*, **`conv_layer`**=*`ConvLayer`*, **`block_sizes`**=*`[64, 128, 256, 512]`*, **`layers`**=*`[2, 2, 2, 2]`*, **`norm`**=*`BatchNorm2d`*, **`act_fn`**=*`ReLU(inplace=True)`*, **`pool`**=*`AvgPool2d(kernel_size=2, stride=2, padding=0)`*, **`expansion`**=*`1`*, **`groups`**=*`1`*, **`dw`**=*`False`*, **`div_groups`**=*`None`*, **`sa`**=*`False`*, **`se`**=*`False`*, **`se_module`**=*`SEModule`*, **`se_reduction`**=*`16`*, **`bn_1st`**=*`True`*, **`zero_bn`**=*`True`*, **`stem_stride_on`**=*`0`*, **`stem_sizes`**=*`[32, 32, 64]`*, **`stem_pool`**=*`MaxPool2d(kernel_size=3, stride=2, padding=1, dilation=1, ceil_mode=False)`*, **`stem_bn_end`**=*`False`*, **`_init_cnn`**=*`init_cnn`*, **`_make_stem`**=*`_make_stem`*, **`_make_layer`**=*`_make_layer`*, **`_make_body`**=*`_make_body`*, **`_make_head`**=*`_make_head`*)\n",
+ "\n",
+ "Model constructor. As default - xresnet18"
+ ],
+ "text/plain": [
+ "class
YaResBlock
[source]YaResBlock
(**`expansion`**, **`ni`**, **`nh`**, **`stride`**=*`1`*, **`conv_layer`**=*`ConvLayer`*, **`act_fn`**=*`ReLU(inplace=True)`*, **`zero_bn`**=*`True`*, **`bn_1st`**=*`True`*, **`pool`**=*`AvgPool2d(kernel_size=2, stride=2, padding=0)`*, **`sa`**=*`False`*, **`sym`**=*`False`*, **`groups`**=*`1`*, **`dw`**=*`False`*, **`div_groups`**=*`None`*, **`se_module`**=*`SEModule`*, **`se`**=*`False`*, **`se_reduction`**=*`16`*) :: `Module`\n",
+ "\n",
+ "YaResBlock. Reduce by pool instead of stride 2"
+ ],
+ "text/plain": [
+ "block = ResBlock(1,64,64,sa=True)
+block
+
block = ResBlock(4,64,64,sa=True, dw=True)
+block
+
block = ResBlock(4,64,64,sa=True, groups=4)
+block
+
block = ResBlock(2,64,64,act_fn=nn.LeakyReLU(), bn_1st=False)
+block
+
block = ResBlock(2, 64, 64, sa=True, se=True)
+block
+
mc = ModelConstructor()
+mc
+
mc._block_sizes
+
mc.block_sizes
+
mc._block_sizes = [128, 256, 512, 1024]
+mc
+
mc.block_sizes
+
mc.block_sizes
+
model = ModelConstructor()
+
mc.stem
+
mc.stem_stride_on = 1
+mc.stem
+
mc.bn_1st = False
+
mc.act_fn =nn.LeakyReLU(inplace=True)
+
mc.sa = True
+mc.se = True
+
mc.body.l_1
+
yaresnet = Net(block=YaResBlock, stem_sizes = [3, 32, 64, 64], name='YaResNet')
+from model_constructor import ModelConstructor
+yaresnet = ModelConstructor(block=YaResBlock, stem_sizes = [3, 32, 64, 64], name='YaResNet')
YaResNet constructor c_in: 3, c_out: 1000 - expansion: 1, groups: 1, dw: False + expansion: 1, groups: 1, dw: False, div_groups: None sa: False, se: False - stem sizes: [3, 32, 64, 64], stide on 0 + stem sizes: [3, 32, 64, 64], stride on 0 body sizes [64, 128, 256, 512] layers: [2, 2, 2, 2]
yaresnet.act_fn = Mish()
+yaresnet.act_fn = torch.nn.Mish()
yaresnet()
@@ -790,7 +816,7 @@ YaResNet constructor.
Sequential(
- model YaResNet
+ YaResNet
(stem): Sequential(
(conv_0): ConvLayer(
(conv): Conv2d(3, 32, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
@@ -963,120 +989,6 @@ YaResNet constructor.
{% endraw %}
-
- {% raw %}
-
-
-
-
-
-
-yaresnet_parameters = {'block': YaResBlock, 'stem_sizes': [3, 32, 64, 64], 'act_fn': Mish(), 'stem_stride_on': 1}
-yaresnet34 = partial(Net, name='YaResnet34', expansion=1, layers=[3, 4, 6, 3], **yaresnet_parameters)
-yaresnet50 = partial(Net, name='YaResnet50', expansion=4, layers=[3, 4, 6, 3], **yaresnet_parameters)
-
-
-
-
-
-
-
- {% endraw %}
-
- {% raw %}
-
-
-
-
-
-
-model = yaresnet50(c_out=10)
-
-
-
-
-
-
-
- {% endraw %}
-
- {% raw %}
-
-
-
-
-
-
-model
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {% endraw %}
-
- {% raw %}
-
-
-
-
-
-
-model.c_out, model.layers
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {% endraw %}
-
end
model_constructor
diff --git a/docs/_data/sidebars/home_sidebar.yml b/docs/_data/sidebars/home_sidebar.yml
index 72d7345..ad2b994 100644
--- a/docs/_data/sidebars/home_sidebar.yml
+++ b/docs/_data/sidebars/home_sidebar.yml
@@ -10,8 +10,8 @@ entries:
title: Overview
url: /
- output: web,pdf
- title: Model constructor class.
- url: Net.html
+ title: Model constructor.
+ url: ModelConstructor.html
- output: web,pdf
title: Activations functions.
url: activations.html
@@ -30,6 +30,9 @@ entries:
- output: web,pdf
title: ConvMixer
url: ConvMixer.html
+ - output: web,pdf
+ title: First version. Net.
+ url: Net.html
- output: web,pdf
title: Base constructor
url: base_constructor.html
diff --git a/docs/activations.html b/docs/activations.html
index ce56e97..1aeba5c 100644
--- a/docs/activations.html
+++ b/docs/activations.html
@@ -43,6 +43,13 @@
https://github.com/digantamisra98/Mish
fastai forum discussion https://forums.fast.ai/t/meet-mish-new-activation-function-possible-successor-to-relu
+
+
+
+
+
+Mish is in Pytorch from version 1.9. Use this version!
+
diff --git a/docs/index.html b/docs/index.html
index bf7aaab..4d6fe78 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -64,7 +64,7 @@ How to use
-First import constructor class, then create model constructor oject.
+First import constructor class, then create model constructor object.
Now you can change every part of model.
@@ -77,7 +77,7 @@ How to use
-from model_constructor.net import Net
+from model_constructor import ModelConstructor
@@ -94,7 +94,7 @@ How to use
-model = Net()
+mc = ModelConstructor()
@@ -111,7 +111,7 @@ How to use
-model
+mc
@@ -126,11 +126,11 @@ How to use
-Net constructor
+MC constructor
c_in: 3, c_out: 1000
- expansion: 1, groups: 1, dw: False
+ expansion: 1, groups: 1, dw: False, div_groups: None
sa: False, se: False
- stem sizes: [3, 32, 32, 64], stide on 0
+ stem sizes: [3, 32, 32, 64], stride on 0
body sizes [64, 128, 256, 512]
layers: [2, 2, 2, 2]
@@ -157,172 +157,8 @@ How to use
-model.c_in
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {% endraw %}
-
- {% raw %}
-
-
-
-
-
-
-model.c_out
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {% endraw %}
-
- {% raw %}
-
-
-
-
-
-
-model.stem_sizes
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {% endraw %}
-
- {% raw %}
-
-
-
-
-
-
-model.layers
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {% endraw %}
-
- {% raw %}
-
-
-
-
-
-
-model.expansion
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {% endraw %}
-
- {% raw %}
-
-
-
-
-
-
-model()
+model = mc()
+model
@@ -341,7 +177,7 @@ How to use
Sequential(
- model Net
+ MC
(stem): Sequential(
(conv_0): ConvLayer(
(conv): Conv2d(3, 32, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
@@ -529,8 +365,8 @@ How to use
-model.expansion = 4
-model.layers = [3,4,6,3]
+mc.expansion = 4
+mc.layers = [3,4,6,3]
@@ -554,7 +390,7 @@ How to use
-model.body
+mc.body
@@ -577,60 +413,27 @@ How to use How to use How to use How to use More modification.
-model = Net(name='MxResNet')
+mc = ModelConstructor(name='MxResNet')
@@ -969,7 +609,7 @@ More modification.
-model.stem_sizes = [3,32,64,64]
+mc.stem_sizes = [3,32,64,64]
@@ -983,7 +623,7 @@ More modification.
Now lets change activation function to Mish.
Here is link to forum disscussion https://forums.fast.ai/t/meet-mish-new-activation-function-possible-successor-to-relu
-Mish is in model_constructor.activations
+We'v got Mish is in model_constructor.activations, but from pytorch 1.9 take it from torch:
@@ -995,7 +635,7 @@ More modification.
-from model_constructor.activations import Mish
+from torch.nn import Mish
@@ -1012,7 +652,7 @@ More modification.
-model.act_fn = Mish()
+mc.act_fn = Mish()
@@ -1029,7 +669,7 @@ More modification.
-model
+mc
@@ -1046,9 +686,9 @@ More modification.
MxResNet constructor
c_in: 3, c_out: 1000
- expansion: 1, groups: 1, dw: False
+ expansion: 1, groups: 1, dw: False, div_groups: None
sa: False, se: False
- stem sizes: [3, 32, 64, 64], stide on 0
+ stem sizes: [3, 32, 32, 64], stride on 0
body sizes [64, 128, 256, 512]
layers: [2, 2, 2, 2]
@@ -1068,7 +708,7 @@ More modification.
-model()
+mc()
@@ -1087,7 +727,7 @@ More modification.
Sequential(
- model MxResNet
+ MxResNet
(stem): Sequential(
(conv_0): ConvLayer(
(conv): Conv2d(3, 32, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
@@ -1095,12 +735,12 @@ More modification.MXResNet
-model.expansion = 4
-model.layers = [3,4,6,3]
-model.name = 'mxresnet50'
+mc.expansion = 4
+mc.layers = [3,4,6,3]
+mc.name = 'mxresnet50'
@@ -1308,7 +948,7 @@ MXResNet
-model
+mc
@@ -1325,9 +965,9 @@ MXResNet
@@ -1347,7 +987,7 @@ MXResNet
-model.stem.conv_1
+mc.stem.conv_1
@@ -1366,8 +1006,8 @@ MXResNet
@@ -1388,7 +1028,7 @@ MXResNet
-model.body.l_0.bl_0
+mc.body.l_0.bl_0
@@ -1477,7 +1117,7 @@ YaResNet
-model.block = YaResBlock
+mc.block = YaResBlock
@@ -1501,8 +1141,8 @@ YaResNet
-model.name = 'YaResNet'
-model
+mc.name = 'YaResNet'
+mc
@@ -1522,9 +1162,9 @@ YaResNet
@@ -1552,7 +1192,7 @@ YaResNet
{% endraw %}
+
+
+
+First version, it deprecated, but still here for compatability.
+
+
+
+
+ {% raw %}
+
+
+
+
+
+
+from model_constructor.net import Net
+
+
+
+
+
+
+
+ {% endraw %}
+
+ {% raw %}
+
+
+
+
+
+
+mc = Net()
+
+
+
+
+
+
+
+ {% endraw %}
+
+ {% raw %}
+
+
+
+
+
+
+mc
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {% endraw %}
+
diff --git a/docs/sidebar.json b/docs/sidebar.json
index 0f32017..6aa0196 100644
--- a/docs/sidebar.json
+++ b/docs/sidebar.json
@@ -1,13 +1,14 @@
{
"model_constructor": {
"Overview": "/",
- "Model constructor class.": "Net.html",
+ "Model constructor.": "ModelConstructor.html",
"Activations functions.": "activations.html",
"Layers": "layers.html",
"MXResNet.": "MXResNet.html",
"YaResNet.": "YaResNet.html",
"Twist.": "Twist.html",
"ConvMixer": "ConvMixer.html",
+ "First version. Net.": "Net.html",
"Base constructor": "base_constructor.html",
"xresnet": "xresnet.html"
}
diff --git a/index.ipynb b/index.ipynb
deleted file mode 100644
index 31356b0..0000000
--- a/index.ipynb
+++ /dev/null
@@ -1,94 +0,0 @@
-{
- "cells": [
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "#hide\n",
- "from your_lib.core import *"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Project name here\n",
- "\n",
- "> Summary description here."
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "This file will become your README and also the index of your documentation."
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Install"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "`pip install your_project_name`"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## How to use"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Fill me in please! Don't forget code examples:"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "2"
- ]
- },
- "execution_count": null,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "1+1"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3",
- "language": "python",
- "name": "python3"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
-}