Pytorch 如何解决使用torch.utils.tensorboard添加图形时的运行时错误

Pytorch 如何解决使用torch.utils.tensorboard添加图形时的运行时错误,pytorch,tensorboard,Pytorch,Tensorboard,我试图使用tensorboard来可视化我的pytorch模型,但遇到了一个问题。输入张量的形状是(-1,1,20,15),输出张量的形状是(-1,6)。我的模型结合了5个卷积网络的列表 套餐: python:3.7.6 pytorch:1.4.0 张力球板:2.1.0 pytorch模型如下所示: 导入火炬 从火炬进口 从torch.nn导入功能为F 类MyModel(nn.Module): “示例” 定义初始化(self,nchunks=[2,5,3,2,3],resp_size=6):

我试图使用tensorboard来可视化我的pytorch模型,但遇到了一个问题。输入张量的形状是(-1,1,20,15),输出张量的形状是(-1,6)。我的模型结合了5个卷积网络的列表

套餐:

  • python:3.7.6
  • pytorch:1.4.0
  • 张力球板:2.1.0
pytorch模型如下所示:

导入火炬
从火炬进口
从torch.nn导入功能为F
类MyModel(nn.Module):
“示例”
定义初始化(self,nchunks=[2,5,3,2,3],resp_size=6):
super()。\uuuu init\uuuuu()
self.nchunks=nchunks
self.conv=[nn.Conv2d(1,2,(2,x))表示x在nchunk中]
self.pool=nn.Sequential(
nn.AdaptiveMaxPool1d(输出大小=10),nn.Flatten(开始大小=1)
)
self.bn=nn.BatchNorm1d(100)
self.fc1=nn.线性(100100)
self.fc2=nn.线性(100100)
self.fc3=nn.线性(100,各自大小)
def前进(自身,x):
席=火炬。分裂(X,Self.nCukes,DIM=3)
席= = f(子x,浮点()).f(1, 2, 19),zip中的子x(Self.CONV,席)
席= [自给池(子x)为席中的子x ]
席=火炬。猫(席,昏暗=1)
席=自我BN(席)
席= F.Relu(自FC1(席))
席= F.Relu(自我.FC2(席))
席=自我,FC3(席)
返回席
以下是tensorboard摘要编写器的代码:

来自torch.utils.tensorboard导入摘要编写器的

x=火炬兰((5,1,20,15))
model=MyModel()
writer=SummaryWriter('日志')
writer.add_图(模型,x)
返回这样一个错误:

RuntimeError: Cannot insert a Tensor that requires grad as a constant. Consider making it a parameter or input, or detaching the gradient
Tensor:
(1,1,.,.) =
 -0.2108 -0.4986
 -0.4009 -0.1910

(2,1,.,.) =
  0.2383 -0.4147
  0.2642  0.0456
[ torch.FloatTensor{2,1,2,2} ]
我想这个模型有一些问题,但我不确定会发生什么


这个类似的github与我的问题无关,因为我没有使用多GPU

我通过替换

[nn.Conv2d(1,2,(2,x))表示x在非圆中]

nn.ModuleList([nn.Conv2d(1,2,(2,x))表示x在nchunk中])