安装深度学习框架 pytorch、tensorflow
安装深度学习框架 pytorch、tensorflow
tensorflow可以直接pip装,pytorch请务必从这里装https://download.pytorch.org/whl/torch_stable.html下载对应cuda版本编译的安装包,放到服务器里pip install xxxx.whl
1、安装tensorflow
#安装依赖包
(python-3.7) root@7a927d2dc743:~# pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --user pytest-cov==2.0 pytest-filter-subpackage==0.1
#安装指定版本的tensorflow
(python-3.7) root@7a927d2dc743:~# pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow==2.3.0
#验证tensorflow是否安装成功
(python-3.7) root@7a927d2dc743:~# pip show tensorflow
Name: tensorflow
Version: 2.3.0
Summary: TensorFlow is an open source machine learning framework for everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: packages@tensorflow.org
License: Apache 2.0
Location: /usr/local/anaconda3/envs/python-3.7/lib/python3.7/site-packages
Requires: absl-py, astunparse, gast, google-pasta, grpcio, h5py, keras-preprocessing, numpy, opt-einsum, protobuf, scipy, six, tensorboard, tensorflow-estimator, termcolor, wheel, wrapt
Required-by:
2、安装pytorch
#下载对应cuda版本编译的安装包
(python-3.7) root@7a927d2dc743:~# wget -P ./ https://download.pytorch.org/whl/cu102/torch-1.6.0-cp37-cp37m-linux_x86_64.whl
(python-3.7) root@7a927d2dc743:~# ll -d torch-1.6.0-cp37-cp37m-linux_x86_64.whl
-rw-r--r-- 1 root root 748807916 Jul 28 2020 torch-1.6.0-cp37-cp37m-linux_x86_64.whl
#安装下载好的安装包
(python-3.7) root@7a927d2dc743:~# pip install torch-1.6.0-cp37-cp37m-linux_x86_64.whl
Processing ./torch-1.6.0-cp37-cp37m-linux_x86_64.whl
Requirement already satisfied: numpy in /usr/local/anaconda3/lib/python3.7/site-packages (from torch==1.6.0) (1.21.5)
Requirement already satisfied: future in /usr/local/anaconda3/lib/python3.7/site-packages (from torch==1.6.0) (0.18.2)
Installing collected packages: torch
Successfully installed torch-1.6.0
#验证pytorch是否安装成功,这里可以写一个小脚本验证下,如没有报错就是安装成功了
(python-3.7) root@7a927d2dc743:~# vim pytorch.py
(python-3.7) root@7a927d2dc743:~# cat pytorch.py
from __future__ import print_function
import torch
x = torch.rand(5, 3)
print(x)
(python-3.7) root@7a927d2dc743:~# python
python python3 python3-config python3.7 python3.7-config python3.7m python3.7m-config
(python-3.7) root@7a927d2dc743:~# python3.7 pytorch.py
tensor([[0.5560, 0.5296, 0.1896],
[0.5847, 0.7915, 0.7916],
[0.9128, 0.2412, 0.1217],
[0.7183, 0.0343, 0.9444],
[0.3063, 0.0969, 0.9200]])