RuntimeError: set_sizes_contiguous is not allowed on Tensor created from .data or .detach()
Closed this issue · 1 comments
Traceback (most recent call last):
File "/home/ayg/Downloads/pycharm-2019.1.1/helpers/pydev/pydevd.py", line 1741, in
main()
File "/home/ayg/Downloads/pycharm-2019.1.1/helpers/pydev/pydevd.py", line 1735, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "/home/ayg/Downloads/pycharm-2019.1.1/helpers/pydev/pydevd.py", line 1135, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/home/ayg/Downloads/pycharm-2019.1.1/helpers/pydev/pydev_imps/pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/home/ayg/workspace/crnn/train.py", line 163, in
cost = trainBatch(net, criterion, optimizer, train_iter)
File "/home/ayg/workspace/crnn/train.py", line 73, in trainBatch
lib.dataset.loadData(image, cpu_images)
File "/home/ayg/workspace/crnn/lib/dataset.py", line 144, in loadData
v.data.resize(data.size()).copy(data)
RuntimeError: set_sizes_contiguous is not allowed on Tensor created from .data or .detach()
程序运行到这里出错:
def loadData(v, data):
v.data.resize_(data.size()).copy_(data)
楼主是说Pytorch版本问题,最新1.1.0版本会出现这种问题。
代码改成如下即可:
with torch.no_grad():
v.resize_(data.size()).copy_(data)