MCPcopy Create free account
hub / github.com/bbaaii/DreamDiffusion / Upsample

Class Upsample

code/dc_ldm/modules/diffusionmodules/openaimodel.py:93–121  ·  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

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