我已经做了一个代码来解决Atari Breakout。我正面临一个小问题,但我不能说它是什么。
这是code
重放内存有问题。
try:
next_states = torch.tensor(batch[3], dtype=torch.float32)
except:
import ipdb; ipdb.set_trace()问题在于这些行在哪里。set_trace()用于弹出交互式外壳。从那里,如果我运行for i in range(batch_size): print(batch[3][i].shape),我将获得以下输出
ipdb> for i in range(32): print(batch[3][i].shape)
(4, 84, 84)
(4, 84, 84)
(4, 84, 84)
(4, 84, 84)
(4, 84, 84)
(4, 84, 84)
(4, 84, 84)
(4, 84, 84)
(4, 84, 84)
(4, 84, 84)
(4, 84, 84)
(4, 84, 84)
(4, 84, 84)
(4, 84, 84)
(4, 84, 84)
(4, 84, 84)
(4, 84, 84)
(4, 84, 84)
(4, 84, 84)
(4, 84, 84)
(4, 84, 84)
(4, 84, 84)
(4, 84, 84)
(4, 84, 84)
(4, 84, 84)
(4, 84, 84)
(4, 84, 84)
*** AttributeError: 'NoneType' object has no attribute 'shape'如何改进代码以避免此类错误?
发布于 2020-04-13 05:15:11
该错误将告诉您问题所在。您正尝试在None上调用shape,因此,在您的代码中,某个变量a为None,而您正在对其调用shape,即a.shape。这是编程中最常见的错误之一!
在你的for循环中
for i in range(32):
print(batch[3][i].shape)在某种程度上,batch[3][i]是None,所以您必须弄清楚batch[3]包含什么以及为什么它是None。
请参阅此处的讨论https://chat.stackexchange.com/transcript/message/54070403#54070403。
https://stackoverflow.com/questions/61178239
复制相似问题