我试图用pytroch构建我的第一个NN,但遇到了问题。
TypeError:new()接收到无效的参数组合-得到了(float,int,int,int),但期望以下之一: *(torch.device设备) *(火炬存储存储) *(张量其他) *(整数大小的元组,torch.device设备) *(对象数据,torch.device设备)
现在,我知道这是在说什么,因为我没有将正确的类型传递给方法或初始化。但是我不知道我应该通过什么,因为它对我来说正确。
def main():
#Get the time and data
now = datetime.datetime.now()
hourGlassToStack = 2 #Hourglasses to stack
numModules= 2 #Residual Modules for each hourglass
numFeats = 256 #Number of features in each hourglass
numRegModules = 2 #Depth regression modules
print("Creating Model")
model = HourglassNet3D(hourGlassToStack, numModules, numFeats,numRegModules).cuda()
print("Model Created")
这是创建模型的主要方法。 然后调用此方法。
class HourglassNet3D(nn.Module):
def __init__(self, nStack, nModules, nFeats, nRegModules):
super(HourglassNet3D, self).__init__()
self.nStack = nStack
self.nModules = nModules
self.nFeats = nFeats
self.nRegModules = nRegModules
self.conv1_ = nn.Conv2d(3, 64, bias = True, kernel_size = 7, stride = 2, padding = 3)
self.bn1 = nn.BatchNorm2d(64)
self.relu = nn.ReLU(inplace = True)
self.r1 = Residual(64, 128)
self.maxpool = nn.MaxPool2d(kernel_size = 2, stride = 2)
self.r4 = Residual(128, 128)
self.r5 = Residual(128, self.nFeats)
_hourglass, _Residual, _lin_, _tmpOut, _ll_, _tmpOut_, _reg_ = [], [], [], [], [], [], []
for i in range(self.nStack):
_hourglass.append(Hourglass(4, self.nModules, self.nFeats))
for j in range(self.nModules):
_Residual.append(Residual(self.nFeats, self.nFeats))
lin = nn.Sequential(nn.Conv2d(self.nFeats, self.nFeats, bias = True, kernel_size = 1, stride = 1),
nn.BatchNorm2d(self.nFeats), self.relu)
_lin_.append(lin)
_tmpOut.append(nn.Conv2d(self.nFeats, 16, bias = True, kernel_size = 1, stride = 1))
_ll_.append(nn.Conv2d(self.nFeats, self.nFeats, bias = True, kernel_size = 1, stride = 1))
_tmpOut_.append(nn.Conv2d(16, self.nFeats, bias = True, kernel_size = 1, stride = 1))
for i in range(4):
for j in range(self.nRegModules):
_reg_.append(Residual(self.nFeats, self.nFeats))
self.hourglass = nn.ModuleList(_hourglass)
self.Residual = nn.ModuleList(_Residual)
self.lin_ = nn.ModuleList(_lin_)
self.tmpOut = nn.ModuleList(_tmpOut)
self.ll_ = nn.ModuleList(_ll_)
self.tmpOut_ = nn.ModuleList(_tmpOut_)
self.reg_ = nn.ModuleList(_reg_)
self.reg = nn.Linear(4 * 4 * self.nFeats,16 )
然后将其称为
class Residual(nn.Module):
#set the number ofinput and output for each layer
def __init__(self, numIn, numOut):
super(Residual, self).__init__()
self.numIn = numIn
self.numOut = numOut
self.bn = nn.BatchNorm2d(self.numIn)
self.relu = nn.ReLU(inplace = True)
self.conv1 = nn.Conv2d(self.numIn, self.numOut / 2, bias = True, kernel_size = 1)
self.bn1 = nn.BatchNorm2d(self.numOut / 2)
self.conv2 = nn.Conv2d(self.numOut / 2, self.numOut / 2, bias = True, kernel_size = 3, stride = 1, padding = 1)
self.bn2 = nn.BatchNorm2d(self.numOut / 2)
self.conv3 = nn.Conv2d(self.numOut / 2, self.numOut, bias = True, kernel_size = 1)
if self.numIn != self.numOut:
self.conv4 = nn.Conv2d(self.numIn, self.numOut, bias = True, kernel_size = 1)
所有这些对我来说看起来都不错,但是如果我做错了,我不知道该如何通过。 谢谢您的帮助
答案 0 :(得分:1)
您可能必须注意要传递给<service android:name=".StickyService" >
</service>
<receiver android:name=".RestartServiceReceiver" >
<intent-filter>
<action android:name="YouWillNeverKillMe" >
</action>
</intent-filter>
</receiver>
类中的卷积层的内容。 Per default, Python 3 will convert any division operation into a float variable。
尝试将变量转换回整数,看看是否有帮助。 Residual
的固定代码:
Residual