MCPcopy Create free account
hub / github.com/TencentARC/BrushNet / TemporalResnetBlock

Class TemporalResnetBlock

src/diffusers/models/resnet.py:574–663  ·  view source on GitHub ↗

r""" A Resnet block. Parameters: in_channels (`int`): The number of channels in the input. out_channels (`int`, *optional*, default to be `None`): The number of output channels for the first conv2d layer. If None, same as `in_channels`. temb_channels (`in

Source from the content-addressed store, hash-verified

572
573
574class TemporalResnetBlock(nn.Module):
575 r"""
576 A Resnet block.
577
578 Parameters:
579 in_channels (`int`): The number of channels in the input.
580 out_channels (`int`, *optional*, default to be `None`):
581 The number of output channels for the first conv2d layer. If None, same as `in_channels`.
582 temb_channels (`int`, *optional*, default to `512`): the number of channels in timestep embedding.
583 eps (`float`, *optional*, defaults to `1e-6`): The epsilon to use for the normalization.
584 """
585
586 def __init__(
587 self,
588 in_channels: int,
589 out_channels: Optional[int] = None,
590 temb_channels: int = 512,
591 eps: float = 1e-6,
592 ):
593 super().__init__()
594 self.in_channels = in_channels
595 out_channels = in_channels if out_channels is None else out_channels
596 self.out_channels = out_channels
597
598 kernel_size = (3, 1, 1)
599 padding = [k // 2 for k in kernel_size]
600
601 self.norm1 = torch.nn.GroupNorm(num_groups=32, num_channels=in_channels, eps=eps, affine=True)
602 self.conv1 = nn.Conv3d(
603 in_channels,
604 out_channels,
605 kernel_size=kernel_size,
606 stride=1,
607 padding=padding,
608 )
609
610 if temb_channels is not None:
611 self.time_emb_proj = nn.Linear(temb_channels, out_channels)
612 else:
613 self.time_emb_proj = None
614
615 self.norm2 = torch.nn.GroupNorm(num_groups=32, num_channels=out_channels, eps=eps, affine=True)
616
617 self.dropout = torch.nn.Dropout(0.0)
618 self.conv2 = nn.Conv3d(
619 out_channels,
620 out_channels,
621 kernel_size=kernel_size,
622 stride=1,
623 padding=padding,
624 )
625
626 self.nonlinearity = get_activation("silu")
627
628 self.use_in_shortcut = self.in_channels != out_channels
629
630 self.conv_shortcut = None
631 if self.use_in_shortcut:

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected