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,而在构建卷积时的参数要求时整型