MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / Upsample

Class Upsample

sat/sgm/modules/diffusionmodules/openaimodel.py:119–151  ·  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

117
118
119class Upsample(nn.Module):
120 """
121 An upsampling layer with an optional convolution.
122 :param channels: channels in the inputs and outputs.
123 :param use_conv: a bool determining if a convolution is applied.
124 :param dims: determines if the signal is 1D, 2D, or 3D. If 3D, then
125 upsampling occurs in the inner-two dimensions.
126 """
127
128 def __init__(self, channels, use_conv, dims=2, out_channels=None, padding=1, third_up=False):
129 super().__init__()
130 self.channels = channels
131 self.out_channels = out_channels or channels
132 self.use_conv = use_conv
133 self.dims = dims
134 self.third_up = third_up
135 if use_conv:
136 self.conv = conv_nd(dims, self.channels, self.out_channels, 3, padding=padding)
137
138 def forward(self, x):
139 assert x.shape[1] == self.channels
140 if self.dims == 3:
141 t_factor = 1 if not self.third_up else 2
142 x = F.interpolate(
143 x,
144 (t_factor * x.shape[2], x.shape[3] * 2, x.shape[4] * 2),
145 mode="nearest",
146 )
147 else:
148 x = F.interpolate(x, scale_factor=2, mode="nearest")
149 if self.use_conv:
150 x = self.conv(x)
151 return x
152
153
154class TransposedUpsample(nn.Module):

Callers 2

__init__Method · 0.70
__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected