{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Model Layers" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This module contains many layer classes that we might be interested in using in our models. These layers complement the default [Pytorch layers](https://pytorch.org/docs/stable/nn.html) which we can also use as predefined layers." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [], "source": [ "from fastai.vision import *\n", "from fastai.gen_doc.nbdoc import *" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Custom fastai modules" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hide_input": true }, "outputs": [ { "data": { "text/markdown": [ "
class AdaptiveConcatPool2d[source][test]AdaptiveConcatPool2d(**`sz`**:`Optional`\\[`int`\\]=***`None`***) :: [`PrePostInitMeta`](/core.html#PrePostInitMeta) :: [`Module`](/torch_core.html#Module)\n",
"\n",
"No tests found for AdaptiveConcatPool2d. To contribute a test please refer to this guide and this discussion.
| epoch | \n", "train_loss | \n", "valid_loss | \n", "accuracy | \n", "
|---|---|---|---|
| 1 | \n", "0.102758 | \n", "0.064676 | \n", "0.984298 | \n", "
| epoch | \n", "train_loss | \n", "valid_loss | \n", "accuracy | \n", "
|---|---|---|---|
| 1 | \n", "0.241485 | \n", "0.201116 | \n", "0.973994 | \n", "
| epoch | \n", "train_loss | \n", "valid_loss | \n", "accuracy | \n", "
|---|---|---|---|
| 1 | \n", "0.203015 | \n", "0.122094 | \n", "0.988224 | \n", "
class Lambda[source][test]Lambda(**`func`**:`LambdaFunc`) :: [`PrePostInitMeta`](/core.html#PrePostInitMeta) :: [`Module`](/torch_core.html#Module)\n",
"\n",
"No tests found for Lambda. To contribute a test please refer to this guide and this discussion.
class Flatten[source][test]Flatten(**`full`**:`bool`=***`False`***) :: [`PrePostInitMeta`](/core.html#PrePostInitMeta) :: [`Module`](/torch_core.html#Module)\n",
"\n",
"No tests found for Flatten. To contribute a test please refer to this guide and this discussion.
PoolFlatten[source][test]PoolFlatten() → [`Sequential`](https://pytorch.org/docs/stable/nn.html#torch.nn.Sequential)\n",
"\n",
"No tests found for PoolFlatten. To contribute a test please refer to this guide and this discussion.
class ResizeBatch[source][test]ResizeBatch(**\\*`size`**:`int`) :: [`PrePostInitMeta`](/core.html#PrePostInitMeta) :: [`Module`](/torch_core.html#Module)\n",
"\n",
"No tests found for ResizeBatch. To contribute a test please refer to this guide and this discussion.
class Debugger[source][test]Debugger() :: [`PrePostInitMeta`](/core.html#PrePostInitMeta) :: [`Module`](/torch_core.html#Module)\n",
"\n",
"No tests found for Debugger. To contribute a test please refer to this guide and this discussion.
class PixelShuffle_ICNR[source][test]PixelShuffle_ICNR(**`ni`**:`int`, **`nf`**:`int`=***`None`***, **`scale`**:`int`=***`2`***, **`blur`**:`bool`=***`False`***, **`norm_type`**=***`No tests found for PixelShuffle_ICNR. To contribute a test please refer to this guide and this discussion.
class MergeLayer[source][test]MergeLayer(**`dense`**:`bool`=***`False`***) :: [`PrePostInitMeta`](/core.html#PrePostInitMeta) :: [`Module`](/torch_core.html#Module)\n",
"\n",
"No tests found for MergeLayer. To contribute a test please refer to this guide and this discussion.
class PartialLayer[source][test]PartialLayer(**`func`**, **\\*\\*`kwargs`**) :: [`PrePostInitMeta`](/core.html#PrePostInitMeta) :: [`Module`](/torch_core.html#Module)\n",
"\n",
"No tests found for PartialLayer. To contribute a test please refer to this guide and this discussion.
class SigmoidRange[source][test]SigmoidRange(**`low`**, **`high`**) :: [`PrePostInitMeta`](/core.html#PrePostInitMeta) :: [`Module`](/torch_core.html#Module)\n",
"\n",
"No tests found for SigmoidRange. To contribute a test please refer to this guide and this discussion.
class SequentialEx[source][test]SequentialEx(**\\*`layers`**) :: [`PrePostInitMeta`](/core.html#PrePostInitMeta) :: [`Module`](/torch_core.html#Module)\n",
"\n",
"No tests found for SequentialEx. To contribute a test please refer to this guide and this discussion.
class SelfAttention[source][test]SelfAttention(**`n_channels`**:`int`) :: [`PrePostInitMeta`](/core.html#PrePostInitMeta) :: [`Module`](/torch_core.html#Module)\n",
"\n",
"class BatchNorm1dFlat[source][test]BatchNorm1dFlat(**`num_features`**, **`eps`**=***`1e-05`***, **`momentum`**=***`0.1`***, **`affine`**=***`True`***, **`track_running_stats`**=***`True`***) :: [`BatchNorm1d`](https://pytorch.org/docs/stable/nn.html#torch.nn.BatchNorm1d)\n",
"\n",
"No tests found for BatchNorm1dFlat. To contribute a test please refer to this guide and this discussion.
class FlattenedLoss[source][test]FlattenedLoss(**`func`**, **\\*`args`**, **`axis`**:`int`=***`-1`***, **`floatify`**:`bool`=***`False`***, **`is_2d`**:`bool`=***`True`***, **\\*\\*`kwargs`**)\n",
"\n",
"No tests found for FlattenedLoss. To contribute a test please refer to this guide and this discussion.
BCEFlat[source][test]BCEFlat(**\\*`args`**, **`axis`**:`int`=***`-1`***, **`floatify`**:`bool`=***`True`***, **\\*\\*`kwargs`**)\n",
"\n",
"No tests found for BCEFlat. To contribute a test please refer to this guide and this discussion.
BCEWithLogitsFlat[source][test]BCEWithLogitsFlat(**\\*`args`**, **`axis`**:`int`=***`-1`***, **`floatify`**:`bool`=***`True`***, **\\*\\*`kwargs`**)\n",
"\n",
"No tests found for BCEWithLogitsFlat. To contribute a test please refer to this guide and this discussion.
CrossEntropyFlat[source][test]CrossEntropyFlat(**\\*`args`**, **`axis`**:`int`=***`-1`***, **\\*\\*`kwargs`**)\n",
"\n",
"No tests found for CrossEntropyFlat. To contribute a test please refer to this guide and this discussion.
MSELossFlat[source][test]MSELossFlat(**\\*`args`**, **`axis`**:`int`=***`-1`***, **`floatify`**:`bool`=***`True`***, **\\*\\*`kwargs`**)\n",
"\n",
"No tests found for MSELossFlat. To contribute a test please refer to this guide and this discussion.
class NoopLoss[source][test]NoopLoss() :: [`PrePostInitMeta`](/core.html#PrePostInitMeta) :: [`Module`](/torch_core.html#Module)\n",
"\n",
"No tests found for NoopLoss. To contribute a test please refer to this guide and this discussion.
class WassersteinLoss[source][test]WassersteinLoss() :: [`PrePostInitMeta`](/core.html#PrePostInitMeta) :: [`Module`](/torch_core.html#Module)\n",
"\n",
"No tests found for WassersteinLoss. To contribute a test please refer to this guide and this discussion.
bn_drop_lin[source][test]bn_drop_lin(**`n_in`**:`int`, **`n_out`**:`int`, **`bn`**:`bool`=***`True`***, **`p`**:`float`=***`0.0`***, **`actn`**:`Optional`\\[[`Module`](https://pytorch.org/docs/stable/nn.html#torch.nn.Module)\\]=***`None`***)\n",
"\n",
"No tests found for bn_drop_lin. To contribute a test please refer to this guide and this discussion.
conv2d[source][test]conv2d(**`ni`**:`int`, **`nf`**:`int`, **`ks`**:`int`=***`3`***, **`stride`**:`int`=***`1`***, **`padding`**:`int`=***`None`***, **`bias`**=***`False`***, **`init`**:`LayerFunc`=***`'kaiming_normal_'`***) → [`Conv2d`](https://pytorch.org/docs/stable/nn.html#torch.nn.Conv2d)\n",
"\n",
"No tests found for conv2d. To contribute a test please refer to this guide and this discussion.
conv2d_trans[source][test]conv2d_trans(**`ni`**:`int`, **`nf`**:`int`, **`ks`**:`int`=***`2`***, **`stride`**:`int`=***`2`***, **`padding`**:`int`=***`0`***, **`bias`**=***`False`***) → [`ConvTranspose2d`](https://pytorch.org/docs/stable/nn.html#torch.nn.ConvTranspose2d)\n",
"\n",
"No tests found for conv2d_trans. To contribute a test please refer to this guide and this discussion.
conv_layer[source][test]conv_layer(**`ni`**:`int`, **`nf`**:`int`, **`ks`**:`int`=***`3`***, **`stride`**:`int`=***`1`***, **`padding`**:`int`=***`None`***, **`bias`**:`bool`=***`None`***, **`is_1d`**:`bool`=***`False`***, **`norm_type`**:`Optional`\\[[`NormType`](/layers.html#NormType)\\]=***`No tests found for conv_layer. To contribute a test please refer to this guide and this discussion.
embedding[source][test]embedding(**`ni`**:`int`, **`nf`**:`int`) → [`Module`](https://pytorch.org/docs/stable/nn.html#torch.nn.Module)\n",
"\n",
"No tests found for embedding. To contribute a test please refer to this guide and this discussion.
relu[source][test]relu(**`inplace`**:`bool`=***`False`***, **`leaky`**:`float`=***`None`***)\n",
"\n",
"No tests found for relu. To contribute a test please refer to this guide and this discussion.
res_block[source][test]res_block(**`nf`**, **`dense`**:`bool`=***`False`***, **`norm_type`**:`Optional`\\[[`NormType`](/layers.html#NormType)\\]=***`No tests found for res_block. To contribute a test please refer to this guide and this discussion.
sigmoid_range[source][test]sigmoid_range(**`x`**, **`low`**, **`high`**)\n",
"\n",
"No tests found for sigmoid_range. To contribute a test please refer to this guide and this discussion.
simple_cnn[source][test]simple_cnn(**`actns`**:`Collection`\\[`int`\\], **`kernel_szs`**:`Collection`\\[`int`\\]=***`None`***, **`strides`**:`Collection`\\[`int`\\]=***`None`***, **`bn`**=***`False`***) → [`Sequential`](https://pytorch.org/docs/stable/nn.html#torch.nn.Sequential)\n",
"\n",
"No tests found for simple_cnn. To contribute a test please refer to this guide and this discussion.
batchnorm_2d[source][test]batchnorm_2d(**`nf`**:`int`, **`norm_type`**:[`NormType`](/layers.html#NormType)=***`No tests found for batchnorm_2d. To contribute a test please refer to this guide and this discussion.
icnr[source][test]icnr(**`x`**, **`scale`**=***`2`***, **`init`**=***`'kaiming_normal_'`***)\n",
"\n",
"No tests found for icnr. To contribute a test please refer to this guide and this discussion.
trunc_normal_[source][test]trunc_normal_(**`x`**:`Tensor`, **`mean`**:`float`=***`0.0`***, **`std`**:`float`=***`1.0`***) → `Tensor`\n",
"\n",
"No tests found for trunc_normal_. To contribute a test please refer to this guide and this discussion.
icnr[source][test]icnr(**`x`**, **`scale`**=***`2`***, **`init`**=***`'kaiming_normal_'`***)\n",
"\n",
"No tests found for icnr. To contribute a test please refer to this guide and this discussion.
Enum = [Batch, BatchZero, Weight, Spectral]\n",
"\n",
"No tests found for NormType. To contribute a test please refer to this guide and this discussion.
forward[source][test]forward(**`x`**:`Tensor`) → `Tensor`\n",
"\n",
"No tests found for forward. To contribute a test please refer to this guide and this discussion.
forward[source][test]forward(**`x`**)\n",
"\n",
"No tests found for forward. To contribute a test please refer to this guide and this discussion.
forward[source][test]forward(**`x`**)\n",
"\n",
"No tests found for forward. To contribute a test please refer to this guide and this discussion.
forward[source][test]forward(**`output`**, **\\*`args`**)\n",
"\n",
"No tests found for forward. To contribute a test please refer to this guide and this discussion.
forward[source][test]forward(**`x`**)\n",
"\n",
"No tests found for forward. To contribute a test please refer to this guide and this discussion.
forward[source][test]forward(**`real`**, **`fake`**)\n",
"\n",
"No tests found for forward. To contribute a test please refer to this guide and this discussion.
forward[source][test]forward(**`x`**)\n",
"\n",
"No tests found for forward. To contribute a test please refer to this guide and this discussion.
forward[source][test]forward(**`x`**)\n",
"\n",
"No tests found for forward. To contribute a test please refer to this guide and this discussion.
forward[source][test]forward(**`x`**)\n",
"\n",
"No tests found for forward. To contribute a test please refer to this guide and this discussion.
forward[source][test]forward(**`x`**)\n",
"\n",
"No tests found for forward. To contribute a test please refer to this guide and this discussion.
forward[source][test]forward(**`x`**)\n",
"\n",
"No tests found for forward. To contribute a test please refer to this guide and this discussion.
append[source][test]append(**`l`**)\n",
"\n",
"No tests found for append. To contribute a test please refer to this guide and this discussion.
extend[source][test]extend(**`l`**)\n",
"\n",
"No tests found for extend. To contribute a test please refer to this guide and this discussion.
insert[source][test]insert(**`i`**, **`l`**)\n",
"\n",
"No tests found for insert. To contribute a test please refer to this guide and this discussion.
forward[source][test]forward(**`x`**)\n",
"\n",
"No tests found for forward. To contribute a test please refer to this guide and this discussion.
forward[source][test]forward(**`x`**)\n",
"\n",
"No tests found for forward. To contribute a test please refer to this guide and this discussion.
forward[source][test]forward(**`x`**)\n",
"\n",
"No tests found for forward. To contribute a test please refer to this guide and this discussion.
class View[source][test]View(**\\*`size`**:`int`) :: [`PrePostInitMeta`](/core.html#PrePostInitMeta) :: [`Module`](/torch_core.html#Module)\n",
"\n",
"No tests found for View. To contribute a test please refer to this guide and this discussion.
forward[source][test]forward(**`x`**)\n",
"\n",
"No tests found for forward. To contribute a test please refer to this guide and this discussion.
forward[source][test]forward(**`x`**)\n",
"\n",
"No tests found for forward. To contribute a test please refer to this guide and this discussion.