私はTensorflowを初めて使い、build_image_data.py
ファイルとチュートリアルhereを使用しました。TFRecordファイルから正しくレコードを読み込めませんか?
私は自分のデータセットを2つのクラスで分類するために小さな畳み込みニューラルネットワークを構築しました。私のコードを実行したとき、私は形状変更に関連したエラーが発生しました。基本的には画像は72x72 RGB
ピクセルです。だから私が定義した形は[72, 72, 3]
だった。私はInvalidArgumentError (see above for traceback): Input to reshape is a tensor with 14040 values, but the requested shape has 15552
を得ていた。今私は72*72*3 = 15552
と思った15552
値でなければなりません。 14040
しかなかった場合は、おそらく画像に何か問題がありますか?
私は自分で画像を撮ったり、Googleから取得したりして、すべての画像を72x72
ピクセルにリサイズするためにJavaプログラムを使用しました。
私は画像がモデルに入ってきたときに画像を表示しようとしましたが、出力がなく、シャットダウンするまで何も表示されません。
sess = tf.InteractiveSession()
filename = "../../dataset/traffic_sign/train-00000-of-00001"
# convert filename to a queue for an input pipeline.
filenameQ = tf.train.string_input_producer([filename], num_epochs=None)
# OUTPUT = AttributeError: 'FIFOQueue' object has no attribute 'eval'
print(filenameQ.eval())
# object to read records
recordReader = tf.TFRecordReader()
# read the full set of features for a single example
key, fullExample = recordReader.read(filenameQ)
# NO OUTPUT: program hangs
print(fullExample.eval())
# parse the full example into its' component features.
features = tf.parse_single_example(
fullExample,
features={
'image/height': tf.FixedLenFeature([], tf.int64),
'image/width': tf.FixedLenFeature([], tf.int64),
'image/colorspace': tf.FixedLenFeature([], dtype=tf.string, default_value=''),
'image/channels': tf.FixedLenFeature([], tf.int64),
'image/class/label': tf.FixedLenFeature([], tf.int64),
'image/class/text': tf.FixedLenFeature([], dtype=tf.string, default_value=''),
'image/format': tf.FixedLenFeature([], dtype=tf.string, default_value=''),
'image/filename': tf.FixedLenFeature([], dtype=tf.string, default_value=''),
'image/encoded': tf.FixedLenFeature([], dtype=tf.string, default_value='')
})
# now we are going to manipulate the label and image features
label = features['image/class/label']
image_buffer = features['image/encoded']
# Decode the jpeg
with tf.name_scope('decode_jpeg', [image_buffer], None):
# decode turns tensor of type string. 0-D the JPEG encoded image
# to tensor of type uint8. 3-D with shape [height, width, channels]
image = tf.image.decode_jpeg(image_buffer, channels=3)
image = tf.reshape(image, [HEIGHT, WIDTH, NUM_CHANNELS])
image = tf.to_float(image, "ToFloat")
# re-define label as a "one-hot" vector
# it will be [0,1] or [1,0] here.
# This approach can easily be extended to more classes
label = tf.one_hot(label - 1, NUM_CLASSES, dtype=tf.int64)
init = tf.global_variables_initializer()
sess.run(init)
# NO OUTPUT: program hangs
print(label.eval())
私はgo
とstop
を含むラベルファイルmylabels.txt
で例hereに続いTFRecordファイルを作成したとき、私のディレクトリ構造は次のとおりです。
traffic_sign/train/go/go*.jpeg
traffic_sign/train/stop/stop*.jpeg
traffic_sign/validation/go/go*.jpeg
traffic_sign/validation/stop/stop*.jpeg
python build_image_data.py --train_directory=./train --output_directory=./ \
--validation_directory=./validation --labels_file=mylabels.txt \
--train_shards=1 --validation_shards=1 --num_threads=1
レコードファイルが作成され、多くのバイトが含まれています。
私はこれを解決する手がかりがありません。私がデータセットを作成する間違いをしたかどうかはわかりません。しかし、画像は72x72x3
でなければならないので、私は14040
の値で私のモデルにテンソルがあるのか分かりません。そして、私はテンソルを評価することができず、ちょうどハングするプログラムは私にデバッグを許さないという事実。 MUCH