是否可以将python.framework.ops.Tensor
转换为PNG图像?
操作是:Tensor("layer_1/Tahn:0", shape=(1, 256, 256, 3), dtype=float32)
答案 0 :(得分:1)
是
tf.image.encode_png(tf.cast((tf.reshape(..., [256, 256, 3]) + 1.) * 127.5), tf.uint8))
示例:强>
import numpy as np
import tensorflow as tf
data = tf.eye(256, batch_shape=[1])
bgr = tf.stack([data, data, data], axis = 3)
png = tf.image.encode_png(tf.cast((tf.reshape(bgr, [256, 256, 3]) + 1.) * 127.5, tf.uint8))
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
png_data_ = sess.run(png)
open("d:/temp.png", 'wb').write(png_data_)