miraclewkf / ImageClassification-PyTorch

170 stars 112 forks source link

python 3.6需要更改的写法 #3

Open Xingxiangrui opened 5 years ago

Xingxiangrui commented 5 years ago

/home/xingxiangrui/env/lib/python3.6/site-packages/torchvision/transforms/transforms.py:563: UserWarning: The use of the transforms.RandomSizedCrop transform is deprecated, please use transforms.RandomResizedCrop instead. "please use transforms.RandomResizedCrop instead.") /home/xingxiangrui/env/lib/python3.6/site-packages/torchvision/transforms/transforms.py:188: UserWarning: The use of the transforms.Scale transform is deprecated, please use transforms.Resize instead. "please use transforms.Resize instead.")

如果更改到python3.6,需要把上面这两个函数更改一下名字。

Xingxiangrui commented 5 years ago

同时,label标签需要从0开始。不然会报错:RuntimeError: cuda runtime error (59) : device-side assert triggered at /home/lychee/mycode/pytorch/aten/src/THC/generic/THCTensorMath.cu:24

Xingxiangrui commented 5 years ago

还有,return loss.data[0] IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number

原语句:

train_loss+=loss.data[0]

修改后:

train_loss+=loss.item()