Tensorflow-将python.framework.ops.Tensor转换为PNG图像
是否可以将Tensorflow-将python.framework.ops.Tensor转换为PNG图像,tensorflow,Tensorflow,是否可以将python.framework.ops.Tensor转换为PNG图像 运算是:张量(“layer_1/Tahn:0”,shape=(1,256,256,3),dtype=float32)是 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
python.framework.ops.Tensor
转换为PNG图像
运算是:张量(“layer_1/Tahn:0”,shape=(1,256,256,3),dtype=float32)
是
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_)
使用此张量调用
sess.run(…)
,然后您将得到np.ndarray
,您可以使用首选方法保存np.ndarray
我收到一个错误:失败的预处理错误(回溯请参见上文):尝试使用未初始化的值生成器/解码器\u 1/deconv/过滤器
和[[Node:generator/decoder\u 1/deconv/filter/read=Identity[T=DT\u FLOAT,\u class=[“loc:@generator/decoder\u 1/deconv/filter”],\u device=“/job:localhost/replica:0/task:0/device:CPU:0”](generator/deconcoder\deconv/filter)]
我得到了没有形状的张量。张量(“generator/png:0”,shape=(),dtype=string)
示例添加到回答在sess.run(tf.global\u variables\u initializer())中的代码冻结问题。。我使用CPU模式