如何验证张量包含图像数据十位数

2024-04-23 06:02:27 发布

您现在位置:Python中文网/ 问答频道 /正文

先测试一下我的基本函数。我有以下python方法来读取数据:

def read_data(filename_queue):

# Whole file reader required for jpeg decoding
  image_reader = tf.WholeFileReader()

# We don't care about the filename, so we ignore the first tuple
  _, image_file = image_reader.read(filename_queue)

# Decode the jpeg images and set them to a universal size 
# so we don't run into "out of bounds" issues down the road 
  image_orig = tf.image.decode_jpeg(image_file, channels=3)

  image = tf.image.resize_images(image_orig, [224, 224])

  return image

“filename_queue”是指向“images”子目录中单个jpeg文件的路径队列。我在文件名上运行一个for循环,以确保只有具有有效路径的文件添加到队列中:

^{pr2}$

我想声明的是,图像被正确地读入,所有的数据都包含在整形后的张量中。我怎么能这么做?在


Tags: theimageforreadsoqueuetffilename
1条回答
网友
1楼 · 发布于 2024-04-23 06:02:27

下面的代码可以为我的实验显示图像。也许这能帮到你。在

import matplotlib.pyplot as plt
import tensorflow as tf
import numpy as np

# ......

sess = tf.Session()
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)

num = 10
for _ in range(num):
    image = sess.run(input)
    plt.imshow(image.astype(np.uint8))
    plt.show()

相关问题 更多 >