动手学深度学习——环境搭建

CentOS环境

1、更新系统源

CentOS 7 已于2024年6月30日结束维护,已无法通过系统自带源安装和更新系统文件,可更改为国内系统源来安装和更新系统文件。

  • 进入/etc/yum.repos.d目录下找到 CentOS-Base.repo

  • 将CentOS-Base.repo文件内容更改为阿里源、清华源、中科大源等皆可。

中科大(参考地址:CentOS - USTC Mirror Help)

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
 
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
 
#released updates
[updates]
name=CentOS-$releasever - Updates
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
# mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

清华源

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
 
[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
 
#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

阿里源:

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
或
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
  • 文件源文件更新后,执行如下命令:
yum clean all
rm -rf  /var/cache/yum/
yum makecache
2、安装编译环境
yum groupinstall "Development Tools"
3、安装Python3
# 1、安装Python编译过程中需要的一些依赖包
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
# 3.7以后版本需要
yum install libffi-devel -y
yum install zlib*
 
# 2、创建一个空文件夹并在改文件夹下使用wget从Python的官方网站下载Python 3.8的源码(若需别的版本可以自行找到连接并更改连接)
mkdir install_python
cd install_python
wget https://www.python.org/ftp/python/3.8.12/Python-3.8.12.tgz
 
 
# 3、解压
tar xzf Python-3.8.12.tgz
 
# 4、进入解压目录后编译安装Python 3.8(这里使用--prefix参数安装到/usr/local/python3.8,如需别处可以自行更改)
cd Python-3.8.12
sudo ./configure --prefix=/usr/local/python3.8 --enable-optimizations
# 注意:编译时,gcc版本需要8以上
make
sudo make install
 
# 5、验证安装成功
/usr/local/python3.8/bin/python3.8 --version


# 6、将系统默认的python备份
mv /usr/bin/python /usr/bin/python2.7.5
 
# 7、更改软连接
# (可选)ln -s /usr/local/python3.8/bin/python3.8 /usr/bin/python
ln -s /usr/local/python3.8/bin/python3.8 /usr/bin/python3
 
# 8、验证
python --version

4、安装miniconda
# miniconda官网:https://docs.conda.io/projects/miniconda/en/latest/miniconda官网:https://docs.conda.io/projects/miniconda/en/latest/

mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm -rf ~/miniconda3/miniconda.sh



5、进入base会话
bash
6、使用pip安装jupyter、d2l、torch、torchvison
python3 -m pip install jupyter d2l torch torchvision

这一步安装会有点长,也可以自行换清华源或者其他国内的镜像,可能会快一点。

注意: 安装d2l是可能会报错,可指定版本安装:

pip install d2l==0.17.0
7、安装李沐老师的jupyter记事本
wget https://zh-v2.d2l.ai/d2l-zh.zip
8、安装zip
yum install zip
9、解压d2l-zh.zip
unzip d2l-zh.zip
  • 使用ls查看当前目录,解压出来有三个版本mxnet、pytorch、tensorflow,这里我们使用pytorch版本。
10、从github克隆ppt
git clone https://github.com/d2l-ai/d2l-pytorch-slides
11、启动jupyter
jupyter notebook --allow--root

这里提示成功启动了 Jupyter Notebook 服务器,并且服务器正在运行中。请注意,由于服务器的环境中没有可运行的浏览器,因此会显示错误信息。

我们可以通过以下链接之一访问 Jupyter Notebook 服务器:

http://localhost:8888/tree?token=....
http://127.0.0.1:8888/tree?token=....

请复制其中一个链接并在浏览器中打开,即可开始使用 Jupyter Notebook。如果您想停止服务器,请使用 Ctrl-C 终止命令两次来确认关闭服务器。

12、将远端的jupyter映射到本地

在本地主机上打开终端并执行以下命令,进行端口转发:

ssh -NL 8888:localhost:8888 username@remote_host
# 其中,username 是远程主机的用户名,remote_host 是远程主机的地址

然后就可以在本地浏览器访问刚才的链接了

13、安装rise插件

rise 是一个用于创建幻灯片的 Jupyter Notebook 扩展,它可以将 Jupyter Notebook 转换为交互式幻灯片演示。

pip install rise
### 关于《动手学深度学习》的学习笔记 #### 使用PyTorch框架的实践指南 该书通过具体的编程实例帮助读者理解并掌握深度学习的核心概念和技术。书中不仅涵盖了理论知识,还提供了大量基于Colab平台的实际操作案例[^1]。 #### 配置开发环境的方法推荐 对于希望快速入门的同学来说,在本地搭建Conda虚拟环境是一个不错的选择。这不仅可以避免复杂的Linux系统配置过程,还能确保不同项目之间的依赖项不会相互干扰。具体安装步骤以及常见问题解决办法可参照相关文档说明[^3]。 #### 深入探讨自然语言处理与计算机视觉的区别 虽然两者都可以利用概率模型和机器学习技术来进行建模分析,但由于数据形式的不同——前者主要涉及符号序列而后者则是由像素构成的图像矩阵——因此各自的研究重点和发展方向也有所差异。例如,在NLP领域中更强调语义理解和上下文关联;而在CV方面则侧重于特征提取及模式识别等方面的工作[^2]。 #### 提供丰富的练习题目以巩固所学知识点 除了跟随书籍中的例子外,《动手学深度学习》还附带了许多额外的挑战性任务,旨在让学员能够灵活运用课堂上学到的知识去解决问题。特别是针对那些想要进入知名科技公司工作的求职者而言,熟悉这类实战型试题是非常有益处的[^4]。 ```python import torch from d2l import torch as d2l def softmax(X): X_exp = torch.exp(X) partition = X_exp.sum(1, keepdim=True) return X_exp / partition # The broadcasting mechanism is applied here X = torch.rand((2, 5)) print("原始输入:", X) output = softmax(X) print("经过Softmax变换后的输出:\n", output) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值