Tensorflow2下载与安装

Tensorflow2有哪些改变

在深度学习领域,谷歌的TensorFlow可以说是最为出名的开源工具。它的出现使得深度学习的门槛大大降低,不仅人工智能专家,就连最普通的科研人员和对深度学习不是很在行的开发人员,都可以轻易利用它来开发出AI程序。
但是随着时间的推移和对TensorFlow构建和使用更为广泛,TensorFlow的缺点也日益暴露出来。例如所使用的中级和高级API过多(layers层和slim层哪个应用的更为广泛),基础深度学习模型的缺乏以及代码编写得过于冗长和混乱。
为了解决这些问题,并且为了更加符合Python“不要重复造轮子”的主题,TensorFlow 2.0大力删除了一些本身重复的API,把一些外围以及编写完的能够被TensorFlow复用的API大胆地引入并进行替代,例如使用keras.layers替代自己本身的tf.layers层。

下载与安装

  1. 在线安装
pip install tensorflwo2.2.0

但是根据之前的经验,在线安装非常慢,而且很容易出问题,因此强烈建议离线安装。

  1. 离线安装
    (1)由于之前安装过1.9,所以先卸载
pip uninstall tensorflow

Tensorflow2下载与安装_第1张图片
(2)下载最新版本Tensorflow

由于我Anaconda的Python版本是3.7因此我选择cp37
在这里插入图片描述
(3)安装

pip install tensorflow_gpu-2.2.0-cp37-cp37m-win_amd64.whl

(4)报错
报错信息1:

ERROR: distributed 1.21.8 requires msgpack, which is not installed.
ERROR: tensorflow 1.9.0 has requirement tensorboard<1.10.0,>=1.9.0, but you'll have tensorboard 2.2.1 which is incompatible.
ERROR: tensorboard 2.2.1 has requirement grpcio>=1.24.3, but you'll have grpcio 1.21.1 which is incompatible.
ERROR: tensorboard 2.2.1 has requirement setuptools>=41.0.0, but you'll have setuptools 39.1.0 which is incompatible.
ERROR: google-auth 1.15.0 has requirement setuptools>=40.3.0, but you'll have setuptools 39.1.0 which is incompatible.

这几个错很明显,只要更新版本即可

pip install --upgrade msgpack
pip install --upgrade grpcio
pip install --upgrade setuptools

报错信息2:

ERROR: Cannot uninstall 'wrapt'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

这个报错信息也很明显,只要下载wrapt即可

pip install wrapt --ignore-installed

至此,成功安装Tensorflw2.2.0

测试

import tensorflow as tf

报错:

ImportError: Could not find the DLL(s) 'msvcp140_1.dll'. TensorFlow requires that these DLLs be installed in a directory that is named in your %PATH% environment variable. You may install these DLLs by downloading "Microsoft C++ Redistributable for Visual Studio 2015, 2017 and 2019" for your platform from this URL: https://support.microsoft.com/help/2977003/the-latest-supported-visual-c-downloads

报错信息很明显,缺少msvcp140_1.dll文件
去这里下载并安装即可
Tensorflow2下载与安装_第2张图片
至此,可以成功使用Tensorflow2了
Tensorflow2下载与安装_第3张图片

你可能感兴趣的:(TensorFlow)