类型错误:在对 pytorch 模型使用 summary() 时,不能将序列乘以“元组”类型的非整数

问题描述

因为我正在设计一个多模式架构,有一个 3dcnn 和 2dcnn,所以我想像在 Keras 中一样查看模型架构。输入大小如图所示,当我尝试打印结构时,我不断收到此错误,但在运行它以进行训练和模型评估时没有问题。

enter image description here

class CombineModel(nn.Module): #A multimodal network(3D and 2D CNN),with multIoUtputs (2 outputs)
  def __init__(self,num_classes):
    super(CombineModel,self).__init__()
    self.CNN3D = CNN3DModel() #output size is (512,1)
    self.Unet = UNet11() #output size is (512,1)
    self.fc1 = nn.Linear(1024,512)
    self.fc2 = nn.Linear(512,num_classes)
    self.fc3 = nn.Linear(512,1)
    self.relu = nn.ReLU()
    self.flatten = nn.Flatten() 
    self.softmax = nn.softmax()

  def forward(self,x1,x2):
    out1 = self.CNN3D(x1)
    out2 = self.Unet(x2)
    outa = torch.cat((out1,out2),dim=1)
    outa = self.fc1(outa)
    outa = self.relu(outa)
    outa = self.softmax(self.fc2(outa))
    outb = self.fc3(self.relu(out2))

    return outa,outb

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)