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

Method __init__

diffusers/src/diffusers/models/unets/unet_2d.py:93–241  ·  view source on GitHub ↗
(
        self,
        sample_size: Optional[Union[int, Tuple[int, int]]] = None,
        in_channels: int = 3,
        out_channels: int = 3,
        center_input_sample: bool = False,
        time_embedding_type: str = "positional",
        freq_shift: int = 0,
        flip_sin_to_cos: bool = True,
        down_block_types: Tuple[str, ...] = ("DownBlock2D", "AttnDownBlock2D", "AttnDownBlock2D", "AttnDownBlock2D"),
        up_block_types: Tuple[str, ...] = ("AttnUpBlock2D", "AttnUpBlock2D", "AttnUpBlock2D", "UpBlock2D"),
        block_out_channels: Tuple[int, ...] = (224, 448, 672, 896),
        layers_per_block: int = 2,
        mid_block_scale_factor: float = 1,
        downsample_padding: int = 1,
        downsample_type: str = "conv",
        upsample_type: str = "conv",
        dropout: float = 0.0,
        act_fn: str = "silu",
        attention_head_dim: Optional[int] = 8,
        norm_num_groups: int = 32,
        attn_norm_num_groups: Optional[int] = None,
        norm_eps: float = 1e-5,
        resnet_time_scale_shift: str = "default",
        add_attention: bool = True,
        class_embed_type: Optional[str] = None,
        num_class_embeds: Optional[int] = None,
        num_train_timesteps: Optional[int] = None,
    )

Source from the content-addressed store, hash-verified

91
92 @register_to_config
93 def __init__(
94 self,
95 sample_size: Optional[Union[int, Tuple[int, int]]] = None,
96 in_channels: int = 3,
97 out_channels: int = 3,
98 center_input_sample: bool = False,
99 time_embedding_type: str = "positional",
100 freq_shift: int = 0,
101 flip_sin_to_cos: bool = True,
102 down_block_types: Tuple[str, ...] = ("DownBlock2D", "AttnDownBlock2D", "AttnDownBlock2D", "AttnDownBlock2D"),
103 up_block_types: Tuple[str, ...] = ("AttnUpBlock2D", "AttnUpBlock2D", "AttnUpBlock2D", "UpBlock2D"),
104 block_out_channels: Tuple[int, ...] = (224, 448, 672, 896),
105 layers_per_block: int = 2,
106 mid_block_scale_factor: float = 1,
107 downsample_padding: int = 1,
108 downsample_type: str = "conv",
109 upsample_type: str = "conv",
110 dropout: float = 0.0,
111 act_fn: str = "silu",
112 attention_head_dim: Optional[int] = 8,
113 norm_num_groups: int = 32,
114 attn_norm_num_groups: Optional[int] = None,
115 norm_eps: float = 1e-5,
116 resnet_time_scale_shift: str = "default",
117 add_attention: bool = True,
118 class_embed_type: Optional[str] = None,
119 num_class_embeds: Optional[int] = None,
120 num_train_timesteps: Optional[int] = None,
121 ):
122 super().__init__()
123
124 self.sample_size = sample_size
125 time_embed_dim = block_out_channels[0] * 4
126
127 # Check inputs
128 if len(down_block_types) != len(up_block_types):
129 raise ValueError(
130 f"Must provide the same number of `down_block_types` as `up_block_types`. `down_block_types`: {down_block_types}. `up_block_types`: {up_block_types}."
131 )
132
133 if len(block_out_channels) != len(down_block_types):
134 raise ValueError(
135 f"Must provide the same number of `block_out_channels` as `down_block_types`. `block_out_channels`: {block_out_channels}. `down_block_types`: {down_block_types}."
136 )
137
138 # input
139 self.conv_in = nn.Conv2d(in_channels, block_out_channels[0], kernel_size=3, padding=(1, 1))
140
141 # time
142 if time_embedding_type == "fourier":
143 self.time_proj = GaussianFourierProjection(embedding_size=block_out_channels[0], scale=16)
144 timestep_input_dim = 2 * block_out_channels[0]
145 elif time_embedding_type == "positional":
146 self.time_proj = Timesteps(block_out_channels[0], flip_sin_to_cos, freq_shift)
147 timestep_input_dim = block_out_channels[0]
148 elif time_embedding_type == "learned":
149 self.time_proj = nn.Embedding(num_train_timesteps, block_out_channels[0])
150 timestep_input_dim = block_out_channels[0]

Callers

nothing calls this directly

Calls 6

TimestepsClass · 0.85
TimestepEmbeddingClass · 0.85
UNetMidBlock2DClass · 0.85
get_down_blockFunction · 0.70
get_up_blockFunction · 0.70

Tested by

no test coverage detected