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

Class Downsample1D

src/diffusers/models/downsampling.py:27–67  ·  view source on GitHub ↗

A 1D downsampling layer with an optional convolution. Parameters: channels (`int`): number of channels in the inputs and outputs. use_conv (`bool`, default `False`): option to use a convolution. out_channels (`int`, optional): number o

Source from the content-addressed store, hash-verified

25
26
27class Downsample1D(nn.Module):
28 """A 1D downsampling layer with an optional convolution.
29
30 Parameters:
31 channels (`int`):
32 number of channels in the inputs and outputs.
33 use_conv (`bool`, default `False`):
34 option to use a convolution.
35 out_channels (`int`, optional):
36 number of output channels. Defaults to `channels`.
37 padding (`int`, default `1`):
38 padding for the convolution.
39 name (`str`, default `conv`):
40 name of the downsampling 1D layer.
41 """
42
43 def __init__(
44 self,
45 channels: int,
46 use_conv: bool = False,
47 out_channels: Optional[int] = None,
48 padding: int = 1,
49 name: str = "conv",
50 ):
51 super().__init__()
52 self.channels = channels
53 self.out_channels = out_channels or channels
54 self.use_conv = use_conv
55 self.padding = padding
56 stride = 2
57 self.name = name
58
59 if use_conv:
60 self.conv = nn.Conv1d(self.channels, self.out_channels, 3, stride=stride, padding=padding)
61 else:
62 assert self.channels == self.out_channels
63 self.conv = nn.AvgPool1d(kernel_size=stride, stride=stride)
64
65 def forward(self, inputs: torch.Tensor) -> torch.Tensor:
66 assert inputs.shape[1] == self.channels
67 return self.conv(inputs)
68
69
70class Downsample2D(nn.Module):

Callers 3

__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected