Applies a 3D deconvolution (optionally with batch normalization and relu activation) over an input signal composed of several input planes. Attributes: conv (nn.Module): convolution module bn (nn.Module): batch normalization module relu (bool): whether
| 164 | |
| 165 | |
| 166 | class Deconv3d(nn.Module): |
| 167 | """Applies a 3D deconvolution (optionally with batch normalization and relu activation) |
| 168 | over an input signal composed of several input planes. |
| 169 | |
| 170 | Attributes: |
| 171 | conv (nn.Module): convolution module |
| 172 | bn (nn.Module): batch normalization module |
| 173 | relu (bool): whether to activate by relu |
| 174 | |
| 175 | Notes: |
| 176 | Default momentum for batch normalization is set to be 0.01, |
| 177 | |
| 178 | """ |
| 179 | |
| 180 | def __init__(self, in_channels, out_channels, kernel_size=3, stride=1, |
| 181 | relu=True, bn=True, bn_momentum=0.1, init_method="xavier", **kwargs): |
| 182 | super(Deconv3d, self).__init__() |
| 183 | self.out_channels = out_channels |
| 184 | assert stride in [1, 2] |
| 185 | self.stride = stride |
| 186 | |
| 187 | self.conv = nn.ConvTranspose3d(in_channels, out_channels, kernel_size, stride=stride, |
| 188 | bias=(not bn), **kwargs) |
| 189 | self.bn = nn.BatchNorm3d(out_channels, momentum=bn_momentum) if bn else None |
| 190 | # self.bn = nn.GroupNorm(8, out_channels) if bn else None |
| 191 | self.relu = relu |
| 192 | |
| 193 | # assert init_method in ["kaiming", "xavier"] |
| 194 | # self.init_weights(init_method) |
| 195 | |
| 196 | def forward(self, x): |
| 197 | y = self.conv(x) |
| 198 | if self.bn is not None: |
| 199 | x = self.bn(y) |
| 200 | if self.relu: |
| 201 | x = F.relu(x, inplace=True) |
| 202 | return x |
| 203 | |
| 204 | def init_weights(self, init_method): |
| 205 | """default initialization""" |
| 206 | init_uniform(self.conv, init_method) |
| 207 | if self.bn is not None: |
| 208 | init_bn(self.bn) |
| 209 | |
| 210 | |
| 211 |