Ubuntu 20.4 安装测试Tenserflow 2

7 篇文章 0 订阅
5 篇文章 0 订阅

官方中文网站:

TensorFlow了解如何在您的系统上安装 TensorFlow。下载 pip 软件包,在 Docker 容器中运行或从源代码构建。在支持的卡上启用 GPU。https://tensorflow.google.cn/install

前提:

安装了cuda 和cudnn;否则就只能安装cpu版本的tensorflow了

 炸一下当前可选版本:

pip install tensorflow==7777

 

本地安装tensorflow gpu 版本的命令:

$ pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple

$ pip install tensorflow-gpu -i https://pypi.tuna.tsinghua.edu.cn/simple

 [2023年,最新的tensorflow不需要 tensorflow-gpu了,都使用 pip install tensorflow 即可,这包含了gpu版本;】

本地安装tensorflow cpu 版本的命令:

$ pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple

$ pip install tensorflow==2.11.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

测试:

    进入ipython3后测试,

In [1]: import tensorflow as tf

In [2]: from tensorflow import keras

In [3]: a = tf.constant([1,3,7])

In [4]: a
Out[4]: <tf.Tensor: shape=(3,), dtype=int32, numpy=array([1, 3, 7], dtype=int32)>

In [5]: a.shape
Out[5]: TensorShape([3])

In [6]: print(a)
tf.Tensor([1 3 7], shape=(3,), dtype=int32)

In [7]: a.device
Out[7]: '/job:localhost/replica:0/task:0/device:GPU:0'

In [8]: net_1 = keras.layers.Dense(100)

In [9]: net_1
Out[9]: <keras.layers.core.dense.Dense at 0x7fb85c412940>

In [10]: net_1.device
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-10-f73786dcf74c> in <module>
----> 1 net_1.device

AttributeError: 'Dense' object has no attribute 'device'

In [11]: print(net_1)
<keras.layers.core.dense.Dense object at 0x7fb85c412940>

In [12]:

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值