python - 用于手语识别的 resnet 模型的准确性没有提高
问题描述
这是数据集:https ://www.kaggle.com/grassknoted/asl-alphabet
def res_block(X, filter, stage):
# Convolutional_block
X_copy = X
f1 , f2, f3 = filter
# Main Path
X = Conv2D(f1, (1,1),strides = (1,1), name ='res_'+str(stage)+'_conv_a', kernel_initializer= glorot_uniform(seed = 0))(X)
X = MaxPooling2D((2,2), padding='same')(X)
X = BatchNormalization(axis =3, name = 'bn_'+str(stage)+'_conv_a')(X)
X = Activation('relu')(X)
X = Conv2D(f2, kernel_size = (3,3), strides =(1,1), padding = 'same', name ='res_'+str(stage)+'_conv_b', kernel_initializer= glorot_uniform(seed = 0))(X)
X = BatchNormalization(axis =3, name = 'bn_'+str(stage)+'_conv_b')(X)
X = Activation('relu')(X)
X = Conv2D(f3, kernel_size = (1,1), strides =(1,1),name ='res_'+str(stage)+'_conv_c', kernel_initializer= glorot_uniform(seed = 0))(X)
X = BatchNormalization(axis =3, name = 'bn_'+str(stage)+'_conv_c')(X)
# Short path
X_copy = Conv2D(f3, kernel_size = (1,1), strides =(1,1),name ='res_'+str(stage)+'_conv_copy', kernel_initializer= glorot_uniform(seed = 0))(X_copy)
X_copy = MaxPooling2D((2,2), padding='same')(X_copy)
X_copy = BatchNormalization(axis =3, name = 'bn_'+str(stage)+'_conv_copy')(X_copy)
# ADD
X = Add()([X,X_copy])
X = Activation('relu')(X)
# Identity Block 1
X_copy = X
# Main Path
X = Conv2D(f1, (1,1),strides = (1,1), name ='res_'+str(stage)+'_identity_1_a', kernel_initializer= glorot_uniform(seed = 0))(X)
X = BatchNormalization(axis =3, name = 'bn_'+str(stage)+'_identity_1_a')(X)
X = Activation('relu')(X)
X = Conv2D(f2, kernel_size = (3,3), strides =(1,1), padding = 'same', name ='res_'+str(stage)+'_identity_1_b', kernel_initializer= glorot_uniform(seed = 0))(X)
X = BatchNormalization(axis =3, name = 'bn_'+str(stage)+'_identity_1_b')(X)
X = Activation('relu')(X)
X = Conv2D(f3, kernel_size = (1,1), strides =(1,1),name ='res_'+str(stage)+'_identity_1_c', kernel_initializer= glorot_uniform(seed = 0))(X)
X = BatchNormalization(axis =3, name = 'bn_'+str(stage)+'_identity_1_c')(X)
# ADD
X = Add()([X,X_copy])
X = Activation('relu')(X)
# Identity Block 2
X_copy = X
# Main Path
X = Conv2D(f1, (1,1),strides = (1,1), name ='res_'+str(stage)+'_identity_2_a', kernel_initializer= glorot_uniform(seed = 0))(X)
X = BatchNormalization(axis =3, name = 'bn_'+str(stage)+'_identity_2_a')(X)
X = Activation('relu')(X)
X = Conv2D(f2, kernel_size = (3,3), strides =(1,1), padding = 'same', name ='res_'+str(stage)+'_identity_2_b', kernel_initializer= glorot_uniform(seed = 0))(X)
X = BatchNormalization(axis =3, name = 'bn_'+str(stage)+'_identity_2_b')(X)
X = Activation('relu')(X)
X = Conv2D(f3, kernel_size = (1,1), strides =(1,1),name ='res_'+str(stage)+'_identity_2_c', kernel_initializer= glorot_uniform(seed = 0))(X)
X = BatchNormalization(axis =3, name = 'bn_'+str(stage)+'_identity_2_c')(X)
# ADD
X = Add()([X,X_copy])
X = Activation('relu')(X)
return X
input_shape = (64, 64, 3)
X_input = Input(input_shape)
# Zero-padding
X = ZeroPadding2D((3,3))(X_input)
# 1 - stage
X = Conv2D(64, (7,7), strides= (2,2), name = 'conv1', kernel_initializer= glorot_uniform(seed = 0))(X)
X = BatchNormalization(axis =3, name = 'bn_conv1')(X)
X = Activation('relu')(X)
X = MaxPooling2D((3,3), strides= (2,2), padding='same')(X)
# 2 - stage
X = res_block(X, filter= [64,64,256], stage= 2)
# 3 - stage
X = res_block(X, filter= [128,128,512], stage= 3)
# 4 - stage
X = res_block(X, filter= [256,256,1024], stage= 4)
# 5 - stage
X = res_block(X, filter= [512,512,2048], stage= 5)
# Average Pooling
X = AveragePooling2D((2,2), name = 'Averagea_Pooling', padding='same')(X)
# Final layer
X = Flatten()(X)
X = Dense(4096, activation = 'relu')(X)
X = Dropout(0.2)(X)
X = Dense(2048, activation = 'relu')(X)
X = Dropout(0.1)(X)
X = Dense(29, activation = 'relu')(X)
my_model = Model( inputs= X_input, outputs = X)
my_model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
my_model.summary()
history = my_model.fit(train_gen, epochs=10, validation_data=val_gen)
任何人都可以告诉技术如何提高此代码的准确性,一段时间后,损失到达 nan.will 应用诸如 earlystopping 或 modelcheckpoint 之类的回调有助于提高准确性。对于第一个 epoch,损失:8.6760 - 准确度:0.0637 - val_loss:7.9905 - val_accuracy:0.1003,对于第二个 epoch,损失变为 nan
解决方案
推荐阅读
- sql - 在 SQL 中如何显示两行的值以及这两行的值的比率?
- css - 带有垂直和水平分隔符的卡片中的 CSS 样式和结构内容
- elasticsearch - 如何搜索结果不能是两个值的总和?
- node.js - 我定义了嵌套模式,当我填充输入时它什么也不返回,也不保存在 Mongodb
- c++ - 如果方法是const,如何找到向量的中位数?
- javascript - onClick 和 className 在 reactjs 中不起作用
- mysql - 根据所选工作的不同要求的工作经验的数据库结构
- javascript - 长文件转录两次(运行两个操作) - 错误
- android - 如何在一个前台服务中对多个任务进行排队,让它们一个一个地执行?
- kubernetes - 如何使用无服务器 VPC 访问云功能