The full UNet model with attention and timestep embedding. :param in_channels: channels in the input Tensor. :param model_channels: base channel count for the model. :param out_channels: channels in the output Tensor. :param num_res_blocks: number of residual blocks per downsam
| 465 | |
| 466 | |
| 467 | class UNetModel(nn.Module): |
| 468 | """ |
| 469 | The full UNet model with attention and timestep embedding. |
| 470 | |
| 471 | :param in_channels: channels in the input Tensor. |
| 472 | :param model_channels: base channel count for the model. |
| 473 | :param out_channels: channels in the output Tensor. |
| 474 | :param num_res_blocks: number of residual blocks per downsample. |
| 475 | :param attention_resolutions: a collection of downsample rates at which |
| 476 | attention will take place. May be a set, list, or tuple. |
| 477 | For example, if this contains 4, then at 4x downsampling, attention |
| 478 | will be used. |
| 479 | :param dropout: the dropout probability. |
| 480 | :param channel_mult: channel multiplier for each level of the UNet. |
| 481 | :param conv_resample: if True, use learned convolutions for upsampling and |
| 482 | downsampling. |
| 483 | :param dims: determines if the signal is 1D, 2D, or 3D. |
| 484 | :param num_classes: if specified (as an int), then this model will be |
| 485 | class-conditional with `num_classes` classes. |
| 486 | :param use_checkpoint: use gradient checkpointing to reduce memory usage. |
| 487 | :param num_heads: the number of attention heads in each attention layer. |
| 488 | :param num_heads_channels: if specified, ignore num_heads and instead use |
| 489 | a fixed channel width per attention head. |
| 490 | :param num_heads_upsample: works with num_heads to set a different number |
| 491 | of heads for upsampling. Deprecated. |
| 492 | :param use_scale_shift_norm: use a FiLM-like conditioning mechanism. |
| 493 | :param resblock_updown: use residual blocks for up/downsampling. |
| 494 | :param use_new_attention_order: use a different attention pattern for potentially |
| 495 | increased efficiency. |
| 496 | """ |
| 497 | |
| 498 | def __init__( |
| 499 | self, |
| 500 | image_size, |
| 501 | in_channels, |
| 502 | model_channels, |
| 503 | out_channels, |
| 504 | num_res_blocks, |
| 505 | attention_resolutions, |
| 506 | dropout=0, |
| 507 | channel_mult=(1, 2, 4, 8), |
| 508 | conv_resample=True, |
| 509 | dims=2, |
| 510 | num_classes=None, |
| 511 | use_checkpoint=False, |
| 512 | use_fp16=False, |
| 513 | num_heads=1, |
| 514 | num_head_channels=-1, |
| 515 | num_heads_upsample=-1, |
| 516 | use_scale_shift_norm=False, |
| 517 | resblock_updown=False, |
| 518 | use_new_attention_order=False, |
| 519 | ): |
| 520 | super().__init__() |
| 521 | |
| 522 | if num_heads_upsample == -1: |
| 523 | num_heads_upsample = num_heads |
| 524 |