MCPcopy Create free account
hub / github.com/VisionXLab/OF-Diff / UNetModel

Class UNetModel

ldm/modules/diffusionmodules/openaimodel.py:414–788  ·  view source on GitHub ↗

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 downsamp

Source from the content-addressed store, hash-verified

412
413
414class UNetModel(nn.Module):
415 """
416 The full UNet model with attention and timestep embedding.
417 :param in_channels: channels in the input Tensor.
418 :param model_channels: base channel count for the model.
419 :param out_channels: channels in the output Tensor.
420 :param num_res_blocks: number of residual blocks per downsample.
421 :param attention_resolutions: a collection of downsample rates at which
422 attention will take place. May be a set, list, or tuple.
423 For example, if this contains 4, then at 4x downsampling, attention
424 will be used.
425 :param dropout: the dropout probability.
426 :param channel_mult: channel multiplier for each level of the UNet.
427 :param conv_resample: if True, use learned convolutions for upsampling and
428 downsampling.
429 :param dims: determines if the signal is 1D, 2D, or 3D.
430 :param num_classes: if specified (as an int), then this model will be
431 class-conditional with `num_classes` classes.
432 :param use_checkpoint: use gradient checkpointing to reduce memory usage.
433 :param num_heads: the number of attention heads in each attention layer.
434 :param num_heads_channels: if specified, ignore num_heads and instead use
435 a fixed channel width per attention head.
436 :param num_heads_upsample: works with num_heads to set a different number
437 of heads for upsampling. Deprecated.
438 :param use_scale_shift_norm: use a FiLM-like conditioning mechanism.
439 :param resblock_updown: use residual blocks for up/downsampling.
440 :param use_new_attention_order: use a different attention pattern for potentially
441 increased efficiency.
442 """
443
444 def __init__(
445 self,
446 image_size,
447 in_channels,
448 model_channels,
449 out_channels,
450 num_res_blocks,
451 attention_resolutions,
452 dropout=0,
453 channel_mult=(1, 2, 4, 8),
454 conv_resample=True,
455 dims=2,
456 num_classes=None,
457 use_checkpoint=False,
458 use_fp16=False,
459 num_heads=-1,
460 num_head_channels=-1,
461 num_heads_upsample=-1,
462 use_scale_shift_norm=False,
463 resblock_updown=False,
464 use_new_attention_order=False,
465 use_spatial_transformer=False, # custom transformer support
466 transformer_depth=1, # custom transformer support
467 context_dim=None, # custom transformer support
468 n_embed=None, # custom support for prediction of discrete ids into codebook of first stage vq model
469 legacy=True,
470 disable_self_attentions=None,
471 num_attention_blocks=None,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected