MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / AutoEncoder

Class AutoEncoder

monai/networks/nets/autoencoder.py:26–306  ·  view source on GitHub ↗

Simple definition of an autoencoder and base class for the architecture implementing :py:class:`monai.networks.nets.VarAutoEncoder`. The network is composed of an encode sequence of blocks, followed by an intermediary sequence of blocks, and finally a decode sequence of blocks. The enco

Source from the content-addressed store, hash-verified

24
25
26class AutoEncoder(nn.Module):
27 """
28 Simple definition of an autoencoder and base class for the architecture implementing
29 :py:class:`monai.networks.nets.VarAutoEncoder`. The network is composed of an encode sequence of blocks, followed
30 by an intermediary sequence of blocks, and finally a decode sequence of blocks. The encode and decode blocks are
31 default :py:class:`monai.networks.blocks.Convolution` instances with the encode blocks having the given stride
32 and the decode blocks having transpose convolutions with the same stride. If `num_res_units` is given residual
33 blocks are used instead.
34
35 By default the intermediary sequence is empty but if `inter_channels` is given to specify the output channels of
36 blocks then this will be become a sequence of Convolution blocks or of residual blocks if `num_inter_units` is
37 given. The optional parameter `inter_dilations` can be used to specify the dilation values of the convolutions in
38 these blocks, this allows a network to use dilated kernels in this middle section. Since the intermediary section
39 isn't meant to change the size of the output the strides for all these kernels is 1.
40
41 Args:
42 spatial_dims: number of spatial dimensions.
43 in_channels: number of input channels.
44 out_channels: number of output channels.
45 channels: sequence of channels. Top block first. The length of `channels` should be no less than 2.
46 strides: sequence of convolution strides. The length of `stride` should equal to `len(channels) - 1`.
47 kernel_size: convolution kernel size, the value(s) should be odd. If sequence,
48 its length should equal to dimensions. Defaults to 3.
49 up_kernel_size: upsampling convolution kernel size, the value(s) should be odd. If sequence,
50 its length should equal to dimensions. Defaults to 3.
51 num_res_units: number of residual units. Defaults to 0.
52 inter_channels: sequence of channels defining the blocks in the intermediate layer between encode and decode.
53 inter_dilations: defines the dilation value for each block of the intermediate layer. Defaults to 1.
54 num_inter_units: number of residual units for each block of the intermediate layer. Defaults to 0.
55 act: activation type and arguments. Defaults to PReLU.
56 norm: feature normalization type and arguments. Defaults to instance norm.
57 dropout: dropout ratio. Defaults to no dropout.
58 bias: whether to have a bias term in convolution blocks. Defaults to True.
59 According to `Performance Tuning Guide <https://pytorch.org/tutorials/recipes/recipes/tuning_guide.html>`_,
60 if a conv layer is directly followed by a batch norm layer, bias should be False.
61 padding: controls the amount of implicit zero-paddings on both sides for padding number of points
62 for each dimension in convolution blocks. Defaults to None.
63
64 Examples::
65
66 from monai.networks.nets import AutoEncoder
67
68 # 3 layers each down/up sampling their inputs by a factor 2 with no intermediate layer
69 net = AutoEncoder(
70 spatial_dims=2,
71 in_channels=1,
72 out_channels=1,
73 channels=(2, 4, 8),
74 strides=(2, 2, 2)
75 )
76
77 # 1 layer downsampling by 2, followed by a sequence of residual units with 2 convolutions defined by
78 # progressively increasing dilations, then final upsample layer
79 net = AutoEncoder(
80 spatial_dims=2,
81 in_channels=1,
82 out_channels=1,
83 channels=(4,),

Callers 4

run_training_testFunction · 0.90
test_shapeMethod · 0.90
test_scriptMethod · 0.90

Calls

no outgoing calls

Tested by 4

run_training_testFunction · 0.72
test_shapeMethod · 0.72
test_scriptMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…