作為標題狀態,從我的 tfrecord 檔案中只加載了 1 個影像 標簽。每個 tfrecord 中有可變數量的影像/標簽,但總是至少 8 對。我正在使用 TF 版本:2.4.1
可能相關我收到此警告:
警告:tensorflow:AutoGraph 無法轉換 <function parse_tfr_element at 0x7fbb7db99160> 并將按原樣運行。請將此報告給 TensorFlow 團隊。提交錯誤時,將詳細程度設定為 10(在 Linux 上
export AUTOGRAPH_VERBOSITY=10)并附上完整的輸出。原因:模塊 'gast' 沒有屬性 'Index' 要消除此警告,請使用 @tf.autograph.experimental.do_not_convert 裝飾函式
以下是我用來加載測驗資料的函式。任何幫助表示贊賞。
def parse_tfr_element(element):
data = {
'height': tf.io.FixedLenFeature([], tf.int64),
'width':tf.io.FixedLenFeature([], tf.int64),
'depth':tf.io.FixedLenFeature([], tf.int64),
'raw_label':tf.io.FixedLenFeature([], tf.string),#tf.string = bytestring (not text string)
'raw_image' : tf.io.FixedLenFeature([], tf.string),#tf.string = bytestring (not text string)
}
content = tf.io.parse_single_example(element, data)
height = content['height']
width = content['width']
depth = content['depth']
raw_label = content['raw_label']
raw_image = content['raw_image']
#get our 'feature'-- our image -- and reshape it appropriately
feature = tf.io.parse_tensor(raw_image, out_type=tf.float16)
feature = tf.reshape(feature, shape=[height,width,depth])
label = tf.io.parse_tensor(raw_label, out_type=tf.int8)
label = tf.reshape(label, shape=[height,width])
return (feature, label)
def get_batched_dataset(filenames):
option_no_order = tf.data.Options()
option_no_order.experimental_deterministic = False
dataset = tf.data.TFRecordDataset(filenames)
dataset = dataset.with_options(option_no_order)
dataset = dataset.map(parse_tfr_element, num_parallel_calls=AUTO)
dataset = dataset.shuffle(2048)
dataset = dataset.batch(BATCH_SIZE, drop_remainder=True)
return dataset
uj5u.com熱心網友回復:
事實證明這個問題很愚蠢,與我在問題中發布的功能無關。問題是我將 steps_per_epoch 的以下值輸入模型。
steps_per_epoch = len(training_filenames) // BATCH_SIZE
由于檔案包含多個案例,因此需要將 len(training_filenames) 乘以每個檔案中的案例數。
steps_per_epoch = len(training_filenames) * images_in_file // BATCH_SIZE
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/453514.html
