【转】Windows+Ubuntu从双系统安装到CUDA cuDNN docker 配置K210等多模型训练环境
目录
一、系统盘制作
二、Ubuntu20.04 LTS+Windows双系统安装
三、cuda & cuDNN & Docker
四、Anaconda & Pycharm
五、yolov5
六、maix_train
准备
U盘或读卡器+SD卡【最好选用USB3.0或高速SD卡(本人用的是读卡器和SD卡)】
个人PC
新手不要在学校服务器上尝试!
新手不要在学校服务器上尝试!
新手不要在学校服务器上尝试!
一、Ubuntu20.04 LTS 镜像下载 & 启动盘制作
1. Ubuntu 20.04 LTS官方镜像下载地址: https://cn.ubuntu.com/download/desktop
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/efce919476088bd9bd1b881f0f135df2f991befd.png@942w_498h_progressive.webp)
2. 使用SD Memory Card Formatter格式化U盘或SD卡,使用Etcher烧录系统镜像,具体使用方法可移步上一个教程: Jetson nano从烧录系统到DeepStream+TensorRT+yolov5检测CSI摄像头视频 - 哔哩哔哩 (bilibili.com) 只需将镜像换成下好的Ubuntu镜像即可!
二、Ubuntu20.04 LTS+Windows双系统安装
1.重启电脑,按F12或者其它键进入启动项选择,并选择U盘为启动项
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/0d45c459e4eadce61df02f9a958b9a7eb66065e9.jpg@942w_707h_progressive.webp)
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/080ad85acd5593d4c6ee33310fa1241ce05eb17b.jpg@942w_707h_progressive.webp)
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/b87b3f1d25cb7cf4cb3e533a8f7f86cd8e4f891b.jpg@942w_707h_progressive.webp)
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/6208437bb39873b22ea11533ea43972f213d8688.jpg@942w_707h_progressive.webp)
下面进入分区步骤,谨慎操作,数据无价!!!
下面进入分区步骤,谨慎操作,数据无价!!!
下面进入分区步骤,谨慎操作,数据无价!!!
2. 第一种情况:重装Ubutnu或者整块空磁盘,可选择清空整块磁盘,高级选项选无即可。
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/48641619a97bbe1ce8955d36617e025405502407.jpg@942w_707h_progressive.webp)
3.下一步选择要安装的磁盘位置,此方法仅适用空磁盘没有其他系统或分区的,如有问题看4,5步
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/a1b2112fe8e1f750fcf3f1f85103392021ed13d6.jpg@942w_707h_progressive.webp)
4.第二种情况Windows或其他系统与Ubuntu共用磁盘,需要提前压缩磁盘,留出连续空闲空间
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/a1f32f361b51691d84cc4e0749e709fd64462312.jpg@942w_707h_progressive.webp)
5.选择要安装的其他,在空闲空间(free space) 依次创建EFI System Partition (ESP)、Ext4 journaling file system、swap area (交换分区,可选)
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/3d080c5084da7436e8c7c94635c0b4f7a72f363e.jpg@942w_707h_progressive.webp)
EFI分区512MB即可
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/69f4359986512771125ab7ae5505fb264bf8f259.jpg@942w_707h_progressive.webp)
Ext4分区选最大,或留出8~16GB做swap分区,swap分区大小跟电脑内存(RAM)大小相同即可,不建议将/home目录单独分区。并挂载到系统跟目录 /
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/8d86d3cd2d970059554f125aa7dfdca4a671ef50.jpg@942w_707h_progressive.webp)
swap分区可选,用作swap分区
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/c3df977ef3717485a69f40c27d8687cf55f20ed5.jpg@942w_707h_progressive.webp)
将Device for boot loader installation选择为EFI分区,并检查主分区是否挂载至根目录!
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/2843a55919c331251d905544eb0c7c638e2649d5.jpg@942w_707h_progressive.webp)
6.双系统请勿随便删除其他非空分区、主分区、逻辑分区,双系统必须在Windows磁盘管理中压缩空间成未分配状态,以防误删。再次检查确认无误后点继续!
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/b1b02171eadd59c2213547bba08a4494985fff95.jpg@942w_707h_progressive.webp)
7.时区这里选择上海(Shanghai)
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/dc84602e1711782d1c5052193c942e0ed55df325.jpg@942w_707h_progressive.webp)
8. 用户名、主机名、简短容易辨识即可
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/53ea45dc61b40b55a8704c11f20bc4344ae37a99.jpg@942w_707h_progressive.webp)
9.等待安装结束~~~
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/754dcbcb81baaabd1917e121820d0d91c8cfd411.jpg@942w_707h_progressive.webp)
10. 安装完成,提示拔出U盘 按回车重启
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/655ed99ee0efea9a684dd2cedd3459332da145a3.jpg@942w_707h_progressive.webp)
进入启动项,选择刚才安装的Ubuntu,如果需要修改启动顺序,自行在Bios中修改
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/c1b0bc0f26f389a91de43eaea89d404f94e1d6b8.jpg@942w_707h_progressive.webp)
这里选择Ubuntu即可,如需进入Windows选第三个
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/6a87b736807d2de3d12a295464a49ff8c06008a9.jpg@942w_707h_progressive.webp)
三、cuda & cuDNN & Docker
cuda cuDNN仅限有NVIDIA独立显卡安装 没有或仅训练k210模型可跳至 四
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/5594dbe228b841db3022c3c14bbbb8109d5fb217.png@942w_531h_progressive.webp)
打开Software & Updates 选择Additional Drivers,可能会出现与我相同的情况,选项为灰色,具体参考Ubuntu社区此帖,https://ubuntu-mate.community/t/no-proprietary-drivers-are-in-use-ubuntu-drivers-list-no-output/23204 此前没有遇到此类问题。
在终端执行sudo ubuntu-drivers autoinstall即可,本以为系统又要重装
然后选择最新的显卡驱动 版本465 cuda11.3 重启即可
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/7f50eb443fed1a9aa5c333c5c00f160fea4fc9f9.png@942w_531h_progressive.webp)
输入nvidia-smi即可查看cuda版本11.3 记住这个版本号,装cuda版本只能小于或等于此版本,建议安装较新的,需要低版本可以通过anaconda中的cudatoolkit解决。anaconda安装配置环境在下面。如果不使用基础环境中的cuda cuDNN可跳过此步骤!
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/93c8f6c23266ac3efba8e5fd17ad762e0cbc924d.png@942w_531h_progressive.webp)
从NVIDIA官网,cuda11.3安装界面。
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/eb737096ac8fcfc2153e9fc202faed4cb211145a.png@942w_515h_progressive.webp)
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/bb87a3ab906d9fac490b28b749b5c7eaad865772.png@942w_531h_progressive.webp)
如遇到下载失败,自行删除失败文件,重新下载
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/e2b44224e5c2ed8bb38cf4233893408818d54960.png@942w_531h_progressive.webp)
deb (local)成功率最高,不建议尝试deb (network) 和runfile loacl,安装过程稍慢,请耐心等待,不要Ctrl C终止或关闭终端。
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/48ff7ad155537872aaec14a45aab34c5f2acb9da.png@942w_531h_progressive.webp)
安装完成之后,加入到环境变量,可用gedit或vim编辑,vim可用sudo apt install vim安装,具体使用方法,参考上一篇帖子,
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/0a5cea83e89e4ab8cfa75e90633878c3bf871590.png@942w_531h_progressive.webp)
注意cuda版本是11.3,保存退出,输入source .bashrc,输入nvcc -V 即可查看cuda版本。
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/c6c75a6e08c4db59b952641f57297fa9b3e33336.png@942w_531h_progressive.webp)
接下来安装cuDNN,需要注册账号,建议选用deb方式安装。https://developer.nvidia.com/cuda-download-survey
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/6953cee0f27f7295d7da0fb999850a1c0350cf59.png@942w_531h_progressive.webp)
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/f11e1a61ed1275d655fdf1c0a6d2cb8cfb0d7110.png@942w_531h_progressive.webp)
依次下载、用sudo dpkg -i *.deb方式安装
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/c6bec98b76663273ca2cbff4d2e08881c4b6bc4e.png@942w_531h_progressive.webp)
然后安装docker,https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#docker
没有curl先sudo apt install curl,然后按照命令依次按照即可,注意不要执行Note里面关于wsl2的命令
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/f6cd522a472ebf4a85e6892f1b67f541c0e78edf.png@942w_531h_progressive.webp)
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/cdb7df118dc0184e1c740fed09a67285186f1f2a.png@942w_531h_progressive.webp)
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/034e7b6ec33540e9aa61ce370e92c354dfa989d0.png@942w_531h_progressive.webp)
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/4590c92e4f8cf13332df1e9ce1a3a54775b2b6ca.png@942w_531h_progressive.webp)
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/e19ea2717721a30ba61193e1944f95b64f451f7b.png@942w_531h_progressive.webp)
安装完成,重启docker服务
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/3cbeffadafe93325ea4afbbd5cac185172a69f89.png@942w_531h_progressive.webp)
输入sudo docker ps -a 即可查看当前运行的容器
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/91e8bc7fa3a31e30b9caaf580bcae73c375502e3.png@942w_531h_progressive.webp)
更多Docker容器 可访问官网https://ngc.nvidia.com/catalog 查看,docker使用非常方便,官方提供各种配好的机器学习框架,计算机视觉等包,拉取即用。
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/307f2dd26f29b0fc2666f8b38eaf3e57e24401b8.png@942w_531h_progressive.webp)
四、Anaconda & Pycharm
另一种就是anaconda虚拟环境,也能够很方便的管理包,可以使用cudatoolkit而取代基础环境中的cuda cuDNN 从而避免以上繁琐的过程
https://www.anaconda.com/products/individual#Downloads
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/ead0ef6c4040c6712e90227d5088641edfb30200.png@942w_531h_progressive.webp)
下载Linux-64位版本,先chmod a+x ./Anaconda3-2021.05-Linux-x86_64.sh提权,然后./Anaconda3-2021.05-Linux-x86_64.sh
注意!不要使用sudo sh命令,否则会安装到root下。
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/9e209d08eaa81e77cf07cce48660761fd98e44a8.png@942w_531h_progressive.webp)
第一个选yes
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/c501b1f64b20dbae0a9e2841c777d576dcf01abe.png@942w_531h_progressive.webp)
安装目录默认即可
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/3e8533a9274be2ffffcb2050874f543dd2be8404.png@942w_531h_progressive.webp)
第二个也要选yes添加到环境变量,
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/0ccc46f44f1d6ce129637439d8044c7feb8a6cd5.png@942w_531h_progressive.webp)
重启终端,可以看见用户名前多了(base)代表基础环境,输入anaconda-navigator即可进入anaconda图形界面
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/325ae75c15585410a1e08ca3bd9ee5c72fe69841.png@942w_531h_progressive.webp)
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/542195e97396080f38d299a27ce89235a1777397.png@942w_531h_progressive.webp)
然后是Pycharm安装,相较于vscode我更推荐用,
https://www.jetbrains.com/pycharm/download/#section=linux
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/924f772db33afc4cdfebe8e5f135300da0e69fd4.png@942w_531h_progressive.webp)
将下载好的压缩包,解压至Home目录下
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/7193950fd5a4722d339ec0139a9812d25c9d3357.png@942w_531h_progressive.webp)
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/655b15b04cada6032ba6d75793d640790868b695.png@942w_531h_progressive.webp)
进入,bin文件夹,./pycharm.sh 启动
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/da9aef68f8da4deab008786f130fed1d9ccf1306.png@942w_531h_progressive.webp)
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/0fe8c4fd94eeb987376dc024f9dabaf5caacfe63.png@942w_531h_progressive.webp)
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/b9da035d2b0894b11a6fe8d0c44bb3fc4b14a52a.png@942w_531h_progressive.webp)
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/d4823886df07a3790b4c68b1f34eb67dcd702666.png@942w_531h_progressive.webp)
安装完成之后,sudo apt install git 可在Pycharm中拉取项目
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/1ef893af69ebc29f1065ea1ddd6009a80efc941e.png@942w_531h_progressive.webp)
五、yolov5
拉取yolov5项目 仅训练k210模型可跳过次步骤
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/a6d1e70bfbce9f439811346e05223c6279cea680.png@942w_531h_progressive.webp)
这里选择取消 不创建Pycharm的虚拟环境
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/79fac035d07e14b32477cc1ba1db2505ba472de3.png@942w_531h_progressive.webp)
在File-Setting-Project-Python Interpreter-Add 中选择Conda Enviroment-New environment Python版本选择项目兼容的,
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/1fbb38c00f33eb76590d5445a6c4c54461d9b393.png@942w_531h_progressive.webp)
pip install -r requiremnets.txt -i https://mirror.baidu.com/pypi/simple
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/59e6e86e9cf49ac76fb8e02d9ffd63d3b31b7de8.png@942w_531h_progressive.webp)
python detect.py
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/f528f3951ae502953e088b03e0a125361d2be718.png@942w_531h_progressive.webp)
关于DarkNet框架编译,请参考我的上一篇教程,编译之前,需要安装cmake make libopencv-dev等包,可自行sudo apt install xxx安装
六、maix_train
接下来进入maix_train环境配置
项目地址:https://github.com/sipeed/maix_train.git
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/6dd0df9e02a27219a1feeb523051e4d0c9c2e1c5.png@942w_531h_progressive.webp)
Python version 3.8
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/6fc89dfb73bed8a04427e68f428ae7d632305bec.png@942w_531h_progressive.webp)
创建好之后点 + 号
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/59659aef7de66e8bb558584dcf2c7355b3025f43.png@942w_531h_progressive.webp)
搜索tensorflow,有NVIDIA的GPU选择tensorflow-gpu版本,没有选tensorflow即可版本号为2.4.1
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/41207ea6abf2add5f502973e95de1d60c2b22938.png@942w_531h_progressive.webp)
然后,pip install -r requiremnets.txt -i https://mirror.baidu.com/pypi/simple 安装剩下的包
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/2b48efe36eb0972bc34d56ae4036c2adf44f6b5b.png@942w_531h_progressive.webp)
训练之前,先按照说明去nncase的GitHub 下载ncc v0.1.0 RC5 的Linux 版本,并解压到tools/ncc/ncc_v0.1目录下,注意不要套目录
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/5cd90c72a0fff67429a569eec452476bba557b1e.png@942w_498h_progressive.webp)
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/b10b7c5a06040e12bfcb85a65b84c0bdb5e34ac5.png@942w_531h_progressive.webp)
训练之前,先python train.py init 生成配置文件,配置文件中包含epoch 等参数
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/3f5a5e901fd7c288ac1032fc5f2ae0e7c9b2fd89.png@942w_531h_progressive.webp)
这里有分类模型和检测模型可选,我这里选的是检测模型
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/910c7edc9a4a35ad7efd29a19f57c3cdca2674f7.png@942w_531h_progressive.webp)
训练结束后,会在out目录生成模型和脚本文件
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/68f39f31f32b4de0c53bc99eea39a102f2b90b2e.png@942w_531h_progressive.webp)
修改boot.py 倒数第6行,为"/sd/m.kmodel" 复制到sd卡,插入烧好Maixpy固件的k210开发板即可运行!
![高性能工作站服务器找我们 高性能工作站服务器找我们](http://i0.hdslb.com/bfs/article/53008e7104888809affc38697c81921dab911fb4.jpg@942w_707h_progressive.webp)
写到最后,大部分深度学习项目,均可通过以上方法在Pycharm中用anaconda环境配置,相较于社区版,Pycharm专业版有更多的功能,使用docker容器也是非常方便,直接拉取就能使用。
https://www.bilibili.com/read/cv12141390/