Pytorch UserWarning:invalid index of a 0-dim tensor.

最近空闲下来,终于有机会从繁忙的工作中脱身做些自己的事情。在新买的电脑上安装了Pytorch,跑了一下研究生期间写的一套程序。发现程序报了以前没有出现过的一个警告,

UserWarning:invalid index of a 0-dim tensor.This will be an error in Pytorch 0.5. Use tensor.item() to convert a 0-dim tensor to a Python number.

经过查阅发现,在新发布的 0.4.0 版本中,loss 是一个  0维标量。 对于标量的索引是没有意义的,在version>0.4的Pytorch 中,语句应修改为:

# 原语句
losses[split] += loss.data[0]
# 修改为
losses[split] += loss.item()

 

(oqc) PS C:\Users\Administrator\Downloads\PyNET-PyTorch-master\PyNET-PyTorch-master> python train_model.py level=5 The following parameters will be applied for CNN training: Training level: 5 Batch size: 50 Learning rate: 5e-05 Training epochs: 8 Restore epoch: None Path to the dataset: raw_images/ CUDA visible devices: 1 CUDA Device Name: NVIDIA GeForce RTX 2080 SUPER D:\anaconda\envs\oqc\lib\site-packages\torchvision\models\_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and may be removed in the future, please use 'weights' instead. warnings.warn( D:\anaconda\envs\oqc\lib\site-packages\torchvision\models\_utils.py:223: UserWarning: Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and may be removed in the future. The current behavior is equivalent to passing `weights=VGG19_Weights.IMAGENET1K_V1`. You can also use `weights=VGG19_Weights.DEFAULT` to get the most up-to-date weights. warnings.warn(msg) Downloading: "https://download.pytorch.org/models/vgg19-dcbb9e9d.pth" to C:\Users\Administrator/.cache\torch\hub\checkpoints\vgg19-dcbb9e9d.pth 100.0% The following parameters will be applied for CNN training: Training level: 5 Batch size: 50 Learning rate: 5e-05 Training epochs: 8 Restore epoch: None Path to the dataset: raw_images/ Traceback (most recent call last): File "C:\Users\Administrator\Downloads\PyNET-PyTorch-master\PyNET-PyTorch-master\train_model.py", line 197, in <module> train_model() File "C:\Users\Administrator\Downloads\PyNET-PyTorch-master\PyNET-PyTorch-master\train_model.py", line 86, in train_model x, y = next(train_iter) File "D:\anaconda\envs\oqc\lib\site-packages\torch\utils\data\dataloader.py", line 733, in __next__ data = self._next_data() File "D:\anaconda\envs\oqc\lib\site-packages\torch\utils\data\dataloader.py", line 1515, in _next_data return self._process_data(data, worker_id) File "D:\anaconda\envs\oqc\lib\site-packages\torch\utils\data\dat
最新发布
06-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值