MCPcopy Index your code
hub / github.com/VisionXLab/OF-Diff / Upsample

Class Upsample

ldm/modules/diffusionmodules/openaimodel.py:92–120  ·  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

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