代码如下:
import tensorflow as tf
raw_data = tf.gfile.FastGFile("0.png", "rb").read()
image = tf.image.decode_png(raw_data)
image = tf.image.resize_images(image, [28, 28], 0)
with tf.Session() as sess:
print(image)
tf.cast(image, tf.uint8)
print(image)
tf.bitcast(tf.cast(image, dtype=tf.int8), tf.uint8)
print(image)
输出:
Tensor("resize_images/Squeeze:0", shape=(28, 28, ?), dtype=float32)
Tensor("resize_images/Squeeze:0", shape=(28, 28, ?), dtype=float32)
Tensor("resize_images/Squeeze:0", shape=(28, 28, ?), dtype=float32)
我想知道为什么我不能将float32转换为uint8,以及如何更正代码。