| 60 | return out |
| 61 | |
| 62 | def base_conv2d(x, conv_layer, channel_last=False, residual=None): |
| 63 | if channel_last: |
| 64 | x = x.permute(0, 3, 1, 2) # NHWC to NCHW |
| 65 | out = F.conv2d(x, conv_layer.weight, conv_layer.bias, stride=conv_layer.stride, padding=conv_layer.padding) |
| 66 | if residual is not None: |
| 67 | if channel_last: |
| 68 | residual = residual.permute(0, 3, 1, 2) # NHWC to NCHW |
| 69 | out += residual |
| 70 | if channel_last: |
| 71 | out = out.permute(0, 2, 3, 1) # NCHW to NHWC |
| 72 | return out |
| 73 | |
| 74 | def base_conv3d(x, conv_layer, channel_last=False, residual=None, only_return_output=False): |
| 75 | if only_return_output: |