为什么在图像调整大小后tf.cast不能正常工作?

时间:2017-01-04 19:16:19

标签: tensorflow

我读了一张图片并调整了大小,结果是正确的,但是在转换为uint8之后,这一切都错了。输出图像也是错误的。发生了什么事?

代码如下:

sess = tf.InteractiveSession()

image_filename = "./images/1.jpg"
out_name = "./images/1_resize3.jpg"

sess.run(tf.global_variables_initializer())

with tf.gfile.FastGFile(image_filename, 'r') as f:
    image_data = f.read()

image = tf.image.decode_jpeg(image_data)
image_shape = tf.shape(image)

resized_image_float = tf.image.resize_images(image, [500, 500])

resized_image_uint8 = tf.cast(resized_image_float, tf.uint8)

encode_image = tf.image.encode_jpeg(resized_image_uint8)
save = tf.write_file(out_name, encode_image)

save.run()

但是,如果我确实喜欢下面,它运作良好,但为什么!!! ??

sess.run(tf.global_variables_initializer())

with tf.gfile.FastGFile(image_filename, 'r') as f:
    image_data = f.read()

image = tf.image.decode_jpeg(image_data)
image_shape = tf.shape(image)

resized_image_float = tf.image.resize_images(image, [50, 50])

# This line is different.
t = resized_image_float.eval()

resized_image_uint8 = tf.cast(t, tf.uint8)

# This line is different.
data = resized_image_uint8.eval()

encode_image = tf.image.encode_jpeg(data)

tf.write_file(out_name, encode_image).run()

0 个答案:

没有答案