UNet3DConditionModel¶
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 3D UNet conditional 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.UNet3DConditionModel
¶
Bases: ModelMixin
, ConfigMixin
, UNet2DConditionLoadersMixin
A conditional 3D UNet model that takes a noisy sample, conditional state, 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.
TYPE:
|
in_channels |
The number of channels in the input sample.
TYPE:
|
out_channels |
The number of channels in the output.
TYPE:
|
down_block_types |
The tuple of downsample blocks to use.
TYPE:
|
up_block_types |
The tuple of upsample blocks to use.
TYPE:
|
block_out_channels |
The tuple of output channels for each block.
TYPE:
|
layers_per_block |
The number of layers per block.
TYPE:
|
downsample_padding |
The padding to use for the downsampling convolution.
TYPE:
|
mid_block_scale_factor |
The scale factor to use for the mid block.
TYPE:
|
act_fn |
The activation function to use.
TYPE:
|
norm_num_groups |
The number of groups to use for the normalization.
If
TYPE:
|
norm_eps |
The epsilon to use for the normalization.
TYPE:
|
cross_attention_dim |
The dimension of the cross attention features.
TYPE:
|
attention_head_dim |
The dimension of the attention heads.
TYPE:
|
num_attention_heads |
The number of attention heads.
TYPE:
|
time_cond_proj_dim |
The dimension of
TYPE:
|
Source code in mindone/diffusers/models/unets/unet_3d_condition.py
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 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 |
|
mindone.diffusers.UNet3DConditionModel.attn_processors: Dict[str, AttentionProcessor]
property
¶
RETURNS | DESCRIPTION |
---|---|
Dict[str, AttentionProcessor]
|
|
Dict[str, AttentionProcessor]
|
indexed by its weight name. |
mindone.diffusers.UNet3DConditionModel.construct(sample, timestep, encoder_hidden_states, class_labels=None, timestep_cond=None, attention_mask=None, cross_attention_kwargs=None, down_block_additional_residuals=None, mid_block_additional_residual=None, return_dict=False)
¶
The [UNet3DConditionModel
] forward method.
PARAMETER | DESCRIPTION |
---|---|
sample |
The noisy input tensor with the following shape
TYPE:
|
timestep |
The number of timesteps to denoise an input.
TYPE:
|
encoder_hidden_states |
The encoder hidden states with shape
TYPE:
|
class_labels |
Optional class labels for conditioning. Their embeddings will be summed with the timestep embeddings.
TYPE:
|
timestep_cond |
(
TYPE:
|
attention_mask |
An attention mask of shape
TYPE:
|
cross_attention_kwargs |
A kwargs dictionary that if specified is passed along to the
TYPE:
|
down_block_additional_residuals |
(
TYPE:
|
mid_block_additional_residual |
(
TYPE:
|
return_dict |
Whether or not to return a [
TYPE:
|
cross_attention_kwargs |
A kwargs dictionary that if specified is passed along to the [
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[UNet3DConditionOutput, Tuple[Tensor]]
|
[ |
Source code in mindone/diffusers/models/unets/unet_3d_condition.py
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 |
|
mindone.diffusers.UNet3DConditionModel.enable_forward_chunking(chunk_size=None, dim=0)
¶
Sets the attention processor to use feed forward chunking.
PARAMETER | DESCRIPTION |
---|---|
chunk_size |
The chunk size of the feed-forward layers. If not specified, will run feed-forward layer individually
over each tensor of dim=
TYPE:
|
dim |
The dimension over which the feed-forward computation should be chunked. Choose between dim=0 (batch) or dim=1 (sequence length).
TYPE:
|
Source code in mindone/diffusers/models/unets/unet_3d_condition.py
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
|
mindone.diffusers.UNet3DConditionModel.set_attn_processor(processor)
¶
Sets the attention processor to use to compute attention.
Parameters:
processor (dict
of AttentionProcessor
or only AttentionProcessor
):
The instantiated processor class or a dictionary of processor classes that will be set as the processor
for all Attention
layers.
If processor
is a dict, the key needs to define the path to the corresponding cross attention
processor. This is strongly recommended when setting trainable attention processors.
Source code in mindone/diffusers/models/unets/unet_3d_condition.py
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 |
|
mindone.diffusers.UNet3DConditionModel.set_default_attn_processor()
¶
Disables custom attention processors and sets the default attention implementation.
Source code in mindone/diffusers/models/unets/unet_3d_condition.py
399 400 401 402 403 404 405 406 407 408 409 410 |
|
mindone.diffusers.models.unets.unet_3d_condition.UNet3DConditionOutput
dataclass
¶
Bases: BaseOutput
The output of [UNet3DConditionModel
].
PARAMETER | DESCRIPTION |
---|---|
sample |
The hidden states output conditioned on
TYPE:
|
Source code in mindone/diffusers/models/unets/unet_3d_condition.py
44 45 46 47 48 49 50 51 52 53 54 |
|