1、卸载
首先,我们前面已经配好了几乎所有的环境。我们这里采用官网这里最简单的方法来安装。 https://www.tensorflow.org/install/install_linux
要是之前安装过tensorflow的,建议先卸载之前版本的tensorflow。
sudo pip uninstall tensorflow
sudo pip uninstall tensorflow-gpu
conda uninstall tensorflow
conda uninstall tensorflow-gpu
2、pip安装
卸载之后,直接用下面的命令来安装tensorflow
sudo pip install –upgrade –ignore-installed tensorflow-gpu
注意:之前安装的tensorflow是CPU版本的,但是tensorflow有一个问题就是使用GPU训练的模型是不能被CPU版本的TF调用的,会报出如下错误:
tensorflow.python.framework.errors_impl.UnimplementedError: Generic conv implementation only supports NHWC tensor format for now.
也就是说:
tensorflow调用GPU训练的模型,数据格式为NCHW,CPU版本的tf调用时是会出错的。因为CPU只能调用NHWC格式的数据。
您可以检查安装是否完成:
[En]
You can check to see if the installation is complete:
pip list
3、或者conda安装
anaconda search -t conda tensorflow-gpu //搜索安装包
运行后显示以下信息
显示指定安装包的安装源
anaconda show cjj3779/tensorflow-gpu
运行后显示以下信息
只需运行最后一句并安装它。
[En]
Just run the last sentence and install it.
conda install --channel https://conda.anaconda.org/cjj3779 tensorflow-gpu
或者直接指定版本安装:
conda install tensorflow-gpu //这里也可以指定版本,比如conda install tensorflow-gpu==2.1.0
我这里安装的是2.1.0的版本,静静等待安装完成,如果安装出现问题,比如进度卡住了之类的多半是网络不稳定,可以选择切换到国内镜像。
等着完成。然后,我们可以查看安装是否完成:
[En]
Waiting to be finished. Then we can see if the installation is complete:
conda list //查看当前环境下安装的包
4、测试
然后安装它并运行以下代码来验证它。
[En]
Then install it and run the following code to verify it.
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
正确输出Hello, TensorFlow!的话,就表示安装成功啦。
Original: https://blog.csdn.net/zml194849/article/details/121860412
Author: 冰雪棋书
Title: ubuntu Tensorflow安装
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/497091/
转载文章受原作者版权保护。转载请注明原作者出处!