[英]My CNN model accuracy is not improving with ResNet50
我正在使用 TensorFlow 進行機器學習項目以進行手語識別。 當我第一次嘗試構建我的 CNN 模型時,它的驗證准確率為 94%:
def create_model():
model = Sequential(name='SIGNS_LANGUAGE')
model.add(layers.Conv2D(32,(3,3),activation='relu',input_shape=(IMG_SIZE, IMG_SIZE , 3) ) )
model.add(layers.MaxPooling2D(pool_size = (2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu' ,input_shape=(IMG_SIZE, IMG_SIZE , 3) ) )
model.add(layers.MaxPooling2D(pool_size = (2, 2)))
#classification layers
model.add(layers.Flatten())
model.add(layers.Dense(512, activation='relu'))
model.add(layers.Dropout(0.2))
model.add(layers.Dense(512, activation='relu'))
model.add(layers.Dropout(0.2))
model.add(layers.Dense(512, activation='relu'))
model.add(layers.Dropout(0.2))
model.add(layers.Dense(targetCount, activation='softmax'))
print(model.summary())
return model`
但它並不擅長用不同的數據進行概括。
所以我嘗試使用像 ResNet50 這樣的預訓練模型,但我無法弄清楚為什么准確度沒有隨着時間的推移而提高,它達到了 40% 並停止了:
def create_model():
model = Sequential(name='SIGNS')
input_shape = (IMG_SIZE , IMG_SIZE , 3)
res_layer = tf.keras.applications.ResNet50(input_shape=input_shape, include_top=False , weights='imagenet' )
res_layer.trainable = False
model.add( res_layer )
model.add(layers.GlobalAveragePooling2D())
model.add(layers.Dropout(0.2))
model.add(layers.Dense(1024, activation='relu'))
model.add(layers.Dropout(0.2))
model.add(layers.Dense(512, activation='relu'))
model.add(layers.Dropout(0.2))
model.add(layers.Dense(targetCount, activation='softmax'))
print(model.summary())
return model
關於如何改進模型的任何建議?
注意:我在 3 個通道中輸入了 54049 個灰度圖像,並使用了 Adam 優化器。
如果您使用的是預訓練架構,則必須根據最初訓練預訓練架構的數據集(在本例中為 Imagenet)對數據進行規范化。
嘗試在您的第一個代碼之后合並此代碼 -
preprocessing_layer = tf.keras.applications.resnet50.preprocess_input(x, data_format=None)
inputs = keras.Input(shape=input_shape)
x = preprocessing_layer(inputs)
outputs = model(x)
inference_model = keras.Model(inputs, outputs)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.