我在使用TensorBoardX的模型的重量和偏差时遇到困难。这是我的模型(无论如何都很简单):
self.pipe = nn.Sequential(nn.Linear(9, 128),
nn.ReLU(),
nn.Linear(128, 256),
nn.ReLU(),
nn.Linear(256,2),
nn.Softmax()
)
def forward(self, x):
return self.pipe(x)
这是我在Pytorch中遇到错误的地方
for name, param in net.named_parameters():
writer.add_histogram(name, param, epoch_size, bins='auto')
错误是
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-70-d060d2df4423> in <module>()
1 for name, param in net.named_parameters():
----> 2 writer.add_histogram(name, param, epoch_size, bins='auto')
~Anaconda3libsite-packagestensorboardXwriter.py in add_histogram(self, tag, values, global_step, bins, walltime)
403 if isinstance(bins, six.string_types) and bins == 'tensorflow':
404 bins = self.default_bins
--> 405 self.file_writer.add_summary(
406 histogram(tag, values, bins), global_step, walltime)
407
AttributeError: 'NoneType' object has no attribute 'add_summary'
,但我确实必须看到直方图,其中权重次优。因此,我更改了一些代码以逐步进行
param = np.array(list(net.parameters()))
print(param[0].data)
writer.add_histogram('weight', param[0].data)
繁荣!仍然同样的错误,也许根本不会改变。
已发布的代码段不足以引起问题。
当在Writer上调用Close()方法时,成员变量file_writer设置为无。请检查Close()方法是否已在作者身上调用。当用作作者对象用作上下文管理器并退出块。
时,也将调用Close()方法。with SummaryWriter() as writer:
writer.add_scalar...
writer.add_histogram # this will cause a crash