[英]Validation Accuracy stuck at .5073
我正在嘗試創建回歸 model 但我的驗證准確度保持在.5073
。 我正在嘗試對圖像進行訓練並讓網絡找到 object 的 position 及其覆蓋的粗糙區域。 我增加了未凍結的層和平台的准確性下降到.4927
。 我將不勝感激任何幫助找出我做錯了什么。
base = MobileNet(weights='imagenet', include_top=False, input_shape=(200,200,3), dropout=.3)
location = base.output
location = GlobalAveragePooling2D()(location)
location = Dense(16, activation='relu', name="locdense1")(location)
location = Dense(32, activation='relu', name="locdense2")(location)
location = Dense(64, activation='relu', name="locdense3")(location)
finallocation = Dense(3, activation='sigmoid', name="finalLocation")(location)
model = Model(inputs=base_model.input,outputs=finallocation)#[types, finallocation])
for layer in model.layers[:91]: #freeze up to 87
if ('loc' or 'Loc') in layer.name:
layer.trainable=True
else: layer.trainable=False
optimizer = Adam(learning_rate=.001)
model.compile(optimizer=optimizer, loss='mean_squared_error', metrics=['accuracy'])
history = model.fit(get_batches(type='Train'), validation_data=get_batches(type='Validation'), validation_steps=500, steps_per_epoch=1000, epochs=10)
數據是從具有圖像數據和一些標簽的 tfrecord 文件生成的。 這是該生成器的最后一點。
IMG_SIZE = 200
def format_position(image, positionx, positiony, width):
image = tf.cast(image, tf.float32)
image = (image/127.5) - 1
image = tf.image.resize(image, (IMG_SIZE, IMG_SIZE))
labels = tf.stack([positionx, positiony, width])
return image, labels
獲取批次:數據集從兩個包含 tfrecord 文件的目錄加載,一個用於訓練,另一個用於驗證
def get_batches(type):
dataset = load_dataset(type=type)
if type == 'Train':
databatch = dataset.repeat()
databatch = dataset.batch(32)
databatch = databatch.prefetch(2)
return databatch
```positionx positiony width``` are all normalized from 0-1 (relative position with respect to the image.
Here is an example output:
紀元 1/10 1000/1000 [===============================] - 233s 233ms/步 - 損失:0.0267 - 准確度: 0.5833 - val_loss: 0.0330 - val_accuracy: 0.5073 Epoch 2/10 1000/1000 [=============================] - 283s 283ms/step - loss: 0.0248 - accuracy: 0.6168 - val_loss: 0.0337 - val_accuracy: 0.5073 Epoch 3/10 1000/1000 [===================== ========] - 221 秒 221 毫秒/步 - 損失:0.0238 - 准確度:0.6309 - val_loss:0.0312 - val_accuracy:0.5073
sigmoid
,因為它將 output 數字介於0
和1
positiony
positionx
width
是這個范圍。 您可以將其替換為'linear'
或'relu'
。'mean_squared_error'
。 您不能使用accuracy
作為度量標准 function。 您應該使用'mae'
(平均絕對誤差)或'mse'
來檢查您的預測與實際目標值之間的差異。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.