UNet2DModel¶
The UNet model was originally introduced by Ronneberger et al. for biomedical image segmentation, but it is also commonly used in 🤗 Diffusers because it outputs images that are the same size as the input. It is one of the most important components of a diffusion system because it facilitates the actual diffusion process. There are several variants of the UNet model in 🤗 Diffusers, depending on it's number of dimensions and whether it is a conditional model or not. This is a 2D UNet model.
The abstract from the paper is:
There is large consent that successful training of deep networks requires many thousand annotated training samples. In this paper, we present a network and training strategy that relies on the strong use of data augmentation to use the available annotated samples more efficiently. The architecture consists of a contracting path to capture context and a symmetric expanding path that enables precise localization. We show that such a network can be trained end-to-end from very few images and outperforms the prior best method (a sliding-window convolutional network) on the ISBI challenge for segmentation of neuronal structures in electron microscopic stacks. Using the same network trained on transmitted light microscopy images (phase contrast and DIC) we won the ISBI cell tracking challenge 2015 in these categories by a large margin. Moreover, the network is fast. Segmentation of a 512x512 image takes less than a second on a recent GPU. The full implementation (based on Caffe) and the trained networks are available at http://lmb.informatik.uni-freiburg.de/people/ronneber/u-net.
mindone.diffusers.UNet2DModel
¶
Bases: ModelMixin
, ConfigMixin
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).
PARAMETER | DESCRIPTION |
---|---|
sample_size |
Height and width of input/output sample. Dimensions must be a multiple of
TYPE:
|
in_channels |
Number of channels in the input sample.
TYPE:
|
out_channels |
Number of channels in the output.
TYPE:
|
center_input_sample |
Whether to center the input sample.
TYPE:
|
time_embedding_type |
Type of time embedding to use.
TYPE:
|
freq_shift |
Frequency shift for Fourier time embedding.
TYPE:
|
flip_sin_to_cos |
Whether to flip sin to cos for Fourier time embedding.
TYPE:
|
down_block_types |
Tuple of downsample block types.
TYPE:
|
mid_block_type |
Block type for middle of UNet, it can be either
TYPE:
|
up_block_types |
Tuple of upsample block types.
TYPE:
|
block_out_channels |
Tuple of block output channels.
TYPE:
|
layers_per_block |
The number of layers per block.
TYPE:
|
mid_block_scale_factor |
The scale factor for the mid block.
TYPE:
|
downsample_padding |
The padding for the downsample convolution.
TYPE:
|
downsample_type |
The downsample type for downsampling layers. Choose between "conv" and "resnet"
TYPE:
|
upsample_type |
The upsample type for upsampling layers. Choose between "conv" and "resnet"
TYPE:
|
dropout |
The dropout probability to use.
TYPE:
|
act_fn |
The activation function to use.
TYPE:
|
attention_head_dim |
The attention head dimension.
TYPE:
|
norm_num_groups |
The number of groups for normalization.
TYPE:
|
attn_norm_num_groups |
If set to an integer, a group norm layer will be created in the mid block's [
TYPE:
|
norm_eps |
The epsilon for normalization.
TYPE:
|
resnet_time_scale_shift |
Time scale shift config
for ResNet blocks (see [
TYPE:
|
class_embed_type |
The type of class embedding to use which is ultimately summed with the time embeddings. Choose from
TYPE:
|
num_class_embeds |
Input dimension of the learnable embedding matrix to be projected to
TYPE:
|
Source code in mindone/diffusers/models/unets/unet_2d.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
|
mindone.diffusers.UNet2DModel.construct(sample, timestep, class_labels=None, return_dict=False)
¶
The [UNet2DModel
] forward method.
PARAMETER | DESCRIPTION |
---|---|
sample |
The noisy input tensor with the following shape
TYPE:
|
timestep |
The number of timesteps to denoise an input.
TYPE:
|
class_labels |
Optional class labels for conditioning. Their embeddings will be summed with the timestep embeddings.
TYPE:
|
return_dict |
Whether or not to return a [
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[UNet2DOutput, Tuple]
|
[ |
Source code in mindone/diffusers/models/unets/unet_2d.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
|
mindone.diffusers.models.unets.unet_2d.UNet2DOutput
dataclass
¶
Bases: BaseOutput
The output of [UNet2DModel
].
PARAMETER | DESCRIPTION |
---|---|
sample |
The hidden states output from the last layer of the model.
TYPE:
|
Source code in mindone/diffusers/models/unets/unet_2d.py
29 30 31 32 33 34 35 36 37 38 39 |
|