[英]My CNN model accuracy is not improving with ResNet50
I'm working on a machine learning project with TensorFlow for sign language recognition.我正在使用 TensorFlow 进行机器学习项目以进行手语识别。 When I first tried to build my CNN model it has a validation accuracy of 94% :当我第一次尝试构建我的 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`
BUT IT HASN'T BEEN GOOD AT generalizing with a different data.但它并不擅长用不同的数据进行概括。
So I tried to work with a pre-trained model like ResNet50 but I couldn't figure out why the accuracy is not improving with time, it hit 40% and stopped:所以我尝试使用像 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
Any suggestions on how to improve the model??关于如何改进模型的任何建议?
NB: I input 54049 grayscale images in the 3 channels and I use Adam optimizer.注意:我在 3 个通道中输入了 54049 个灰度图像,并使用了 Adam 优化器。
If you are using a pre-trained architecture, you have to normalize your data according to the dataset on which the pre-trained architecture was originally trained on(in this case, Imagenet).如果您使用的是预训练架构,则必须根据最初训练预训练架构的数据集(在本例中为 Imagenet)对数据进行规范化。
Try incorporating this code after your first one -尝试在您的第一个代码之后合并此代码 -
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.