utils
最后更新
luxonis_train.nodes.blocks.utils构建块的辅助函数:保持卷积大小的填充、块工厂的类型以及收集中间输出的前向传播。类
ModuleFactory
in_channels 和 out_channels 并返回一个 torch.nn.Module。像 GeneralReparameterizableBlock 这样的块类匹配。BottleRep 使用关键字参数调用其工厂。函数
autopad
Python
1def autopad(kernel_size: T, padding: T | None = None) -> T:1 和膨胀为 1 的情况下保持大小。示例
Pycon
1>>> from luxonis_train.nodes.blocks import autopad
2>>> autopad(3)
31
4>>> autopad((3, 5))
5(1, 2)
6>>> autopad(3, padding=0)
70kernel_size(T): 内核大小,一个值或每个轴一个值。padding(T | None): 显式填充。None选择计算出的填充。
T: 当padding不为None时为padding。否则为每个值的kernel_size // 2,类型与kernel_size相同。
forward_gather
Python
1def forward_gather(x: Tensor, modules: Iterable[nn.Module]) -> list[Tensor]:x。示例
Pycon
1>>> import torch
2>>> from torch import nn
3>>> from luxonis_train.nodes.blocks.utils import forward_gather
4>>> pools = [nn.MaxPool2d(2), nn.MaxPool2d(2)]
5>>> outputs = forward_gather(torch.zeros(1, 1, 8, 8), pools)
6>>> [tuple(output.shape) for output in outputs]
7[(1, 1, 4, 4), (1, 1, 2, 2)]x(Tensor): 第一个模块的输入。modules(Iterable[nn.Module]): 模块,按运行顺序排列。
list[Tensor]: 每个模块的输出,按相同顺序排列。列表不包含x。