尽管之前有写安装环境的教程,不过今日发现其中一些步骤还有简化的空间,写此文以记之,愿能给入坑深度学习的新人节省一些时间。
教程将安装以下软件,请读者按需阅读:
前往 Ubuntu 官网下载系统安装包,现推荐 Ubuntu 18.04.3 LTS 稳定版本。
然后使用 U 盘制作启动盘,如果您不熟悉如何制作启动盘,可以参考以下几个教程:
下载的文件类似于ubuntu-18.04.3-desktop-amd64.iso
,大小约 1.9 GB。
制作完成后,把 U 盘插入到您将要安装的电脑上,然后从 U 盘启动电脑(一般来说,在电脑开机的时候,按住F12
)。
具体安装流程可以参考官方教程。
接下来安装 Anaconda,进入官网,在下方选择 Linux,选择 Python 3.7 版本进行下载:
下载的文件类似于Anaconda3-2019.07-Linux-x86_64.sh
,大小约为 542 MB。
接下来安装 Anaconda,您可以参考详细的官方教程,或者进入安装包目录,输入以下命令:
# 注意替换为您下载的实际文件名
bash Anaconda3-*.sh
之后一路回车或yes
,安装完成后,重新打开 Terminal
,输入
anaconda-navigator
打开 Anaconda Navigator 之后,选择左侧的 Environments
选项卡,在右栏中,把下拉框切换为All
,在搜索框中搜索cud
,不出意外的话搜索结果为cudatoolkit
、cudnn
、cupy
。右键点击名字前面的方框,选择Mark for specific version installation
,对于cudatoolkit
,选择10.1.243
,对于cudnn
,选择7.6.0
:
进入官网,选择 PyCharm for Anaconda Community Edition 进行下载:
文件名类似于pycharm-community-anaconda-2019.2.2.tar.gz
,大小约为 435 MB。、
下载完成后,进入下载目录,输入以下指令:
# 注意替换自己实际的文件名
sudo tar xfz pycharm-*.tar.gz -C /opt/
然后进入安装目录,打开 PyCharm:
# 注意替换自己实际的安装目录
cd /opt/pycharm-*/bin
sh pycharm.sh
如果您想在桌面创建 PyCharm 图表,在 PyCharm 主页点击
Tools
>Create Desktop Entry...
即可。
sudo apt-get install --no-install-recommends nvidia-driver
安装完成后,重启系统。
在终端中输入以下指令查看是否安装成功:
nvidia-smi
接下来安装 TensorFlow 2.2.0
作为示例,读者亦可安装其他学习库,例如 PyTorch
等。
pip install tensorflow-gpu==2.2.0
如果下载速度过慢,可以使用临时清华的镜像:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow-gpu==2.2.0
下载的过程中,我们可以在 PyCharm 中导入 Anaconda 所创建的虚拟环境。具体不再赘述。
在终端中进入 Python 环境:
(base) xovee@xovee:~$ python
Python 3.7.3 (default, Mar 27 2019, 22:11:17)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
输入:
import tensorflow as tf
print("GPU Available: ", tf.test.is_gpu_available())
如果输出的最后一行为 GPU Available: True
:
2019-09-23 15:19:01.479144: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-09-23 15:19:01.513322: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2394785000 Hz
2019-09-23 15:19:01.516071: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x5579e6f69df0 executing computations on platform Host. Devices:
2019-09-23 15:19:01.516139: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): Host, Default Version
2019-09-23 15:19:01.520674: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1
2019-09-23 15:19:02.011779: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x5579e6fe08a0 executing computations on platform CUDA. Devices:
2019-09-23 15:19:02.011828: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): GeForce GTX 1080 Ti, Compute Capability 6.1
2019-09-23 15:19:02.011840: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (1): GeForce GTX 1080 Ti, Compute Capability 6.1
2019-09-23 15:19:02.016452: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties:
name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.6575
pciBusID: 0000:03:00.0
2019-09-23 15:19:02.017960: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 1 with properties:
name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.683
pciBusID: 0000:05:00.0
2019-09-23 15:19:02.060333: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.0
2019-09-23 15:19:02.678910: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10.0
2019-09-23 15:19:02.927700: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10.0
2019-09-23 15:19:03.016661: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10.0
2019-09-23 15:19:03.784929: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10.0
2019-09-23 15:19:04.099612: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10.0
2019-09-23 15:19:05.120265: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2019-09-23 15:19:05.123062: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0, 1
2019-09-23 15:19:05.123148: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.0
2019-09-23 15:19:05.147053: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-09-23 15:19:05.147099: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165] 0 1
2019-09-23 15:19:05.147108: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 0: N Y
2019-09-23 15:19:05.147113: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 1: Y N
2019-09-23 15:19:05.149566: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1304] Created TensorFlow device (/device:GPU:0 with 9749 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:03:00.0, compute capability: 6.1)
2019-09-23 15:19:05.151028: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1304] Created TensorFlow device (/device:GPU:1 with 10479 MB memory) -> physical GPU (device: 1, name: GeForce GTX 1080 Ti, pci bus id: 0000:05:00.0, compute capability: 6.1)
GPU Available: True
就意味着,环境搭好啦!!!接下来您可以下载 Chrome、设置中文输入法等,开始深度学习之旅~
如果您有什么问题,可以在评论区或者通过邮件 [email protected] 与我交流。: )