就是把groups设置成input_channels
Code: Select all
class DepthWidth_Conv2d(nn.Module):
def __init__(self, input_channels, output_channels, kernel_size=1, strides=1, padding=1) -> None:
super(Conv, self).__init__()
self.models = nn.Sequential()
self.models.add_module('conv2d', nn.Conv2d(input_channels, input_channels, kernel_size=kernel_size, stride=strides, padding=padding, groups=input_channels))
self.models.add_module('Conv_BN1', nn.BatchNorm2d(input_channels))
self.models.add_module('Conv_leakrelu1', nn.LeakyReLU(inplace=True))
#self.models.add_module('Conv_relu1', nn.ReLU(inplace=True))
self.models.add_module('point_conv2d',nn.Conv2d(in_channels=input_channels,out_channels=output_channels,kernel_size=1,stride=1,padding=0))
self.models.add_module('Conv_BN2', nn.BatchNorm2d(output_channels))
self.models.add_module('Conv_leakrelu2', nn.LeakyReLU(inplace=True))
#self.models.add_module('Conv_relu2', nn.ReLU(inplace=True))
def forward(self, x):
return self.models.forward(x)