Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tensorflow-将python.framework.ops.Tensor转换为PNG图像_Tensorflow - Fatal编程技术网

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模式