错误的模型预测Keras

时间:2019-02-17 17:11:55

标签: python arrays numpy keras deep-learning

我创建了一个区分不同手势的模型。当我尝试对自己的培训进行测试时,输出效果很好。这就是我对训练图像的预测。

test_image = Xtest[4]
test_image = cv2.resize(test_image, (64,64))
test_image = test_image[:,:,np.newaxis]
test_image = np.expand_dims(test_image, axis = 0)
result = model.predict(test_image) 

我的输出是:

[[1.1471398e-02 1.7711835e-05 6.1694984e-05 2.8054390e-07 1.6065275e-04
  9.8699224e-01 1.9591409e-04 3.8560024e-06 4.1441439e-08 1.0961749e-03]] 

有了np.round(result, 1),我得到[[0. 0. 0. 0. 0. 1. 0. 0. 0. 0.]]是正确的。当我尝试对自己的图像进行测试时,

test_image = cv2.imread('imageedit_3_8900841608.jpg', cv2.IMREAD_GRAYSCALE)
test_image = cv2.resize(test_image, (64,64))
test_image = test_image[:,:,np.newaxis]
test_image = np.expand_dims(test_image, axis = 0)
result = model.predict(test_image)

输出为[[0. 1. 0. 0. 0. 0. 0. 0. 0. 0.]]预测是正确的,但是为什么我得到一个整数? 我的模型是

model = Sequential()

# Convolutional Blocks: (1) Convolution, (2) Activation, (3) Pooling
model.add(Conv2D(input_shape=(64, 64, 1), filters=64, kernel_size=(4,4), strides=(2)))
model.add(Activation('relu'))
#outputs a (20, 20, 32) matrix
model.add(Conv2D(filters=64, kernel_size=(4,4), strides=(1)))
model.add(Activation('relu'))
#outputs a (8, 8, 32) matrix


model.add(MaxPooling2D(pool_size=4))

# dropout helps with over fitting by randomly dropping nodes each epoch
model.add(Dropout(0.3))

model.add(Flatten())
model.add(Dense(256, activation='relu'))
model.add(BatchNormalization())

model.add(Dense(10, activation='softmax'))
model.compile(loss='categorical_crossentropy',
             optimizer=optimizers.Adadelta(),
             metrics=['accuracy'])
model.fit(Xtrain, ytrain, batch_size=32, epochs=10)

0 个答案:

没有答案