Pytorch框架的教训!!
-
IndexError: invalid index of a 0-dim tensor. Use
tensor.item()
in Python ortensor.item<T>()
in C++ to convert a 0-dim tensor to a number
解决方法: 查找.data[0]全部替换成.item() (经常出现在loss函数)
参考博客 -
TypeError:Missing 1 required positional argument :‘self’
解决方法: 可能是定了模型类,但是使用使并没有实例化类,去使用了其中的函数。例如 class model这个模型,里面有一个train()方法,net = model(),需要使用net.train(),而不是model.train().
没看明白的点这里 -
RuntimeError: CUDA out of memory. Tried to allocate 823.88 MiB (GPU 0; 7.93 GiB total capacity; 6.96 GiB