深度学习环境搭建(六)—— Pytorch/TensorFlow

2020-10-31  本文已影响0人  YNWA_Liverpool

这部分我们要安装深度学习中最常用的两个框架,Pytorch和TensorFlow。目前Pytorch最新的版本为1.7,TensorFlow最新版本为2.3。但这里不推荐安装最新版,因为最新版一般会很不稳定,对硬件和其他Python包的支持也不是很好。推荐安装Pytorch 1.6和TensorFlow 2.1。关于Pytorch与TensorFlow之间孰优孰劣不在本文的讨论范围内。

1. 用conda创建python虚拟环境

使用conda命令可以创建虚拟环境,不同虚拟环境之间的安装包不会互相影响。

conda create -n tensorflow2 python=3.7

这里我们创建一个名为tensorflow2的虚拟环境,python版本为3.7.

source activate tensorflow2
image.png

注意这里左边括号里显示目前的虚拟环境为tensorflow2

2. 安装TensorFlow:

pip install tensorflow-gpu==2.1.0

在虚拟环境中安装TensorFlow 2.1和其他需要的安装包。

(tensorflow2) ➜ python
Python 3.7.9 (default, Aug 31 2020, 07:22:35)
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tensorflow.__version__
2.1.0
>>> tensorflow.test.is_gpu_available()
True
>>>

如果出现上面的信息,则说明安装成功。

3. 安装Pytorch

安装过程与上述第1步和第2步类似。

conda create -n pytorch python=3.7
source activate pytorch
image.png
(pytorch) ➜ python
Python 3.7.9 (default, Aug 31 2020, 07:22:35)
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> pytorch.__version__
1.7.0
>>> torch.cuda.is_available()
True
>>>

4. 常用命令

source activate xxx
source deactivate
conda list
pip list
上一篇下一篇

猜你喜欢

热点阅读