2017-06-22 5 views
0

テンソルフローが初めてのので、まず基本関数をテストしようとしています。私は、データを読み取るための次の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は、」「画像」サブディレクトリ内の個々のJPEGファイルへのパスのキューです。私は、有効なパスを持つものだけがキューに追加されますことを確認するために、ファイル名を繰り返し処理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) 

私は画像が正しく読み込まれていることを主張したいとすべてのデータがあります再構成されたテンソル内に含まれる。どうすればこのことができますか?

答えて

0

次のコードは私の実験用の画像を表示できます。たぶんこれがあなたを助けることができます。

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() 
関連する問題