win10+ubuntu18.04双系统配置深度学习环境

目录

一、双系统安装

1、制作U盘启动盘

2、选择装机位置

3、用U盘装机

二、Windows系统下cuda10.1+cudnn+anoconda+pycharm+tensorflow+pytorch环境搭建

三、Ubuntu18.04系统下cuda10.1+cudnn+anoconda+pycharm+tensorflow+pytorch环境搭建


由于虚拟机对硬件支持不是太好,所以在笔记本上装了双系统,并配置了深度学习环境,折腾了近两天,现在做个简单记录。

一、双系统安装

1、制作U盘启动盘

可以先下载一个ubuntuxxx.iso文件,由于其官网速度可能会比较慢,这里以18.04版本为例,可以到国内镜像源网站直接下载,如http://mirrors.aliyun.com/ubuntu-releases/18.04/。下载完成后,无须多疑,插上U盘(最后先将其格式化),点开ubuntu-18.04.5-desktop-amd64.iso文件,将里面的内容全部复制到U盘即可,当然也可以尝试用其他工具,但能简单一点怎就不简单一点。

2、选择装机位置

再在windows系统里面格式化一块分区用于装ubuntu系统,我这里将1T的机械硬盘分区成两个E和F,最后将系统装在了F盘。步骤大致如下图所示:

win10+ubuntu18.04双系统配置深度学习环境

3、用U盘装机

大概就是重启进入bios,选择用U盘启动。这里大致如这般(进入boot后不同的电脑可能不一样,但目的都一样,将U盘设为启动的第一项)我这儿的示例图中由于时已经装了ubuntu系统的,也会稍有差别:

win10+ubuntu18.04双系统配置深度学习环境

win10+ubuntu18.04双系统配置深度学习环境

进入后,不出意外就会从U盘启动ubuntu系统,但意外总是会有的,本机是拯救者Y7000,独显RTX2060,在启动过程中,会出现花屏的现象。在进入ubuntu系统的时候按e,进入后, 找到“quite splash”,在其后空一格输入nomodeset。

win10+ubuntu18.04双系统配置深度学习环境

win10+ubuntu18.04双系统配置深度学习环境

待其安装完成后,拔掉U盘,开机进入bios选择启动的系统,如果仍然出现花屏,先在GRUB界面,按e,找到“quite splash”,空一格输入nomodeset。进入系统后,在终端输入:sudo gedit /etc/default/grub,找到这行:GRUB_CMDLINE_LINUX_DEFAULT="quiet splash",改成:GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nomodeset" 保存文档,更新GRUB: sudo update-grub。至此,双系统就算安装完成。

二、Windows系统下cuda10.1+cudnn+anoconda+pycharm+tensorflow+pytorch环境搭建

windows上安装cuda比较简单,电脑一般都已经安装好NVIDIA驱动,只需要安装cuda和cudnn即可,在Nvidia官网下载相应的版本,如windows下10.1如下图。

win10+ubuntu18.04双系统配置深度学习环境

Nvidia官网下载cudnn(需要先注册个账号),选择相应的版本,进行下载。这里以cuda10.1为例进行安装,由于官网可能网速比较慢,这里有百度网盘链接,密码li6f。下载完成后,双击exe进行安装。然后解压cudnn,将cudunn对应的lib64、include下的文件移动到的cuda10.1中,安装中如果没有修改路径应该是C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1。我安装的时候,自动加了环境变量,所以这里不再赘述。这里写得比较简略,具体可参考这篇博文,实属优秀,在此表示感谢。至此,cuda环境已有,接下来就是安装pycharm和anoconda,在此表示感谢。然后就是一堆conda命令,即可完成环境搭建,常用命令在此,在此表示感谢。完成环境搭建后,需要注意的是,搭建pytroch环境的时候,在其官网选择相应系统和版本后,推荐的安装指令中,去掉-c pytorch,就不会从pytorch官方下载源安装,而从conda配置的源(国内有很多的)中下载,速度应该会快一点。就是验证环境是否成功,tensorflow-gpu2.3.1和pytorch1.8.1的验证如下:

