• 大小: 3.94MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-09-18
  • 语言: Python
  • 标签: CNN;  openCV  

资源简介

基于 CNN 的疲劳检测源码-Python - 模型: CNN; - drowsiness detection; - blink detection; - yawning detection

资源截图

代码片段和文件信息


from __future__ import absolute_import
from __future__ import print_function
import numpy as np
import os
from keras.utils import plot_model
import cv2

np.random.seed(1337)  # for reproducibility



from keras.models import Sequential
from keras.layers.core import Dense Dropout Activation Flatten
from keras.layers.convolutional import Convolution2D MaxPooling2D
from keras.utils import np_utils
from keras.optimizers import SGD Adadelta Adagrad

from six.moves import cPickle as pickle

import tensorflow as tf
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

os.environ[“PATH“] += os.pathsep + ‘C:/Program Files (x86)/Graphviz2.38/bin/‘

pickle_files = [‘open_eyes.pickle‘ ‘closed_eyes.pickle‘]
i = 0
for pickle_file in pickle_files:
    with open(pickle_file ‘rb‘) as f:
        save = pickle.load(f)
        if i == 0:
            train_dataset = save[‘train_dataset‘]
            train_labels = save[‘train_labels‘]
            test_dataset = save[‘test_dataset‘]
            test_labels = save[‘test_labels‘]
        else:
            print(“here“)
            train_dataset = np.concatenate((train_dataset save[‘train_dataset‘]))
            train_labels = np.concatenate((train_labels save[‘train_labels‘]))
            test_dataset = np.concatenate((test_dataset save[‘test_dataset‘]))
            test_labels = np.concatenate((test_labels save[‘test_labels‘]))
        del save  # hint to help gc free up memory
    i += 1

print(‘Training set‘ train_dataset.shape train_labels.shape)
print(‘Test set‘ test_dataset.shape test_labels.shape)

batch_size = 30
nb_classes = 1
epochs = 12

X_train = train_dataset
X_train = X_train.reshape((X_train.shape[0] X_train.shape[3]) + X_train.shape[1:3])
Y_train = train_labels

X_test = test_dataset
X_test = X_test.reshape((X_test.shape[0] X_test.shape[3]) + X_test.shape[1:3])
Y_test = test_labels

# print shape of data while model is building
print(“{1} train samples {4} channel{0} {2}x{3}“.format(““ if X_train.shape[1] == 1 else “s“ *X_train.shape))
print(“{1}  test samples {4} channel{0} {2}x{3}“.format(““ if X_test.shape[1] == 1 else “s“ *X_test.shape))

# input image dimensions
_ img_channels img_rows img_cols = X_train.shape

# convert class vectors to binary class matrices
# Y_train = np_utils.to_categorical(y_train nb_classes)
# Y_test = np_utils.to_categorical(y_test nb_classes)

model = Sequential()

model.add(Convolution2D(32 (3 3) padding=‘same‘
                        input_shape=(img_channels img_rows img_cols)data_format=‘channels_first‘))
model.add(Activation(‘relu‘))
model.add(Convolution2D(24 (3 3) data_format=‘channels_first‘))
model.add(Activation(‘relu‘))
model.add(MaxPooling2D(pool_size=(2 2)))
model.add(Dropout(0.25))

model.add(Convolution2D(64 (3 3) padding=‘same‘ data_format=‘channels_first‘))
model.add(Activation(‘relu‘))
model.add(Convolution2D(64 (3 3)))
model.add(Activation(‘relu‘))
model.add(MaxPooling2D(pool_size=(2 2)))
mode

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-05-21 13:30  DrowsyDriverDetection-master\
     文件     5502669  2018-05-19 22:50  DrowsyDriverDetection-master\closed_eyes.pickle
     目录           0  2018-05-21 19:08  __MACOSX\
     目录           0  2018-05-21 19:08  __MACOSX\DrowsyDriverDetection-master\
     文件         212  2018-05-19 22:50  __MACOSX\DrowsyDriverDetection-master\._closed_eyes.pickle
     文件        6148  2018-05-21 13:30  DrowsyDriverDetection-master\.DS_Store
     文件         120  2018-05-21 13:30  __MACOSX\DrowsyDriverDetection-master\._.DS_Store
     文件     1066283  2018-05-19 22:50  DrowsyDriverDetection-master\yawn_mouths.pickle
     文件         212  2018-05-19 22:50  __MACOSX\DrowsyDriverDetection-master\._yawn_mouths.pickle
     文件          69  2018-05-19 22:50  DrowsyDriverDetection-master\requirements.txt
     文件         212  2018-05-19 22:50  __MACOSX\DrowsyDriverDetection-master\._requirements.txt
     文件       97341  2018-05-19 22:50  DrowsyDriverDetection-master\model.png
     文件         212  2018-05-19 22:50  __MACOSX\DrowsyDriverDetection-master\._model.png
     文件        1093  2018-05-19 22:50  DrowsyDriverDetection-master\README.md
     文件         212  2018-05-19 22:50  __MACOSX\DrowsyDriverDetection-master\._README.md
     文件         570  2018-05-19 22:50  DrowsyDriverDetection-master\test.jpg
     文件         212  2018-05-19 22:50  __MACOSX\DrowsyDriverDetection-master\._test.jpg
     文件     5682693  2018-05-19 22:50  DrowsyDriverDetection-master\open_eyes.pickle
     文件         212  2018-05-19 22:50  __MACOSX\DrowsyDriverDetection-master\._open_eyes.pickle
     文件        2807  2018-05-19 22:50  DrowsyDriverDetection-master\eyesPreprocess.py
     文件         212  2018-05-19 22:50  __MACOSX\DrowsyDriverDetection-master\._eyesPreprocess.py
     文件          24  2018-05-19 22:50  DrowsyDriverDetection-master\.gitignore
     文件         212  2018-05-19 22:50  __MACOSX\DrowsyDriverDetection-master\._.gitignore
     文件        3756  2018-05-19 22:50  DrowsyDriverDetection-master\eyesCNN.py
     文件         212  2018-05-19 22:50  __MACOSX\DrowsyDriverDetection-master\._eyesCNN.py
     目录           0  2018-05-19 22:50  DrowsyDriverDetection-master\Code_archive\
     文件        1993  2018-05-19 22:50  DrowsyDriverDetection-master\Code_archive\faceDetect.py
     目录           0  2018-05-21 19:08  __MACOSX\DrowsyDriverDetection-master\Code_archive\
     文件         212  2018-05-19 22:50  __MACOSX\DrowsyDriverDetection-master\Code_archive\._faceDetect.py
     文件        2970  2018-05-19 22:50  DrowsyDriverDetection-master\Code_archive\eyeDetect.py
     文件         212  2018-05-19 22:50  __MACOSX\DrowsyDriverDetection-master\Code_archive\._eyeDetect.py
............此处省略6个文件信息

评论

共有 条评论