MCPcopy Index your code
hub / github.com/YesianRohn/TextSSR / UNet2DModel

Class UNet2DModel

diffusers/src/diffusers/models/unets/unet_2d.py:40–346  ·  view source on GitHub ↗

r""" A 2D UNet model that takes a noisy sample and a timestep and returns a sample shaped output. This model inherits from [`ModelMixin`]. Check the superclass documentation for it's generic methods implemented for all models (such as downloading or saving). Parameters: sam

Source from the content-addressed store, hash-verified

38
39
40class UNet2DModel(ModelMixin, ConfigMixin):
41 r"""
42 A 2D UNet model that takes a noisy sample and a timestep and returns a sample shaped output.
43
44 This model inherits from [`ModelMixin`]. Check the superclass documentation for it's generic methods implemented
45 for all models (such as downloading or saving).
46
47 Parameters:
48 sample_size (`int` or `Tuple[int, int]`, *optional*, defaults to `None`):
49 Height and width of input/output sample. Dimensions must be a multiple of `2 ** (len(block_out_channels) -
50 1)`.
51 in_channels (`int`, *optional*, defaults to 3): Number of channels in the input sample.
52 out_channels (`int`, *optional*, defaults to 3): Number of channels in the output.
53 center_input_sample (`bool`, *optional*, defaults to `False`): Whether to center the input sample.
54 time_embedding_type (`str`, *optional*, defaults to `"positional"`): Type of time embedding to use.
55 freq_shift (`int`, *optional*, defaults to 0): Frequency shift for Fourier time embedding.
56 flip_sin_to_cos (`bool`, *optional*, defaults to `True`):
57 Whether to flip sin to cos for Fourier time embedding.
58 down_block_types (`Tuple[str]`, *optional*, defaults to `("DownBlock2D", "AttnDownBlock2D", "AttnDownBlock2D", "AttnDownBlock2D")`):
59 Tuple of downsample block types.
60 mid_block_type (`str`, *optional*, defaults to `"UNetMidBlock2D"`):
61 Block type for middle of UNet, it can be either `UNetMidBlock2D` or `UnCLIPUNetMidBlock2D`.
62 up_block_types (`Tuple[str]`, *optional*, defaults to `("AttnUpBlock2D", "AttnUpBlock2D", "AttnUpBlock2D", "UpBlock2D")`):
63 Tuple of upsample block types.
64 block_out_channels (`Tuple[int]`, *optional*, defaults to `(224, 448, 672, 896)`):
65 Tuple of block output channels.
66 layers_per_block (`int`, *optional*, defaults to `2`): The number of layers per block.
67 mid_block_scale_factor (`float`, *optional*, defaults to `1`): The scale factor for the mid block.
68 downsample_padding (`int`, *optional*, defaults to `1`): The padding for the downsample convolution.
69 downsample_type (`str`, *optional*, defaults to `conv`):
70 The downsample type for downsampling layers. Choose between "conv" and "resnet"
71 upsample_type (`str`, *optional*, defaults to `conv`):
72 The upsample type for upsampling layers. Choose between "conv" and "resnet"
73 dropout (`float`, *optional*, defaults to 0.0): The dropout probability to use.
74 act_fn (`str`, *optional*, defaults to `"silu"`): The activation function to use.
75 attention_head_dim (`int`, *optional*, defaults to `8`): The attention head dimension.
76 norm_num_groups (`int`, *optional*, defaults to `32`): The number of groups for normalization.
77 attn_norm_num_groups (`int`, *optional*, defaults to `None`):
78 If set to an integer, a group norm layer will be created in the mid block's [`Attention`] layer with the
79 given number of groups. If left as `None`, the group norm layer will only be created if
80 `resnet_time_scale_shift` is set to `default`, and if created will have `norm_num_groups` groups.
81 norm_eps (`float`, *optional*, defaults to `1e-5`): The epsilon for normalization.
82 resnet_time_scale_shift (`str`, *optional*, defaults to `"default"`): Time scale shift config
83 for ResNet blocks (see [`~models.resnet.ResnetBlock2D`]). Choose from `default` or `scale_shift`.
84 class_embed_type (`str`, *optional*, defaults to `None`):
85 The type of class embedding to use which is ultimately summed with the time embeddings. Choose from `None`,
86 `"timestep"`, or `"identity"`.
87 num_class_embeds (`int`, *optional*, defaults to `None`):
88 Input dimension of the learnable embedding matrix to be projected to `time_embed_dim` when performing class
89 conditioning with `class_embed_type` equal to `None`.
90 """
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,

Calls

no outgoing calls

Tested by 12

get_model_optimizerMethod · 0.72
dummy_uncond_unetMethod · 0.72
dummy_uncond_unetMethod · 0.72
dummy_super_res_firstMethod · 0.72
dummy_super_res_lastMethod · 0.72
dummy_super_res_firstMethod · 0.72
dummy_super_res_lastMethod · 0.72
dummy_uncond_unetMethod · 0.72
dummy_uncond_unetMethod · 0.72
get_dummy_componentsMethod · 0.72