Cifar10(バイナリファイル、size = 96*96*3
画像ごとのバイト数)に似た形式の画像がたくさんあります(STL-10 dataset)。開いているファイルのサイズは 138MB です。
画像を含む Tensor の内容を読み取って確認し、読み取りが正しく行われたことを確認しようとしましたが、2 つの質問があります。
FixedLengthRecordReader
ファイル全体をロードしますが、一度に 1 つずつ入力を提供するだけですか?size
最初のバイトの読み取りは比較的高速であるためです。ただし、コードの実行には約 2 分かかります。- 実際の画像コンテンツを表示可能な形式で取得する方法、またはそれらを内部的に表示して画像が適切に読み取られることを検証する方法は? しました
sess.run(uint8image)
が、結果は空です。
コードは以下のとおりです。
import tensorflow as tf
def read_stl10(filename_queue):
class STL10Record(object):
pass
result = STL10Record()
result.height = 96
result.width = 96
result.depth = 3
image_bytes = result.height * result.width * result.depth
record_bytes = image_bytes
reader = tf.FixedLengthRecordReader(record_bytes=record_bytes)
result.key, value = reader.read(filename_queue)
print value
record_bytes = tf.decode_raw(value, tf.uint8)
depth_major = tf.reshape(tf.slice(record_bytes, [0], [image_bytes]),
[result.depth, result.height, result.width])
result.uint8image = tf.transpose(depth_major, [1, 2, 0])
return result
# probably a hack since I should've provided a string tensor
filename_queue = tf.train.string_input_producer(['./data/train_X'])
image = read_stl10(filename_queue)
print image.uint8image
with tf.Session() as sess:
result = sess.run(image.uint8image)
print result, type(result)
出力:
Tensor("ReaderRead:1", shape=TensorShape([]), dtype=string)
Tensor("transpose:0", shape=TensorShape([Dimension(96), Dimension(96), Dimension(3)]), dtype=uint8)
I tensorflow/core/common_runtime/local_device.cc:25] Local device intra op parallelism threads: 4
I tensorflow/core/common_runtime/local_session.cc:45] Local session inter op parallelism threads: 4
[empty line for last print]
Process finished with exit code 137
それが何かを追加する場合、私はこれを私のCPUで実行しています。
編集: Rosa のおかげで純粋な TensorFlow ソリューションを見つけました。どうやら、 を使用する場合string_input_producer
、結果を表示するには、キュー ランナーを初期化する必要があります。上記のコードに追加する必要があるのは、下から 2 行目だけです。
...
with tf.Session() as sess:
tf.train.start_queue_runners(sess=sess)
...
その後、 で画像をresult
表示できますmatplotlib.pyplot.imshow(result)
。これが誰かに役立つことを願っています。さらに質問がある場合は、お気軽に私に尋ねるか、Rosa の回答のリンクを確認してください。