Б қосымшасының жалғасы
model.summary()
log_file_path = base_path + '_emotion_training.log'
csv_logger = CSVLogger(log_file_path, append=False)
early_stop = EarlyStopping('val_loss', patience=patience)
reduce_lr = ReduceLROnPlateau('val_loss', factor = 0.1, patience =
int(patience/4), verbose = 1)
trained_models_path = base_path + '_mini_XCEPTION'
model_names = trained_models_path + '.{epoch:02d}-{val_acc:.2f}.hdf5'
model_checkpoint = ModelCheckpoint(model_names, 'val_loss', verbose = 1,
save_best_only = True)
callbacks = [model_checkpoint, csv_logger, early_stop, reduce_lr]
faces, emotions = '
test’
faces = preprocess_input(faces)
num_samples, num_classes = emotions.shape
xtrain, xtest, ytrain, ytest = train_test_split(faces, emotions, test_size=0.2,
shuffle = True)
model.fit_generator(data_generator.flow(xtrain, ytrain, batch_size),
steps_per_epoch=len(xtrain) / batch_size, epochs=num_epochs,
verbose=1, callbacks=callbacks, validation_data=(xtest,ytest))
from keras.preprocessing.image import img_to_array
import imutils
import cv2
from keras.models import load_model
import numpy as npdetection_model_path =
'haarcascade_files/haarcascade_frontalface_default.xml'
emotion_model_path = 'models/ABS_XCEPTION.hdf5'
face_detection = cv2.CascadeClassifier(detection_model_path)
emotion_classifier = load_model(emotion_model_path, compile=False)
EMOTIONS = ["angry" ,"disgust","scared", "happy", "sad", "surprised",
"neutral"]
cv2.namedWindow('Emotion!')
camera = cv2.VideoCapture(0)
while True:
frame = camera.read()[1]
frame = imutils.resize(frame,width=400)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces =
face_detection.detectMultiScale(gray,scaleFactor=1.1,minNeighbors=5,minSize=30,
30),flags=cv2.CASCADE_SCALE_IMAGE)
canvas = np.zeros((250, 300, 3), dtype="uint8")
Достарыңызбен бөлісу: |