blocks
最后更新
luxonis_train.nodes.necks.reppan_neck.blocksRepPAN neck 的上采样和下采样块。类
CSPDownBlock
out_channels。当 block 为 "CSPStackRepBlock" 时,RepPANNeck 使用此步骤,如 "m" 和 "l" 变体所示。示例
Pycon
1>>> import torch
2>>> block = CSPDownBlock(
3... 4, 8, in_channels_next=12, out_channels=16, n_repeats=2, e=0.25
4... )
5>>> block.encode_block.conv_1.out_channels
64
7>>> x0, x1 = torch.zeros(1, 4, 8, 8), torch.zeros(1, 12, 4, 4)
8>>> block(x0, x1).shape
9torch.Size([1, 16, 4, 4])方法
init
Python
1def __init__(in_channels: int, downsample_out_channels: int, in_channels_next: int, out_channels: int, n_repeats: int, e: float):in_channels(int): 精细输入的通道数。downsample_out_channels(int): 下采样卷积后的通道数。in_channels_next(int): 横向输入的通道数,该步骤将其连接。out_channels(int): 输出通道数。n_repeats(int): 控制 CSPStackRepBlock 中 RepVGG 风格块的数量。每个 BottleRep 包含两个,因此堆栈有max(1, n_repeats // 2)个 BottleRep 块和2 * max(1, n_repeats // 2)个 RepVGG 风格块。e(float): CSPStackRepBlock 的两条路径中out_channels的分数。
CSPUpBlock
out_channels。当 block 为 "CSPStackRepBlock" 时,RepPANNeck 使用此步骤,如 "m" 和 "l" 变体所示。示例
Pycon
1>>> block = CSPUpBlock(
2... 32, in_channels_next=16, out_channels=8, n_repeats=4, e=0.5
3... )
4>>> block.encode_block.conv_1.out_channels
54
6>>> len(block.encode_block.rep_stack)
72方法
init
Python
1def __init__(in_channels: int, in_channels_next: int, out_channels: int, n_repeats: int, e: float):in_channels(int): 粗略输入的通道数。in_channels_next(int): 更精细输入的通道数,该步骤将其连接。out_channels(int): 输出通道数。n_repeats(int): 控制 CSPStackRepBlock 中 RepVGG 风格块的数量。每个 BottleRep 包含两个,因此堆栈有max(1, n_repeats // 2)个 BottleRep 块和2 * max(1, n_repeats // 2)个 RepVGG 风格块。e(float): CSPStackRepBlock 的两条路径中out_channels的分数。
PANDownBlockBase
3x3 ConvBlock,步长为 2,填充为 1,带批量归一化和 ReLU,将精细输入的高度和宽度减半。奇数尺寸向上取整。该块将结果与横向输入沿通道轴连接,并对其运行 encode_block。子类选择 encode_block。方法
init
Python
1def __init__(in_channels: int, downsample_out_channels: int, encode_block: nn.Module):in_channels(int): 精细输入的通道数。downsample_out_channels(int): 下采样卷积后的通道数。encode_block(nn.Module): 在连接上运行的块。其输入具有downsample_out_channels加上横向输入的通道数。
forward
Python
1def forward(x0: Tensor, x1: Tensor) -> Tensor:示例
Pycon
1>>> import torch
2>>> block = RepDownBlock(
3... 4, 8, in_channels_next=12, out_channels=16, n_repeats=1
4... )
5>>> x0, x1 = torch.zeros(1, 4, 8, 8), torch.zeros(1, 12, 4, 4)
6>>> block(x0, x1).shape
7torch.Size([1, 16, 4, 4])x0(Tensor): 形状为[B, in_channels, H, W]的精细图。x1(Tensor): 形状为[B, C1, H / 2, W / 2]的横向图。奇数H或W向上取整。在子类中,C1是in_channels_next。
Tensor:encode_block的输出。在子类中,其形状为[B, out_channels, H / 2, W / 2]。
属性
downsample
encode_block
PANUpBlockBase
1x1 ConvBlock,带批量归一化和 ReLU,将粗略输入映射到 out_channels。然后,一个步长为 2 的 2x2 转置卷积将高度和宽度加倍。该块将结果与更精细的输入沿通道轴连接,并对其运行 encode_block。子类选择 encode_block。方法
init
Python
1def __init__(in_channels: int, out_channels: int, encode_block: nn.Module):1x1 卷积和上采样层。参数in_channels(int): 粗略输入的通道数。out_channels(int):1x1卷积后的通道数。上采样层保持此数量。encode_block(nn.Module): 在连接上运行的块。其输入具有out_channels加上更精细输入的通道数。
forward
Python
1def forward(x0: Tensor, x1: Tensor) -> tuple[Tensor, Tensor]:示例
Pycon
1>>> import torch
2>>> block = RepUpBlock(
3... 32, in_channels_next=16, out_channels=8, n_repeats=1
4... )
5>>> x0, x1 = torch.zeros(1, 32, 4, 4), torch.zeros(1, 16, 8, 8)
6>>> conv_out, out = block(x0, x1)
7>>> conv_out.shape, out.shape
8(torch.Size([1, 8, 4, 4]), torch.Size([1, 8, 8, 8]))x0(Tensor): 形状为[B, in_channels, H, W]的粗略图。x1(Tensor): 形状为[B, C1, 2 * H, 2 * W]的更精细图。在子类中,C1是in_channels_next。
tuple[Tensor, Tensor]: 元组(conv_out, out)。conv_out是1x1卷积的输出,形状为[B, out_channels, H, W]。RepPANNeck 将其作为横向输入提供给自下而上步骤。out是encode_block的输出。在子类中,out的形状为[B, out_channels, 2 * H, 2 * W]。
属性
conv
encode_block
upsample
RepDownBlock
n_repeats 个 GeneralReparameterizableBlock 层的 BlockRepeater。第一层将连接映射到 out_channels。其他层保持该数量。当 block 为 "RepBlock" 时,RepPANNeck 使用此步骤,如 "n" 和 "s" 变体所示。示例
Pycon
1>>> import torch
2>>> block = RepDownBlock(
3... 4, 8, in_channels_next=12, out_channels=16, n_repeats=3
4... )
5>>> block.encode_block(torch.zeros(1, 20, 4, 4)).shape
6torch.Size([1, 16, 4, 4])方法
init
Python
1def __init__(in_channels: int, downsample_out_channels: int, in_channels_next: int, out_channels: int, n_repeats: int):in_channels(int): 精细输入的通道数。downsample_out_channels(int): 下采样卷积后的通道数。in_channels_next(int): 横向输入的通道数,该步骤将其连接。out_channels(int): 输出通道数。n_repeats(int): GeneralReparameterizableBlock 层的数量。小于1的值仍会构建一层。
RepUpBlock
n_repeats 个 GeneralReparameterizableBlock 层的 BlockRepeater。第一层将连接映射到 out_channels。其他层保持该数量。当 block 为 "RepBlock" 时,RepPANNeck 使用此步骤,如 "n" 和 "s" 变体所示。示例
Pycon
1>>> import torch
2>>> block = RepUpBlock(
3... 32, in_channels_next=16, out_channels=8, n_repeats=3
4... )
5>>> block.encode_block(torch.zeros(1, 24, 4, 4)).shape
6torch.Size([1, 8, 4, 4])方法
init
Python
1def __init__(in_channels: int, in_channels_next: int, out_channels: int, n_repeats: int):in_channels(int): 粗略输入的通道数。in_channels_next(int): 更精细输入的通道数,该步骤将其连接。out_channels(int): 输出通道数。n_repeats(int): GeneralReparameterizableBlock 层的数量。小于1的值仍会构建一层。