MCPcopy Create free account
hub / github.com/CompVis/diff2flow / Upsample

Class Upsample

diff2flow/models/unet/openaimodel.py:94–122  ·  view source on GitHub ↗

An upsampling layer with an optional convolution. :param channels: channels in the inputs and outputs. :param use_conv: a bool determining if a convolution is applied. :param dims: determines if the signal is 1D, 2D, or 3D. If 3D, then upsampling occurs in the inner

Source from the content-addressed store, hash-verified

92
93
94class Upsample(nn.Module):
95 """
96 An upsampling layer with an optional convolution.
97 :param channels: channels in the inputs and outputs.
98 :param use_conv: a bool determining if a convolution is applied.
99 :param dims: determines if the signal is 1D, 2D, or 3D. If 3D, then
100 upsampling occurs in the inner-two dimensions.
101 """
102
103 def __init__(self, channels, use_conv, dims=2, out_channels=None, padding=1):
104 super().__init__()
105 self.channels = channels
106 self.out_channels = out_channels or channels
107 self.use_conv = use_conv
108 self.dims = dims
109 if use_conv:
110 self.conv = conv_nd(dims, self.channels, self.out_channels, 3, padding=padding)
111
112 def forward(self, x):
113 assert x.shape[1] == self.channels
114 if self.dims == 3:
115 x = F.interpolate(
116 x, (x.shape[2], x.shape[3] * 2, x.shape[4] * 2), mode="nearest"
117 )
118 else:
119 x = F.interpolate(x, scale_factor=2, mode="nearest")
120 if self.use_conv:
121 x = self.conv(x)
122 return x
123
124class TransposedUpsample(nn.Module):
125 'Learned 2x upsampling without padding'

Callers 2

__init__Method · 0.70
__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected