当前位置: 代码迷 >> 综合 >> pytorch实现常用的一些即插即用模块(长期更新)
  详细解决方案

pytorch实现常用的一些即插即用模块(长期更新)

热度:96   发布时间:2024-02-19 23:47:24.0

1.可分离卷积

#coding:utf-8
import torch.nn as nnclass DWConv(nn.Module):def __init__(self, in_plane, out_plane):super(DWConv, self).__init__()self.depth_conv = nn.Conv2d(in_channels=in_plane,out_channels=in_plane,kernel_size=3,stride=1,padding=1,groups=in_plane)self.point_conv = nn.Conv2d(in_channels=in_plane,out_channels=out_plane,kernel_size=1,stride=1,padding=0,groups=1)def forward(self, x):x = self.depth_conv(x)x = self.point_conv(x)return xdef deubg_dw():import torchDW_model = DWConv(3, 32)x = torch.rand((32, 3, 320, 320))out = DW_model(x)print(out.shape)
if __name__ == '__main__':deubg_dw()

 

  相关解决方案