概述
得到shape
input_shape = [4,224,224,4]
input = tf.random_normal(input_shape) #转成tensor
inputs_shape = input.get_shape().as_list() #转成list
print(inputs_shape)
[4,224,224,4]
tensor转ndarray
import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np
image_path = r"E:data178955836273545-Back.jpg"
#image_string = open(image_path,'rb').read()
#image_string = tf.gfile.FastGFile(image_path, 'rb').read() # 字节
image_string = tf.io.read_file(image_path)
image = tf.image.decode_jpeg(image_string) # 2.图片解码
with tf.Session() as sess:
print(sess.run(image).shape)
image = image.eval() # 将tensor对象转成数组
print(image.shape)
plt.imshow(image)
plt.show()
image = tf.expand_dims(image, 0)
#image = np.asarray(sess.run(image), dtype='uint8') # TF处理过的图片自动转换了类型,需要调整回uint8才能正常显示,将tensor转为ndarray
image = tf.image.convert_image_dtype(image,dtype=tf.uint8)
image = image.eval()
height, width, channels = image.shape[1:]
image = image.reshape(height, width, channels)
plt.imshow(image)
plt.show()
最后
以上就是传统外套为你收集整理的tf中list和tensor的转换[4,224,224,4]的全部内容,希望文章能够帮你解决tf中list和tensor的转换[4,224,224,4]所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复