python - [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:\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是什么意思?
解决方案
这只是一个警告,而不是错误。您需要将 numpy 降级到 version1.16.4
以使其与当前版本的 tensorflow 兼容。您的安装已完成。
检查最后的输出:Tensor("Sum:0", shape=(), dtype=float32)
python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
以上是使用终端(-c
是命令参数)运行python代码的一种方式。
在此代码中,您首先导入由import tensorflow as tf
.
tf.random.normal([1000, 1000])
[1000, 1000]
输出填充有随机正常值的形状的张量。它从正态分布中输出随机值。
tf.reduce_sum
计算张量维度上元素的总和. 如果 axis 是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]))))"
推荐阅读
- javascript - 如果移动,发送到不同的随机站点数组
- c++ - 使用带有 shared_ptr 的 Clang 线程安全分析
- sql - 对数据库中的所有表启用更改跟踪
- sql - 如何从 SQL 函数返回 nvarchar(150) 列表?
- swift - UIScrollView 不缩放:我错过了什么?
- php - 在 Woocommerce 3+ 中的“我的帐户订单”表中添加自定义列
- .net - 多对多关系实体框架核心db优先
- mongodb - mongodb - $dateFromString 支持多种格式
- excel - 单元格、地址函数的条件格式 Excel 结果
- sql - SQL:左连接 vs CASE 子查询——效率更高