更换计算机时我的CNN模型预测错误

时间:2019-06-02 15:28:39

标签: python

我训练了一个cnn模型来识别情绪,我用权重保存了该模型并使用外部图像进行了预测,它可以高精度地识别它们,但是当我将该模型发送到另一台计算机并使用同一模型进行了预测时在相同的图像上,模型无法识别它们 两台计算机都使用JetBrains PyCHarm在Windows 10上运行 这是我的模特

`model2 = Sequential()
 # First set Conv Layers  LeNet
 model2.add(Conv2D(64, (3, 3), padding='valid', input_shape=(48, 48, 1), 
 activation='relu'))
 model2.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
 model2.add(BatchNormalization())

 # 2nd set Conv layers
 model2.add(Conv2D(128, (3, 3), padding='valid',  input_shape=(48, 48, 
 1),activation='relu'))
 model2.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
 model2.add(BatchNormalization())

 model2.add(Conv2D(256, (3, 3), padding='valid',activation='relu'))
 model2.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
 model2.add(BatchNormalization())


 # Set of FC => Relu layers
 model2.add(Flatten())
 model2.add(Dense(256))
 model2.add(Activation('relu'))
 model2.add(Dropout(0.5))

model2.add(Conv2D(512, (3, 3), padding='valid', activation='relu'))
model2.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))
model2.add(BatchNormalization())
model2.add(Dropout(0.5))

# Softmax classifier
model2.add(Dense(150, activation='relu'))
model2.add(Dense(7))
model2.add(Activation('softmax'))


model2.compile(optimizer='adam', loss='sparse_categorical_crossentropy', 
metrics=['acc'])

model2.fit(x_train,y_train,validation_split=0.20,validation_data= 
(xx_test, y_test), epochs=100, batch_size=128)

prediction = model2.predict( test_image)
print(prediction)

0 个答案:

没有答案