pytorch使用备忘
pytorch日常使用及常见问题。
安装
指定GPU训练
CUDA_VISIBLE_DEVICES=1 python main.py
tensorboard
tensorboard --logdir ./stargan/logs
常见错误
print( loss.data[0])
报错:
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number
修改:
loss.data[]
改为:
loss.item()
更新pytorch 到 pytorch 1.7-cuda11
# 卸载旧版本
ssh 18.18.10.201
pip uninstall torch
# 安装新版本
pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio===0.7.2 -f https://download.pytorch.org/whl/torch_stable.html