最近在学习李沐老师的《动手学深度学习(Pytorch版)》,试着整理下所学笔记。
学习资源
- 教材:https://zh-v2.d2l.ai/
- 纸质书: https://j.youzan.com/2E82KT(半价购书)
- 视频: https://space.bilibili.com/1567748478/channel/seriesdetail?sid=358497
- 竞赛:https://tianchi.aliyun.com/competition/entrance/231784/introduction?spm=5176.12281973.0.0.7c47106baWMBl3
- OpenI云环境(可直接运行):https://openi.pcl.ac.cn/Datawhale/d2l
1 软件安装及环境配置
1.1 Miniconda的安装及配置
1.1.1 安装Miniconda
- 进入Miniconda — conda documentation,找到Windows installer,点击下载即可。
- 下载好后,修改路径,修改设置,开始安装
1.1.2 Conda更换镜像源
- From the Start menu, search for and open “Anaconda Powershell Prompt.”
- 输入下列代码,新建记事本_ (注意有个小点"."在"condarc"前面)_
notepad .condarc
- 进入上海交通大学Linux用户组软件镜像服务conda镜像源,复制如下内容到记事本中,保存
default_channels:
- https://mirror.sjtu.edu.cn/anaconda/pkgs/r
- https://mirror.sjtu.edu.cn/anaconda/pkgs/main
custom_channels:
conda-forge: https://mirror.sjtu.edu.cn/anaconda/cloud/
pytorch: https://mirror.sjtu.edu.cn/anaconda/cloud/
channels:
- defaults
- 再在Anaconda Powershell Prompt中输入如下代码_ (清除原缓存,以应用镜像源)_
conda clean -i
1.1.3 更换PyPI镜像源
- 打开上海交通大学Linux用户组软件镜像服务PyPI镜像源,复制如下指令
pip config set global.index-url https://mirror.sjtu.edu.cn/pypi/web/simple
- 在Anaconda Powershell Prompt中粘贴运行即可,显示如下内容则完成
_ 补:GPU版本Pytorch镜像源可见:https:/mirrors.sjtug.situ.edu.cn/docs/pytorch-wheels_
_ (但是如果不理解GPU版本Pytorch的话,建议不要安装,此次学习CPU版本足够了)_
1.2 Git的安装与使用
1.2.1 Git的安装和下载
- 打开下载网址Git - Downloading Package (git-scm.com),复制框选位置的链接
- 打开加速地址,将复制的链接粘贴,下载即可
- 打开安装程序后,一直点next即可完成安装。
1.2.2 下载课程Repo
- 在Anaconda Powershell Prompt中运行如下命令,即可在E盘建立工作目录E:\coding\d2l (直接在文件夹中新建也是一样的)
mkdir E:\coding\d2l
- 使用cd命令改变终端路径
cd E:\coding\d2l
- 在当前终端中输入:
git clone https://github.com/d2l-ai/d2l-zh.git # d2l课程资源
git clone https://github.com/d2l-ai/d2l-pytorch-slides.git # d2l幻灯片资源
可能会犯的错误:Anaconda Powershell Prompt一直没关,那么输入上述命令就会报错,提示没有"git"这个命令,那么关闭Anaconda Powershell Prompt,重新打开即可。
- 可选操作:(若出现连接失败)
- ghproxy.com 加速
- –depth=1 减少下载量
使用方法:在clone后加上操作代码
git clone --depth=1 https://ghproxy.com/https://github.com/d2l-ai/d2l-zh.git
git clone --depth=1 https://ghproxy.com/https://github.com/d2l-ai/d2l-pytorch-slides.git # d2l幻灯片资源
实在不行就去d2l-ai/d2l-zh: 《动手学深度学习》:面向中文读者、能运行、可讨论。中英文版被60多个国家的400多所大学用于教学。 (github.com),d2l-ai/d2l-pytorch-slides: Automatically Generated Notebook Slides (github.com)或Datawhale/d2l - d2l - OpenI - 启智AI开源社区提供普惠算力! (pcl.ac.cn)下载
推荐学习:git——计算机教育中缺失的一课 · the missing semester of your cs education
1.3 课程环境搭建
1.3.1 创建与激活Conda环境
- 在Anaconda Powershell Prompt中创建Conda环境
conda create --name d2l python=3.10 # conda 环境创建
其中–name代表创建的环境名称,这里是d2l;并指定Python版本为3.10,(版本3.9是经过d2l测试)。
- 激活(打开)刚创建的Conda环境:
conda activate d2l
若环境从base变到d2l,则说明创建成功
如果需要删除某个Conda环境
1.3.2 Pip安装与展示
- Pip安装课程所需第三方库:
确保环境在d2l中,下载过程中不要使用代理
pip install d2l torch # 必装库
pip install d2l torch torchvision rise # 所有库
其中,
必装的是:
- d2l # 课程代码片段
- torch # 深度学习框架 PyTorch
可选的有:
- torchvision # PyTorch CV工具包
- rise # Notebook Slides插件
ERROR:
我的Python版本是3.10,下载过程中出现error
解决方法:
a. 进入d2l · PyPI,下载d2l-1.0.0b0-py3-none-any.whl
b. 按以下命令,安装本地文件,路径换成你下载文件的本地路径,如:
python -m pip install "E:\Downloads\d2l-1.0.0b0-py3-none-any.whl"
c. 再次安装即可正常
pip install d2l==0.17.6 torch jupyter torchvision rise
- 进入课程路径并查看目录下文件夹
cd E:\coding\d2l #打开课程路径
ls #查看目录下文件夹
再进入课程幻灯片路径
再进入jupyter-notebook,打开slides
自动跳转浏览器,打开slides
- 结束学习时使用:
Ctrl+C # 关闭jupyter-notebook服务