【深度学习】empty() received an invalid combination of arguments - got (tuple, dtype=NoneType, device=None

构建yoloV3的resblock时,python的一个小坑

在构建一个简单的卷积层时,出现如下的错误:
在这里插入图片描述
代码如下:

class resblock(nn.Module):
    def __init__(self,inputDims):
        super(resblock,self).__init__()
        self.inputChannels = inputDims
        self.middleChannels = int(inputDims/2)
        #报错行
        self.conv1 = nn.Conv2d(in_channels=inputDims,out_channels=inputDims/2,kernel_size=1,stride=1)
        self.bn1 = nn.BatchNorm2d(self.middleChannels)
        self.active1 = nn.LeakyReLU()
        self.conv3x3 = nn.Conv2d(in_channels=self.middleChannels,out_channels=inputDims,kernel_size=3,stride=1,padding=1)
        self.bn2 = nn.BatchNorm2d(inputDims)
        self.active2 = nn.LeakyReLU()

        self.shortcut = shortCut()
    def forward(self,x):
        y1 = self.active1(self.bn1(self.conv1(x)))
        y = self.active2(self.bn2(self.conv3x3(y1)))
        return self.shortcut(x,y)

产生的原因是因为在python3中两个整型相除得到的是浮点型,例如:4/2=2.0,而在构建卷积时的参数要求时整型

猜你喜欢

转载自blog.csdn.net/qq_25105061/article/details/123705011
今日推荐