Microsoft Windows [版本 10.0.19041.867]
(c) 2020 Microsoft Corporation. 保留所有权利。

C:\Users\lee>conda activate tf2

(tf2) C:\Users\lee>python
Python 3.8.0 (default, Nov  6 2019, 16:00:02) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2021-04-04 20:54:47.962721: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudart64_101.dll
>>> print(tf.__version__)
2.3.1
>>> print(tf.test.is_gpu_available())
WARNING:tensorflow:From <stdin>:1: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.config.list_physical_devices('GPU')` instead.
2021-04-04 20:55:15.952168: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations:  AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-04-04 20:55:15.959075: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x28f1c8c9290 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2021-04-04 20:55:15.959113: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2021-04-04 20:55:15.960597: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library nvcuda.dll
2021-04-04 20:55:15.991689: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1716] Found device 0 with properties:
pciBusID: 0000:01:00.0 name: GeForce RTX 2060 computeCapability: 7.5
coreClock: 1.2GHz coreCount: 30 deviceMemorySize: 6.00GiB deviceMemoryBandwidth: 245.91GiB/s
2021-04-04 20:55:15.991837: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudart64_101.dll
2021-04-04 20:55:15.995591: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cublas64_10.dll
2021-04-04 20:55:15.998593: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cufft64_10.dll
2021-04-04 20:55:15.999658: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library curand64_10.dll
2021-04-04 20:55:16.003465: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cusolver64_10.dll
2021-04-04 20:55:16.005307: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cusparse64_10.dll
2021-04-04 20:55:16.012095: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudnn64_7.dll
2021-04-04 20:55:16.012257: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1858] Adding visible gpu devices: 0
2021-04-04 20:55:16.448161: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1257] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-04-04 20:55:16.448257: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1263]      0
2021-04-04 20:55:16.448366: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1276] 0:   N
2021-04-04 20:55:16.449417: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1402] Created TensorFlow device (/device:GPU:0 with 4722 MB memory) -> physical GPU (device: 0, name: GeForce RTX 2060, pci bus id: 0000:01:00.0, compute capability: 7.5)
2021-04-04 20:55:16.452087: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x28f4e1093c0 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2021-04-04 20:55:16.452238: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): GeForce RTX 2060, Compute Capability 7.5
True
>>> exit()

(tf2) C:\Users\lee>conda activate pytorch

(pytorch) C:\Users\lee>python
Python 3.8.8 (default, Feb 24 2021, 15:54:32) [MSC v.1928 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> print(torch.__version__)
1.8.1
>>> print(torch.cuda.is_available())
True

三、Ubuntu18.04系统下cuda10.1+cudnn+anoconda+pycharm+tensorflow+pytorch环境搭建

Ubuntu系统下环境的搭建比windows下多了某些步骤,下载部分同windows,这里同样以cuda10.1为例,附上链接,提取码:4ilr 。过程可见https://blog.csdn.net/ithinking110/article/details/105144202/,其中包含了cuda及cudann的安装,环境变量等等,在此表示感谢。但在安装前需要进入bios禁掉secure boot,我是在禁掉之后才安装成功的,还有就是我安装cuda是通过deb方式安装的,可参见nvidia官网,具体如下:

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/10.1/Prod/local_installers/cuda-repo-ubuntu1804-10-1-local-10.1.243-418.87.00_1.0-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1804-10-1-local-10.1.243-418.87.00_1.0-1_amd64.deb
sudo apt-key add /var/cuda-repo-10-1-local-10.1.243-418.87.00/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda

安装完成后验证同windows,这里不再赘述。至此,双系统windows10+ubuntu18.04+深度学习环境就已经搭建好了,就这些东西,两天的时间东拼西凑,但总有不成功的时候,这里进行汇总。对于文中提到的链接,这里再次表示感谢。

 

上一篇:【号外-福利帖】HBaseCon亚洲2018


下一篇:55. 跳跃游戏 - LeetCode