[python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))" ] 是做什么的?



我在其官方站点中安装了TensorFlow。但是,在网站中,作为安装的最后一步,他们给了"验证安装"的代码行。但是他们尚未告诉该代码作为输出。

行是:

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

当我输入此代码时,我得到了以下输出的以下内容:

C:Usersjoeljvenvlibsite-packagestensorflowpythonframeworkdtypes.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:Usersjoeljvenvlibsite-packagestensorflowpythonframeworkdtypes.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:Usersjoeljvenvlibsite-packagestensorflowpythonframeworkdtypes.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:Usersjoeljvenvlibsite-packagestensorflowpythonframeworkdtypes.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:Usersjoeljvenvlibsite-packagestensorflowpythonframeworkdtypes.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:Usersjoeljvenvlibsite-packagestensorflowpythonframeworkdtypes.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:Usersjoeljvenvlibsite-packagestensorboardcompattensorflow_stubdtypes.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:Usersjoeljvenvlibsite-packagestensorboardcompattensorflow_stubdtypes.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:Usersjoeljvenvlibsite-packagestensorboardcompattensorflow_stubdtypes.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:Usersjoeljvenvlibsite-packagestensorboardcompattensorflow_stubdtypes.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:Usersjoeljvenvlibsite-packagestensorboardcompattensorflow_stubdtypes.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:Usersjoeljvenvlibsite-packagestensorboardcompattensorflow_stubdtypes.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)

我怎么知道安装已经完成,此输出意味着什么?

这只是一个警告,而不是错误。您需要将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计算张量的尺寸元素的总和。如果轴为None,则所有维度都会降低,并且返回具有单个元素的张量。

由于您正在打印结果而不创建会话,这就是为什么您将输出作为Tensor("Sum:0", shape=(), dtype=float32)。从这里阅读有关tf.session((的信息。

为了打印下面的实际结果运行:

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

命令要调用Python执行-c之后的内容。
您可以在输出线路中看到FutureWarning,并由Numpy版本在将来更新引起。您可以忽略它们或在Python中设置以使它们不再输出。
实际输出是上线。并且安装是完成的

pip安装" numpy< 1.17"是解决问题。

最新更新