【Linux Mint 深度学习开发环境搭建】多深度学习框架融合环境

发布时间:2026/7/28 21:45:34
【Linux Mint 深度学习开发环境搭建】多深度学习框架融合环境 系列文章目录第一章 Linux mint 深度学习开发环境搭建之Nvidia显卡相关软件安装第二章 Linux mint 深度学习开发环境搭建之开发软件安装第三章 Linux mint 深度学习开发环境搭建之多深度学习框架融合环境文章目录系列文章目录前言一、搭建步骤(1)拉取合适的基础镜像(2)安装anaconda(3)安装pytorch环境(4)安装tensorFlow(5)安装caffe(7)安装mxnet(8)安装ssh、xrdp前言前文已经介绍了进行深度学习所需要的显卡环境以及编码IDE的安装本章节将搭建一个多深度学习框架环境搭建此环境所要达到的目的是多个项目所需训练环境不同要将caffeTensorFlowpytorch可以在别台电脑上轻易复现免去重新搭建环境的时间。基于这些前置要求我初步打算拉取一个ubuntu镜像在镜像中安装anaconda利用conda环境隔离多个深度学习框架。一、搭建步骤(1)拉取合适的基础镜像要使所有的深度学习框架在镜像中都能用GPU训练加速我们希望尽量在一个已经比较成型的镜像上再做操作。所以我们先上dockerhub上寻找合适的镜像image。点击下面链接进入dockerhub官网dockerhub在上面的搜索框中输入nvidia/cuda搜索点击第一项进入点击Tags输入ubuntu20.04搜索下拉找到11.5.1-cudnn8-devel-ubuntu20.04这个即为cuda11.5.1cudnn8的ubuntu20.04环境。点击右方的复制图标可将拉取命令复制到剪切板在终端下右击鼠标粘贴命令回车执行如果网速好的话很快就拉取成功了。当然你也可以在portainer中的image中拉取。进入portainer点击 Add container创建一个container。输入相关的配置需求如下方红框所示点击publish a new network port来增加映射的端口最好多映射几个22端口是ssh用来远程连接的端口。3389端口则是远程桌面其他端口有时候可以用tensorboard进行监控训练状况。补充交互功能等添加挂载目录第一行填容器中的路径第二行填物理机中的路径点击Deploy the container生成容器点击红框处进入点击Connect进入终端可以输入命令测试结果如图所示cuda版本11.5cudnn版本8.3.3可看到挂载的物理机上的目录nvcc-Vcat/usr/include/cudnn_version.h|grepCUDNN_MAJOR-A2(2)安装anaconda更新源aptupdateaptupgrade安装vimaptinstallvim下载anaconda并安装./Anaconda3-2022.10-Linux-x86_64.sh最后一步要选择“no”You can undo this by running conda init--reverse$SHELL?[yes|no][no]no You have chosen to not have conda modify your shell scripts at all. To activate condas base environment in your current shell session: eval $(/root/miniconda3/bin/conda shell.YOUR_SHELL_NAME hook) To install condas shell functionsforeasier access, first activate, then: conda init/root/miniconda3/bin/conda initbashsource~/.bashrcconda config--setauto_activate_basefalse这样既保留了 conda activate 的能力又不会每次一开终端提示符前面就挂个 (base)。这是最省心的组合比死守着不 init 要好用得多。替换conda源vim~/.condarcchannels: - defaults show_channel_urls:truedefault_channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2 custom_channels: conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud(3)安装pytorch环境创建名为pytorch1.6.0的conda环境提示要安装相关依赖回车conda create-npytorch1.6.0python3.8启动环境sourceactivate pytorch1.6.0安装pytorch1.6.0版本提示安装回车condainstallpytorch1.6.0torchvision0.7.0torchaudio0.6.0cudatoolkit10.2-cpytorch(4)安装tensorFlow创建名为tensorflow1.14.0的环境conda create-ntensorflow1.14.0python3.7启动环境sourceactivate tensorflow1.14.0安装tensorflowcondainstalltensorflow-gpu1.14.0cudatoolkit10.1(5)安装caffe创建caffe环境caffe对python3兼容不好还是选择python2.7环境注意caffe-gpu安装版本是1.0但是实测这个caffe版本似乎是有问题的caffe1.0版本是带有depthwiseconvolution层即深度分离卷积层。但这个版本的caffe不能识别建议还是从官网下载当然了顺便说一句2020年caffe就已经停止了维护更新conda create-ncaffe-cdefaultspython2.7caffe-gpu默认安装的是cuda10.0启动环境sourceactivate caffe(7)安装mxnet创建mxnet1.7.0版本的环境conda create-nmxnet1.7.0python3.7启动环境sourceactivate mxnet1.7.0安装mxnet1.7.0pipinstallmxnet-cu1021.7.0安装cudatoolkit10.2condainstallcudatoolkit10.2(8)安装ssh、xrdp在终端下输入以下命令根据提示修改root的密码此处修改为rootpasswd在终端下输入命令安装ssh、xrdp、netstat注意xfce4安装过程中会让你选择默认的显示管理器。gdm和lightdm二选一我们选择lightdmaptinstallopenssh-server xrdp net-tools xfce4 xfce4-terminal配置xfce4将xfce4-session写入echoxfce4-session~/.xsession配置sshvim/etc/ssh/sshd_config确认下面红框内的相关项打开将ssh、xrdp默认容器开机启动进入/etc/profile.d下,创建一个脚本文件vim/etc/profile.d/start_ssh_xrdp.sh按下i键进入vim的输入模式将下面文本粘贴进去粘贴完后保存退出res$(netstat-tunlp2/dev/null|grep22)if[$res];thenservicesshstartfires$(netstat-tunlp2/dev/null|grep3389)if[$res];thenif[-f/var/run/xrdp/xrdp.pid];thenrm/var/run/xrdp/xrdp.pidfiservicexrdp restartfi打开bashrc将这个脚本设置为容器启动。vim~/.bashrc将下面语句加到bashrc的最后一行bash/etc/profile.d/start_ssh_xrdp.sh重启容器在其他linux主机的终端下输入以下命令可以测试远程端口是否配置成功。此处10.10.161.121为所配置容器的ip地址。7000是预先映射的与端口号22相通的端口号sshroot10.10.161.121-p7000成功连接如图所示在其他windowspc上搜索并打开远程桌面连接。在计算机(C):栏中输入IP地址端口号。ip地址可以通过在mint终端下输入ipconfig查到。端口号为之前开启容器时3389所映射的端口号。点击连接username和password均为root。输入后点击OK进入界面在桌面右击选择Applications→Settings→Settings Manager→Preferred Applications。设置后在桌面右击选择Open Terminal Here即可打开终端