【发布时间】:2018-06-28 21:51:24
【问题描述】:
我正在做我的最后一个项目,使用 CNN 进行人脸识别,我是这个领域的新手,正在寻求建议。
我已经在 Keras 中构建了 CNN 模型,并在 Faces94 上对其进行了训练,我得到了 90.97% 的准确率
现在,我正在尝试绘制 CRO、FAR、FRR。
我尝试了很多代码,但没有任何效果。你能帮帮我吗?
PFB 我的代码:
import keras
from keras import backend as K
import os
from keras.layers.advanced_activations import LeakyReLU
from __future__ import print_function
from keras.datasets import mnist
import matplotlib.pylab as plt
from importlib import reload
def set_keras_backend(backend):
if K.backend() != backend:
os.environ['KERAS_BACKEND'] = backend
reload(K)
assert K.backend() == backend
set_keras_backend("tensorflow")
DATA = joblib.load(open('Data.sav', 'rb'))
LABEL = joblib.load(open('Lable.sav', 'rb'))
print(DATA.shape)
print(LABEL.shape)
print(tf.__version__)
X_train, X_test, y_train, y_test = train_test_split(DATA, LABEL, test_size=0.30, random_state=45)
print(X_train.shape)
print(X_test.shape)
print(y_train.shape)
print(y_test.shape)
print(X_train[0])
X_train = np.reshape(X_train,(X_train.shape[0],200,180,1))
X_test = np.reshape(X_test,(X_test.shape[0],200,180,1))
# convert the data from binary to float
X_train = X_train.astype('float32')
X_test = X_test.astype('float32')
X_train /= 255
X_test /= 255
model = Sequential()
model.add(Conv2D(32, kernel_size=(5,5), strides=(1, 1),
activation='relu',
input_shape=([200,180,1])))
model.add(LeakyReLU(alpha=0.1))
model.add(MaxPooling2D(pool_size=(2,2)))
# add another 2D convolutional layer and 2D max pooling layer, with 64 output channels
model.add(Conv2D(64,(5,5), activation='relu'))
model.add(LeakyReLU(alpha=0.1))
model.add(MaxPooling2D(pool_size=(2,2)))
# add another 2D convolutional layer and 2D max pooling layer, with 128 output channels
model.add(Conv2D(128,(5,5), activation='relu'))
model.add(LeakyReLU(alpha=0.1))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Dropout(0.30))
model.add(Flatten())
model.add(Dense(1000, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(72, activation='softmax'))
# When we compile the model, we declare the loss function and the optimizer
model.compile(loss=keras.losses.categorical_crossentropy, optimizer=keras.optimizers.Adam(), metrics=['accuracy'])
# Train the model
hist = model.fit(X_train, Y_train,batch_size=32,epochs=12, verbose=1, validation_data=(X_test, Y_test))
score = model.evaluate(X_test, Y_test, verbose=0)
print("%s: %.2f%%" % ('Accuracy', score[1]*100))
【问题讨论】:
标签: python-3.x keras classification face-recognition roc