from mmcv.cnn import build_conv_layer
build_conv_layer函数会构建一个卷积层。
函数需要提供的参数有:
- cfg:dict类型,是卷积层的配置参数,应该包含:
- type:str类型,'Conv1d','Conv2d'等价于'Conv’,'Conv3d';
- layer args:实例化激活层需要的参数,也可以是卷积层的其它参数;
- args:参数列表,输入到对应的卷积层的参数(nn.ConvNd);
- kwargs:关键字参数,输入到对应的卷积层的参数(nn.ConvNd);
不传入cfg情况下,默认为构建nn.Conv2d,且卷积层参数均为默认。
返回的参数为:
- nn.Module(nn.ConvNd)
from mmcv.cnn import build_conv_layer
cfg = dict(
type='Conv2d'
)
conv2d = build_conv_layer(cfg, in_channels=3, out_channels=16, kernel_size=3)
print(conv2d) # Conv2d(3, 16, kernel_size=(3, 3), stride=(1, 1))
cfg2 = dict(
type='Conv2d',
in_channels=3,
out_channels=16,
kernel_size=5
)
conv2d_2 = build_conv_layer(cfg2)
print(conv2d_2) # Conv2d(3, 16, kernel_size=(5, 5), stride=(1, 1))