【问题标题】:What does [python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"] do?[python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"] 是做什么的?
【发布时间】:2019-07-31 16:18:55
【问题描述】:

我按照官方网站上的步骤安装了 tensorflow。但是,在站点中,作为安装的最后一步,他们给出了一行代码来“验证安装”。但是他们还没有告诉这个代码会给出什么输出。

该行是:

python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

当我输入这段代码时,我得到以下输出:

C:\Users\joelj\venv\lib\site-packages\tensorflow\python\framework\dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
C:\Users\joelj\venv\lib\site-packages\tensorflow\python\framework\dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
C:\Users\joelj\venv\lib\site-packages\tensorflow\python\framework\dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
C:\Users\joelj\venv\lib\site-packages\tensorflow\python\framework\dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
C:\Users\joelj\venv\lib\site-packages\tensorflow\python\framework\dtypes.py:520: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
C:\Users\joelj\venv\lib\site-packages\tensorflow\python\framework\dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
C:\Users\joelj\venv\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:541: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
C:\Users\joelj\venv\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:542: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
C:\Users\joelj\venv\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:543: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
C:\Users\joelj\venv\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:544: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
C:\Users\joelj\venv\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:545: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
C:\Users\joelj\venv\lib\site-packages\tensorboard\compat\tensorflow_stub\dtypes.py:550: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
Tensor("Sum:0", shape=(), dtype=float32)

我怎么知道安装完成了,这个Output是什么意思?

【问题讨论】:

  • 您不必向我们展示整个错误消息。尽量只向我们展示重要的错误。它将使它更清晰,更易于阅读

标签: python python-3.x tensorflow


【解决方案1】:

这只是一个警告,而不是错误。您需要将 numpy 降级到版本 1.16.4 以使其与当前版本的 tensorflow 兼容。您的安装已完成。

检查最后的输出:Tensor("Sum:0", shape=(), dtype=float32)

python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

以上是使用终端运行python代码的一种方式(-c是命令参数)。

在这段代码中,你首先导入了import tensorflow as tf给出的tensorflow库。

tf.random.normal([1000, 1000]) 输出一个形状为[1000, 1000] 的张量,其中填充了随机正常值。它从正态分布中输出随机值。

tf.reduce_sum 计算张量维度上元素的总和。如果axis为None,则所有维度都被缩减,并返回单个元素的张量。

由于您在没有创建会话的情况下打印结果,这就是您得到输出为Tensor("Sum:0", shape=(), dtype=float32) 的原因。从here 了解 tf.Session()。

为了打印实际结果,运行以下命令:

python -c "import tensorflow as tf; sess=tf.Session(); print(sess.run(tf.reduce_sum(tf.random.normal([1000, 1000]))))"

【讨论】:

【解决方案2】:

命令是调用python执行-c之后的内容。
您可以在输出行中看到FutureWarning,这是由于numpy 将来的版本更新引起的。您可以忽略它们或在 python 中设置以使它们不再输出。
真正的输出是最后一行。并且安装完成

【讨论】:

    【解决方案3】:

    点安装“numpy

    【讨论】:

      猜你喜欢
      • 2019-04-14
      • 2017-03-30
      • 2022-11-10
      • 2011-10-05
      • 1970-01-01
      • 2014-11-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多