简体   繁体   English

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

[英]How to verify a tensor contains image data tensorflow

I'm new to tensorflow, so I'm trying to test out my elementary functions first. 我是tensorflow的新手,所以我想先测试一下我的基本函数。 I have the following python method for reading data: 我有以下用于读取数据的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" is a queue of paths to individual jpeg files in an 'images' subdirectory. “ filename_queue”是“ images”子目录中各个jpeg文件的路径队列。 I run a for loop iterating over the filenames to make sure only ones with valid paths get added to the queue: 我运行一个for循环遍历文件名,以确保仅将具有有效路径的文件添加到队列中:

filenames = []
for i in range(1000):
  filename = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                       "./images/seatbelt%d.jpg" % i)
  if not tf.gfile.Exists(filename):
    # print("Filename %s does not exist" % filename)
    continue
  else:
    filenames.append(filename)

# Create a string queue out of all filenames found in local 'images' directory
filename_queue = tf.train.string_input_producer(filenames)

input = read_data(filename_queue)

I'd like to assert that the images are being read in properly and all of the data is contained within the reshaped tensor. 我想断言图像已被正确读取,并且所有数据都包含在重构的张量中。 How could I do this? 我该怎么办?

The code following can show images for my experiment. 以下代码可以显示我的实验图像。 Maybe this can help you. 也许这可以帮助您。

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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM