Keras-训练数据的预测准确性较差吗?

时间:2019-06-13 10:48:06

标签: python machine-learning keras conv-neural-network

我已经训练好模型并得到了.hdf5文件。 (培训和验证的准确性约为0.9)

下面是我的精度曲线。

trainnig curve

由于我的数据不平衡,我使用SMOTE对我的数据进行过采样,然后将其分为训练和验证数据。

 sm = SMOTE(random_state=42)

X_resampled, y_resampled = sm.fit_resample(X, Y)

X_resampled = X_resampled.reshape(X_resampled.shape[0],128,128,3)

X_tr, X_tst, y_tr, y_tst = train_test_split(X_resampled, y_resampled, test_size=0.33,random_state=22)

下面是我的模型结构。

image_input = Input(shape=(img_size, img_size, 3))

conv_1 = Conv2D(64, (5, 5), padding='same',
                input_shape=(img_size, img_size, 3), activation='relu')(image_input)
drop_2 = Dropout(0.4)(conv_1)
conv_3 = Conv2D(64, (3, 3), padding='same', activation='relu')(drop_2)
drop_4 = Dropout(0.4)(conv_3)
max_5 = MaxPooling2D(pool_size=(2, 2))(drop_4)

conv_6 = Conv2D(32, (5, 5), padding='same', activation='relu')(max_5)
drop_7 = Dropout(0.4)(conv_6)
conv_8 = Conv2D(32, (3, 3), padding='same', activation='relu')(drop_7)
drop_9 = Dropout(0.4)(conv_8)
max_10= MaxPooling2D(pool_size=(2, 2))(drop_9)

conv_11 = Conv2D(32, (5, 5), padding='same', activation='relu')(max_10)
drop_12 = Dropout(0.4)(conv_11)
conv_13 = Conv2D(32, (3, 3), padding='same', activation='relu')(drop_12)
drop_14 = Dropout(0.4)(conv_13)
max_15= MaxPooling2D(pool_size=(2, 2))(drop_14)

flat_16 = Flatten()(max_15)

den_17= Dense(8,activation='relu')(flat_16)

output = Dense(nb_classes, activation='softmax')(den_17)

img_size = 128         
nb_classes = 6          
batch_size = 256
nb_epoch=1000
savedModelName = 'M.hdf5'   
lr = 0.00001 

完成模型训练后,我保存了模型(根据验证的准确性,通过ModelCheckpoint save_best_only)。

然后我用它来预测“相同的”数据(相同的random_state)。

 sm = SMOTE(random_state=42)

X_resampled, y_resampled = sm.fit_resample(X, Y)

X_resampled = X_resampled.reshape(X_resampled.shape[0], 128, 128, 3)

X_tr, X_tst, y_tr, y_tst = train_test_split(X_resampled, y_resampled, test_size=0.33,random_state=22)

但是!!我得到的预测精度约为0.3。

为什么?

不是0.9吗?

1 个答案:

答案 0 :(得分:0)

您能否提供适合模型的代码。 如果用模型预测第一个测试集,还会发生什么?您能否提供一个混淆矩阵或Precision / Recall-Values?

我的第一个猜测是,您的模型可能过拟合或没有真正学习。