栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

conda安装Tensorflow和pytorch经验

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

conda安装Tensorflow和pytorch经验

conda安装Tensorflow和pytorch经验

conda安装pytorch和tensorflow最让人难受的就是cuda,cudnn版本不一致,没有镜像源等问题。

首先是cuda的选择。

cuda是NVIDIA用GPU做训练时用的,所以首先你要有NVIDIA的显卡,然后装好驱动。然后打开驱动的控制面板,选择帮助->系统信息->组件,然后在产品名称那儿可以看到一个NVIDIA CUDA x.x.x,这个是你的NVIDIA驱动最高支持的cuda的版本号。(安装cuda时对应的名字是cudatoolkit)

然后cudnn一般网站会给你推荐一个版本,或者不指定,缺省不写,然后看安装的默认版本的是否能用

详细信息请看:https://blog.csdn.net/iamqianrenzhan/article/details/89343601

然后是从官网找命令了

官网上一般介绍了cuda cudaa和你的tensorflow或者pytorch的搭配,直接复制命令安装即可。但是注意命令后面的-c是指定安装镜像源,官网指定的源是外国的,比较慢,用国内的。

但是国内好多镜像源都不能用,现在有几个稍微好用点的,但是不全

show_channel_urls: true
channels:
  - https://mirrors.bfsu.edu.cn/anaconda/pkgs/free
  - https://mirrors.bfsu.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - defaults

配置上述渠道方法:(注意镜像从下往上复制,因为是依次往上添加,上面的优先级高 )(这是对自己输入命令说的,下方的代码直接复制即可)

conda config --set show_channel_urls yes
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/pkgs/main
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/pkgs/free
conda config --show channels

还有一个pytorch的镜像源 :https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/ ,自己加上去

但是经常出现找不到你的安装版本的情况,可以用以下命令看你的源是否有你需要的版本:

conda search cudatoolkit //将显示所有关于镜像源的cudatoolkit的下载信息

conda search tensorflow

找到你有的版本,然后从官网找到你有的版本对应的命令复制然后执行。

然后你会发现会有一些插件的版本不匹配,可以用install命令更新

conda install python=3.6 //假如原来是3.5,现在需要3.6,会给你更新为3.6版本的。

安装命令:

指定版本安装: conda install cudatoolkit=9.0

指定版本和安装镜像源:conda install cudatoolkit=9.0 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/linux-64/

指定渠道安装的另一种方法:conda install pytorch=1.1.0 torchvision=0.3.0 cudatoolkit=9.0 --channel https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

conda install tensorflow-gpu=1.12 cudatoolkit=9.0 cudnn=7.2

tensorflow的版本对应适配:https://tensorflow.google.cn/install/source_windows#gpu

Tensorflow的安装及验证:https://blog.csdn.net/Never__Say__No/article/details/105000916

pytorch安装命令举例:conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

pytorch的安装及验证:https://blog.csdn.net/gg864461719/article/details/112259806

一般习惯创建一个新的环境镜像安装

conda create -n pytorch python=3.6 #conda 是指调用 conda 包,create 是创建的意思,-n 是指后面的名字是屋子的名字, pytorch是屋子的名字(可以更改成自己喜欢的),python=3.6 是指创建的屋子,是 python3.6 版本。
conda info --envs #看到 conda 环境中,有新建的 pytorch 环境,右边的 * 号表示,当前你处于哪个环境。
conda activate pytorch  #进入 pytorch 环境

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/321305.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号