当前位置:网站首页>使用d2l包和相关环境配置的一些血泪心得
使用d2l包和相关环境配置的一些血泪心得
2022-07-24 05:15:00 【欣欣草木生】
目录
一 引言
写给:
初学深度学习的同学
缺少环境错误排查经验的同学
以李沐老师B站机器学习课程,dive into deep learning网站为教材学习的同学
以下:
皆为本人所踩的雷 , 也在排查错误中花费了许多时间 , 获得了一些经验
本人使用的cpu版的pytorch
现已经整理碰到的许多的坑 , 也添加了一些自己的分析 , 希望可以帮助到大家
二 关于anaconda的配置
1 anaconda的安装过程
注意点
1 安装的时候最好不要直接安装到c盘(如果c盘空间不富裕的话)
因为它会越来越大 , 直至我重装系统的时候已经有50g大小了
2 安装的时候有个添加到环境变量(add to path)最好勾选上 , 不然可能后边还是要添加到环境变量 , 稍微有些麻烦
2 d2l包和pytorch包的下载
1 创建新环境
最好不要把所有需要的包都直接在base环境里
可以创建一个新环境
创建命令:
conda create -n newd2l python=3.7
newd2l : 这个环境的名称叫做newd2l , 读者可自行更改
py=3.7 : 创建的python版本是3.7
d2l : 这里是l是小写英文字母l , 不是1
提示 : python最好是3.7版本 , 本人起初安装了3.6的版本 , 有一些代码无法运行(因为有更新) , debug好久
例1 本人在3.6中收到 grad can be implicitly created only for scalar outputs的报错 , 但是3.7就可以运行
例2 pip install d2l 搜索到的d2l是0.17.0的版本 , 而不是所需的0.17.5的版本 , 有一些不兼容的地方
2 添加镜像源
为什么要添加镜像源?
anaconda的服务器在境外 , 国内下载速度十分缓慢甚至下载断链失败的情况
使用镜像源可以下载的更快更稳一些
1 . 给conda添加镜像源
按照路径 , 找到 此电脑 - C盘 - 用户 - 你的账户名 - .condarc 文件
如果没找到 , 自己新建一个.condarc文件 , 文件名字是空的 , 就一个.condarc后缀
用记事本方式打开即可
复制并粘贴以下代码以设置镜像源
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- http://pypi.douban.com/simple/
- defaults
show_channel_urls: true
这里添加了3个镜像源 , 自己可以再找别的镜像源按照以上的格式粘贴上去即可
如果你不能修改后缀名
尝试如下操作
以上设置对用conda install 命令来下载包时有效
2 . 给pip添加镜像源
在 此电脑 - C盘 - 用户 - 你的账户名 文件夹里创建一个pip文件夹
在pip 文件夹里创建 pip.ini 文件
记事本方式打开
赋值粘贴以下代码
[global]
index-url = https://pypi.mirrors.ustc.edu.cn/simple/
extra-index-url = https://pypi.mirrors.ustc.edu.cn/simple/
https://mirrors.aliyun.com/pypi/simple/
https://pypi.tuna.tsinghua.edu.cn/simple/
http://pypi.mirrors.ustc.edu.cn/simple/
https://pypi.org/simple/
trusted-host = pypi.mirrors.ustc.edu.cn
pypi.mirrors.ustc.edu.cn
mirrors.aliyun.com
pypi.tuna.tsinghua.edu.cn
pypi.mirrors.ustc.edu.cn
pypi.org
index-url 是设置镜像源 上边设置了多个镜像源
trusted-host 设置信任这些网站
以上设置对用 pip install 命令来下载包时有效
3 . 如果你在科学上网
可以选择暂时关闭科学上网 , 如果执意坚持
还需要设置代理服务器
1 在 .condarc 文件中再添加
proxy_servers:
http: http://127.0.0.1:7893
https: http://127.0.0.1:7893
ssl_verify: false
此处的7893修改成你的端口名
2 在 pip.info 文件中再添加
proxy = http://127.0.0.1:7893
如下图所示

3 d2l包和pytorch包的下载
1 打开anaconda prompt
2 切换到目录二.2.1中你创建的新环境
3 输入 pip install d2l
然后等待 , 如果碰到选择yes or no , 输入y , 敲击回车
等待它下载安装完成
现在d2l 0.17.5 就已经安装好了
4 pytorch的安装
如果你是安装cpu版的torch , 输入
conda install pytorch torchvision torchaudio cpuonly -c pytorch
即可
如果你是安装gpu版的torch , 移步链接
https://zh-v2.d2l.ai/chapter_installation/index.html
有问题请查看评论区和自行搜索
(推荐: gpu更合适
本人由于囊中羞涩 , 无力置换老电脑 , 没有NVIDIA的显卡 , 无奈使用cpu版)
3 kaggle
提供免费算力的宝藏网站
在本人电脑代码由于版本原因出现bug却又找不出原因时 ,
暂时使用了这个网站进行跑代码训练
如何在kaggle中如何导入所需的包?例如d2l?
只要输入
!pip install d2l
点击运行 , 就可以进行d2l这个包的下载了
如果你是属于配置较低的电脑 , 也可以把代码放在这里运行
边栏推荐
猜你喜欢

MGRE and OSPF comprehensive experiment

FRP intranet penetration service usage

Markov random field: definition, properties, maximum a posteriori probability problem, energy minimization problem

【深度学习】(三)图像分类

Update C language notes

熊市抄底指南

Bear market bottoming Guide

Performance test process

Scikit learn -- steps of machine learning application development

c2-随机产生函数种子seed、numpy.random.seed()、tf.random.set_seed学习+转载整理
随机推荐
【sklearn】tree.DecisionTreeClassifier
Learning some contents of vector and iterator
Data annotation learning summary
postgresql:在Docker中运行PostgreSQL + pgAdmin 4
JMeter upload and download files
generator生成器,只生成两个方法
web开发
How can NFT, whose stars enter the market against the market, get out of the independent market?
Hcip day 3 - mGRE experiment
Pointer learning diary (III)
The fourth job: about the usage of cat, grep, cut, sort, uniq, VIM, TR and other commands
How to avoid the most common mistakes when building a knowledge base?
网NN计算能主机系统资e提供的NTCP
Hotel IPTV digital TV system solution
Career planning route
)To feed back to the application layer or into multiple format documents:
)的低字节来反馈给应用层或者成多种格式文档:
Machine vision learning summary
Relational database 10 minutes to understand MySQL
JMeter FAQs