pytorch版segnet复现实践

复现了github地址:https://github.com/nshaud/DeepNetsForEO的pytorch版本应用于遥感影像上的segnet模型。
将配置环境时遇到的问题总结如下:

1.在指定的conda虚拟环境运行Jupyter Notebook

参考网址:https://blog.csdn.net/weixin_43593330/article/details/89856136

#查看已有虚拟环境
conda info --envs
#新建一个Python2版本的conda虚拟环境
conda create -n py2 python=2.7
#进入虚拟环境
conda activate py2
#安装jupyter
conda install -n py2 jupyter
#安装nb_conda
conda install -n py2 nb_conda

启动jupyter notebook:
将路径切到对应目录下,然后输入jupyter notebook,在kernel中可以选择虚拟环境
在这里插入图片描述

2.错误提示:ImportError: cannot import name ‘_validate_lengths’

这是scikit-image和numpy版本问题导致的,解决方案如下:

#安装如下包:
scikit-iamge==0.14.2
numpy==1.16.2

3.安装pytorch

参考网址:https://blog.csdn.net/fkyyly/article/details/89107235

#添加Anaconda的TUNA镜像
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ #可能提示已存在
#设置搜索时显示通道地址
conda config --set show_channel_urls yes
#安装GPU版本的pytorch
conda install pytorch torchvision -c pytorch

不过安装了好多次包都下不下来,提示错误如下:

CondaMultiError: CondaError: Downloaded bytes did not match Content-Length
  url: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/linux-64/pytorch-1.3.1-py2.7_cuda10.1.243_cudnn7.6.3_0.tar.bz2
  target_path: /home/ubuntu/anaconda2/pkgs/pytorch-1.3.1-py2.7_cuda10.1.243_cudnn7.6.3_0.tar.bz2
  Content-Length: 448800224
  downloaded bytes: 225967788

这是网络原因导致pytorch包下载不下来,反复尝试下载均无果。最后参考网址https://blog.csdn.net/guihuo2889/article/details/84652733下载了对应的whl包,同时放到服务器的Downloads文件夹中,cd到对应路径下,利用pip install进行了安装
在这里插入图片描述然后终于将pytorch安装成功。

4.遇到错误提示:

IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python

报错原因分析:
train_loss += loss.data[0] 是pytorch0.3.1版本代码,在0.4-0.5版本的pytorch会出现警告,不会报错,但是0.5版本以上的pytorch就会报错,总的来说是版本更新问题.
解决方法:

#将原语句:
train_loss+=loss.data[0]
#修改为:
train_loss+=loss.item()

参考网址:https://blog.csdn.net/chen645096127/article/details/94019443

5.错误提示:

NameError: name 'IntProgress' is not defined

错误原因:jupyter notebook /lab 使用tqdm时(from tqdm import tqdm_notebook as tqdm) 报错: NameError: name ‘IntProgress’ is not defined
解决方案: 安装ipywidgets即可.

pip install ipywidgets
或
conda install  ipywidgets

参考网址:https://blog.csdn.net/vola9527/article/details/79875022

6.遇到错误提示:

AssertionError:
The NVIDIA driver on your system is too old (found version 9010).
Please update your GPU driver by downloading and installing a new
version from the URL: http://www.nvidia.com/Download/index.aspx
Alternatively, go to: https://pytorch.org to install
a PyTorch version that has been compiled with your version
of the CUDA driver.

错误原因分析:cuda版本和安装的pytorch不匹配
解决方案:

(1)安装与cuda版本对应的pytorch版本

:我是先按照3安装了pytorch,本来在安装torch时对应了cuda8.0版本,但是在运行pip install torchvision时torch版本发生了改变,所以出现了6中的错误,所以我再次运行了pip install torch××××.whl,安装cuda8对应的torch。这个问题就解决了,但是出现了问题5,我又安装了ipywidgets,在安装这个的过程中torch版本又更新了,不过依旧是对应了cuda8.0版本,但是又出现了问题4,然后又针对问题4修改后,程序成功运行。

(2)在Ubuntu上安装多个cuda版本并切换,

可参考网址:https://blog.csdn.net/yinxingtianxia/article/details/80462892
出现报错的原因是因为目前pytorch版本更对应于cuda9,所以我本来想在ubuntu上再安装个cuda9,进行多个cuda的切换,但由于程序成功运行,这个暂时没弄,等有空搞一下。

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值