MCPcopy Create free account
hub / github.com/DPS2022/diffusion-posterior-sampling / EncoderUNetModel

Class EncoderUNetModel

guided_diffusion/unet.py:754–965  ·  view source on GitHub ↗

The half UNet model with attention and timestep embedding. For usage, see UNet.

Source from the content-addressed store, hash-verified

752
753
754class EncoderUNetModel(nn.Module):
755 """
756 The half UNet model with attention and timestep embedding.
757
758 For usage, see UNet.
759 """
760
761 def __init__(
762 self,
763 image_size,
764 in_channels,
765 model_channels,
766 out_channels,
767 num_res_blocks,
768 attention_resolutions,
769 dropout=0,
770 channel_mult=(1, 2, 4, 8),
771 conv_resample=True,
772 dims=2,
773 use_checkpoint=False,
774 use_fp16=False,
775 num_heads=1,
776 num_head_channels=-1,
777 num_heads_upsample=-1,
778 use_scale_shift_norm=False,
779 resblock_updown=False,
780 use_new_attention_order=False,
781 pool="adaptive",
782 ):
783 super().__init__()
784
785 if num_heads_upsample == -1:
786 num_heads_upsample = num_heads
787
788 self.in_channels = in_channels
789 self.model_channels = model_channels
790 self.out_channels = out_channels
791 self.num_res_blocks = num_res_blocks
792 self.attention_resolutions = attention_resolutions
793 self.dropout = dropout
794 self.channel_mult = channel_mult
795 self.conv_resample = conv_resample
796 self.use_checkpoint = use_checkpoint
797 self.dtype = th.float16 if use_fp16 else th.float32
798 self.num_heads = num_heads
799 self.num_head_channels = num_head_channels
800 self.num_heads_upsample = num_heads_upsample
801
802 time_embed_dim = model_channels * 4
803 self.time_embed = nn.Sequential(
804 linear(model_channels, time_embed_dim),
805 nn.SiLU(),
806 linear(time_embed_dim, time_embed_dim),
807 )
808
809 ch = int(channel_mult[0] * model_channels)
810 self.input_blocks = nn.ModuleList(
811 [TimestepEmbedSequential(conv_nd(dims, in_channels, ch, 3, padding=1))]

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected