テンソルフローチュートリアルのcifar-10の畳み込みネットワークコードを自分の画像(さまざまなサイズ)で使用しようとしています。今度は、イメージとラベルがキーとしてイメージ名で別々に格納されます。私はcifar10_input.pyで以下の関数を修正する方法を知りました。ありがとう。共有キーを持つ別々のファイルからテンソルフローでイメージとラベルをバッチに読み込む方法は?
def read_cifar10(filename_queue):
class CIFAR10Record(object):
pass
result = CIFAR10Record()
label_bytes = 1 # 2 for CIFAR-100
result.height = 32
result.width = 32
result.depth = 3
image_bytes = result.height * result.width * result.depth
record_bytes = label_bytes + image_bytes
reader = tf.FixedLengthRecordReader(record_bytes=record_bytes)
result.key, value = reader.read(filename_queue)
record_bytes = tf.decode_raw(value, tf.uint8)
result.label = tf.cast(
tf.slice(record_bytes, [0], [label_bytes]), tf.int32)
depth_major = tf.reshape(tf.slice(record_bytes, [label_bytes], [image_bytes]),
[result.depth, result.height, result.width])
result.uint8image = tf.transpose(depth_major, [1, 2, 0])
return result
あなたの答えをありがとう。私が理解するように、reader.read opは、同じファイルにストアされている場合、イメージとラベルの両方を読み込みます。私の場合は、jpg画像とラベルを保存したファイルしか持っていないので、画像の名前はキーとして機能します。この場合、どのように入力すればいいのですか(画像サイズについての心配はなく、後でサイズを変更できますね) – Penny
https://www.tensorflow.org/versions/r0.9/api_docs/python/image.htmlでjpegを読むこともできます。https://www.tensorflow.org/versions/r0.9/how_tos /reading_data/index.html#reading-from-files –