MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / Upsample2D

Class Upsample2D

diffusers/src/diffusers/models/upsampling.py:76–184  ·  view source on GitHub ↗

A 2D upsampling layer with an optional convolution. Parameters: channels (`int`): number of channels in the inputs and outputs. use_conv (`bool`, default `False`): option to use a convolution. use_conv_transpose (`bool`, default `False`):

Source from the content-addressed store, hash-verified

74
75
76class Upsample2D(nn.Module):
77 """A 2D upsampling layer with an optional convolution.
78
79 Parameters:
80 channels (`int`):
81 number of channels in the inputs and outputs.
82 use_conv (`bool`, default `False`):
83 option to use a convolution.
84 use_conv_transpose (`bool`, default `False`):
85 option to use a convolution transpose.
86 out_channels (`int`, optional):
87 number of output channels. Defaults to `channels`.
88 name (`str`, default `conv`):
89 name of the upsampling 2D layer.
90 """
91
92 def __init__(
93 self,
94 channels: int,
95 use_conv: bool = False,
96 use_conv_transpose: bool = False,
97 out_channels: Optional[int] = None,
98 name: str = "conv",
99 kernel_size: Optional[int] = None,
100 padding=1,
101 norm_type=None,
102 eps=None,
103 elementwise_affine=None,
104 bias=True,
105 interpolate=True,
106 ):
107 super().__init__()
108 self.channels = channels
109 self.out_channels = out_channels or channels
110 self.use_conv = use_conv
111 self.use_conv_transpose = use_conv_transpose
112 self.name = name
113 self.interpolate = interpolate
114
115 if norm_type == "ln_norm":
116 self.norm = nn.LayerNorm(channels, eps, elementwise_affine)
117 elif norm_type == "rms_norm":
118 self.norm = RMSNorm(channels, eps, elementwise_affine)
119 elif norm_type is None:
120 self.norm = None
121 else:
122 raise ValueError(f"unknown norm_type: {norm_type}")
123
124 conv = None
125 if use_conv_transpose:
126 if kernel_size is None:
127 kernel_size = 4
128 conv = nn.ConvTranspose2d(
129 channels, self.out_channels, kernel_size=kernel_size, stride=2, padding=padding, bias=bias
130 )
131 elif use_conv:
132 if kernel_size is None:
133 kernel_size = 3

Callers 15

__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls