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

Method __init__

diffusers/src/diffusers/models/resnet.py:74–147  ·  view source on GitHub ↗
(
        self,
        *,
        in_channels: int,
        out_channels: Optional[int] = None,
        conv_shortcut: bool = False,
        dropout: float = 0.0,
        temb_channels: int = 512,
        groups: int = 32,
        groups_out: Optional[int] = None,
        eps: float = 1e-6,
        non_linearity: str = "swish",
        time_embedding_norm: str = "ada_group",  # ada_group, spatial
        output_scale_factor: float = 1.0,
        use_in_shortcut: Optional[bool] = None,
        up: bool = False,
        down: bool = False,
        conv_shortcut_bias: bool = True,
        conv_2d_out_channels: Optional[int] = None,
    )

Source from the content-addressed store, hash-verified

72 """
73
74 def __init__(
75 self,
76 *,
77 in_channels: int,
78 out_channels: Optional[int] = None,
79 conv_shortcut: bool = False,
80 dropout: float = 0.0,
81 temb_channels: int = 512,
82 groups: int = 32,
83 groups_out: Optional[int] = None,
84 eps: float = 1e-6,
85 non_linearity: str = "swish",
86 time_embedding_norm: str = "ada_group", # ada_group, spatial
87 output_scale_factor: float = 1.0,
88 use_in_shortcut: Optional[bool] = None,
89 up: bool = False,
90 down: bool = False,
91 conv_shortcut_bias: bool = True,
92 conv_2d_out_channels: Optional[int] = None,
93 ):
94 super().__init__()
95 self.in_channels = in_channels
96 out_channels = in_channels if out_channels is None else out_channels
97 self.out_channels = out_channels
98 self.use_conv_shortcut = conv_shortcut
99 self.up = up
100 self.down = down
101 self.output_scale_factor = output_scale_factor
102 self.time_embedding_norm = time_embedding_norm
103
104 if groups_out is None:
105 groups_out = groups
106
107 if self.time_embedding_norm == "ada_group": # ada_group
108 self.norm1 = AdaGroupNorm(temb_channels, in_channels, groups, eps=eps)
109 elif self.time_embedding_norm == "spatial":
110 self.norm1 = SpatialNorm(in_channels, temb_channels)
111 else:
112 raise ValueError(f" unsupported time_embedding_norm: {self.time_embedding_norm}")
113
114 self.conv1 = nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=1, padding=1)
115
116 if self.time_embedding_norm == "ada_group": # ada_group
117 self.norm2 = AdaGroupNorm(temb_channels, out_channels, groups_out, eps=eps)
118 elif self.time_embedding_norm == "spatial": # spatial
119 self.norm2 = SpatialNorm(out_channels, temb_channels)
120 else:
121 raise ValueError(f" unsupported time_embedding_norm: {self.time_embedding_norm}")
122
123 self.dropout = torch.nn.Dropout(dropout)
124
125 conv_2d_out_channels = conv_2d_out_channels or out_channels
126 self.conv2 = nn.Conv2d(out_channels, conv_2d_out_channels, kernel_size=3, stride=1, padding=1)
127
128 self.nonlinearity = get_activation(non_linearity)
129
130 self.upsample = self.downsample = None
131 if self.up:

Callers

nothing calls this directly

Calls 6

AdaGroupNormClass · 0.85
SpatialNormClass · 0.85
get_activationFunction · 0.85
Upsample2DClass · 0.85
Downsample2DClass · 0.85
__init__Method · 0.45

Tested by

no test coverage detected