我是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
。現在應該是15552
值我認爲是72*72*3 = 15552
。如果只有14040
那麼我的圖像可能有問題嗎?
我自己拍攝了這些圖像,或者從Google獲取了這些圖像,並使用了一個Java程序將它們全部調整爲72x72
像素。
我試圖eval()
圖像,因爲他們進入模型,但沒有輸出,整個事情只是掛了一分鐘,直到我關閉它。
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())
當我創建的TFRecord文件I跟着示例here用含有go
和stop
一個標籤文件mylabels.txt
和我的目錄結構,如下所示:
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
。事實上,我似乎無法評估張量和程序的掛起不允許我進行調試。
幫助非常感謝