根据官网的介绍,通过pip命令安装tensorflow,步骤很简单。下为官网的链接
https://www.tensorflow.org/install/install_windows
##安装tensorflow
使用下面的命令安装tensorflow。但是注意python应是64位版本的,如果是32位版本的就会报错。会提示如下错误信息“No matching distribution found for tensorflow”
pip install tensorflow
这会选择从官网下载各类文件,速度比较慢。可以使用国内镜像,提高了下载速度
##查看tensorflow版本等信息
pip show tensorflow
Name: tensorflow
Version: 1.5.0
Summary: TensorFlow helps the tensors flow
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: opensource@google.com
License: Apache 2.0
Location: e:\python\lib\site-packages
Requires: numpy, six, wheel, protobuf, tensorflow-tensorboard, absl-py
##卸载tensorflow
pip uninstall tensorflow
##运行第一个例子
运行官网第一个例子时,电脑提示了如下警告
Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
这个警告是说,你安装的这个版本的tensorflow不是适用你这台机器结构的最优的,也就是说,有一些可以利用的性能,但是由于二进制指令没被编译,所以没有被用到。
AVX(Advanced Vector Extensions),AVX,引入了FMA(fused multiply-accumulate)操作,加速线性代数的计算,点乘,矩阵乘,卷积等。几乎每一次机器学习训练都会涉及很多这些操作,所以在支持AVX和FMA的CPU上运行会快到300%。在百度各种帮助之后,发现有如下两个解决办法:
第一,忽视警告,并屏蔽警告。使用如下命令:
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
方案二,从源码安装。下面是给出的解决方案链接。
https://stackoverflow.com/questions/47068709/your-cpu-supports-instructions-that-this-tensorflow-binary-was-not-compiled-to-u?answertab=votes#tab-top
linux 操作系统安装tensorflow
使用命令后
pip install tensorflow
提示下面的错误
could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
查看cuda的版本
# 使用命令nvcc
nvcc -V
# 或者使用 --version
nvcc --version
# 或者直接去cuda的安装目录查看
cat /usr/local/cuda/version.txt
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Sat_Aug_25_21:08:01_CDT_2018
Cuda compilation tools, release 10.0, V10.0.130
查看cuDNN的情况
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
#define CUDNN_MAJOR 7
#define CUDNN_MINOR 6
#define CUDNN_PATCHLEVEL 5
--
#define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL)
#include "driver_types.h"