MCPcopy Create free account
hub / github.com/TencentARC/BrushNet / Upsample2D

Class Upsample2D

src/diffusers/models/upsampling.py:76–193  ·  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 conv_cls = nn.Conv2d if USE_PEFT_BACKEND else LoRACompatibleConv
115
116 if norm_type == "ln_norm":
117 self.norm = nn.LayerNorm(channels, eps, elementwise_affine)
118 elif norm_type == "rms_norm":
119 self.norm = RMSNorm(channels, eps, elementwise_affine)
120 elif norm_type is None:
121 self.norm = None
122 else:
123 raise ValueError(f"unknown norm_type: {norm_type}")
124
125 conv = None
126 if use_conv_transpose:
127 if kernel_size is None:
128 kernel_size = 4
129 conv = nn.ConvTranspose2d(
130 channels, self.out_channels, kernel_size=kernel_size, stride=2, padding=padding, bias=bias
131 )
132 elif use_conv:
133 if kernel_size is None:

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