python - tensorflow tf.cast 的奇怪行为
问题描述
tf.cast
有没有人在整数和无符号整数之间有奇怪的行为?我运行以下示例(在 上https://colab.research.google.com
):
import tensorflow as tf
c = tf.constant([5, 6, 7, 8, 9, 10], dtype=tf.int32)
x = tf.cast(c, dtype=tf.uint32)
with tf.Session() as sess:
x_raw = sess.run(x)
print(x_raw.dtype)
print(x_raw)
print(tf.__version__)
并得到结果:
uint32
[0 0 0 0 0 0]
1.14.0-rc1
我是否以错误的方式使用演员表?或者 TF 中的类型转换是否存在一些错误?
- - - - - - - - - 更新 - - - - - - - - -
有些人可能已经运行了上面的代码并得到了正确的结果。实际上,当我只运行一次(在笔记本单元中)时,我也得到了正确的,但如果你再次运行单元,它会让你大吃一惊。重新创建事件的更好方法可能是运行以下命令:
import tensorflow as tf
c = tf.constant([5, 6, 7, 8, 9, 10], dtype=tf.int32)
d = tf.constant([5, 6, 7, 8, 9, 10], dtype=tf.int32)
x = tf.cast(c, dtype=tf.uint32)
y = tf.cast(c, dtype=tf.uint32)
with tf.Session() as sess:
x_raw, y_raw = sess.run([x, y])
print(x_raw.dtype, y_raw.dtype)
print(x_raw)
print(y_raw)
print(tf.__version__)
在我的情况下,这将保证一个错误。似乎 TF 运行时发生了一些非常臭的事情......
解决方案
推荐阅读
- reactjs - 单击上传的图像反应时图像轮播未加载
- android-studio - Android Studio 调试是否与 API 23-26 不兼容?
- android - 尝试从要显示在 ListView 中的字符串列表中读取项目时出错
- mysql - mysql 选择有限制的行,但也包括超过限制的相同投票的用户
- python - Django:切换活跃用户
- java - “选择更新”并使用悲观锁定更新
- python - 将字典行插入数据库
- javascript - 如何使用“。”从 javascript 访问 html 中的字典值 操作员?
- python - 在 for 循环理解中分配默认值以及设置交集
- node.js - 子类函数的返回类型