pytorch中depthwidth_conv2d在esp32s3上的优化问题

gjhave
Posts: 12
Joined: Mon Aug 14, 2023 7:27 am

pytorch中depthwidth_conv2d在esp32s3上的优化问题

Postby gjhave » Tue Aug 29, 2023 3:34 am

各位好,我用pytorch1.13写的模型,因为pytorch中没有直接的depthwidth_conv2d的算子,所以我做了如下替代:
就是把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)
经过官方手动量化工具后还是是两个conv2d,请问这个时候是否可以直接在我的cpp代码里将第一个conv2d用esp-dl/include/layer中的depthwidth_conv2d替代,如果可以,depthwidth_conv2d和还是使用conv2d哪个效率更高?谢谢

Who is online

Users browsing this forum: No registered users and 8 guests