当前位置:网站首页>Inception V3 Eye Closure Detection

Inception V3 Eye Closure Detection

2022-08-09 06:38:00 Starry-sky(jing)

一. 模型演示

闭眼检测

Closed eyes detection accuracy is high98%

二.网络设计

The network structure is reproduced from the source : One of the classic convolutional networksInceptionV3
InceptionV3模型是googleThe third generation model in the series,InceptionThe biggest feature of the network is the expansion of the convolution operation between the layers of the neural network.
如VGG,AlexNetThe network is always convolutional,ResNetThen a residual network is introduced,The data of a certain layer in the first several layers is directly skipped and introduced into the input part of the following data layer,The content of the later feature layer will be partially linearly provided by a previous layer.而InceptionThe network uses convolution kernels of different sizes to have different sizes of receptive fields,Finally, splicing to achieve feature fusion of different scales is achieved.

在这里插入图片描述

在这里插入图片描述

三.结构层次

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

三. 网络优点

Such a structure exists,利用1x7的卷积和7x1的卷积代替7x7的卷积,This way you can use only approx(1x7 + 7x1) / (7x7) = 28.6%的计算开销;利用1x3的卷积和3x1的卷积代替3x3的卷积,This way you can use only approx(1x3 + 3x1) / (3x3) = 67%的计算开销.
下图利用1x7的卷积和7x1的卷积代替7x7的卷积(This structure is mostly in the codeblock2使用).

在这里插入图片描述

下图利用1x3的卷积和3x1的卷积代替3x3的卷积(This structure is mostly in the codeblock3使用).
在这里插入图片描述

三.主要代码讲解

The realization idea of ​​the closed eye detection function is as follows:

  1. 用haarCascaded classifiers are implemented on human faces,Recognition of left and right eyes
  2. 读取,处理数据集
  3. 加载模型,输入数据集,训练
  4. 验证模型

主要是利用InceptionV3The main network structure is featured,Modify the full link part of the output layer of the network for retraining. The specific network structure code is as follows:

def V3Model(classes=2):

	# 采用imagenet as weight
	# include_top=False 不采用Inception原始分类,自定义分类
    base_model = InceptionV3(weights='imagenet', include_top=False)

    # 输出层
    x = base_model.output
    
	# 可以使用gap全局池化代替flatten,It can be seen from the comparison of parameters,This improvement greatly reduces the number of parameters used,避免了过拟合现象.
    x = GlobalAveragePooling2D()(x)
    x = Dense(1024, activation='relu')(x)

    x = Dropout(0.5)(x)
    y = Dense(classes, activation='softmax')(x)
    model = Model(inputs=base_model.input, outputs=y)
    # The previous training parameters are not used
    for layer in base_model.layers:
        layer.trainable = True

    model.summary()
    return model

部分训练,测试代码

if os.path.exists("data/checkpoints"):
    print('-------------load the model-----------------')
    model.load_weights("data/checkpoints/model.006-0.040.h5")

model.compile(optimizer='Adam',
              loss='categorical_crossentropy', metrics=['accuracy'])

model.fit_generator(train_data, steps_per_epoch=train_data.samples // batchsize,
                    epochs=50,
                    validation_data=validation_data,
                    validation_steps=validation_data.samples // batchsize,
                    verbose=1,
                    callbacks=callbacks)

loss, acc = model.evaluate_generator(train_data)
val_loss, val_acc = model.evaluate_generator(validation_data)
print(f"acc:{
      acc},loss:{
      loss},val_acc:{
      val_acc},val_loss:{
      val_loss}")

数据集处理

for dirpath, dirname, filename in os.walk(raw_data):
    for file in tqdm([f for f in filename if f.endswith('.png')]):
        if file.split('_')[4] == '0':
            path = '/home/delixus/Desktop/drowsiness_detection/data/train/closed'
            if not os.path.exists(path):
                os.makedirs(path)
            shutil.copy(src=dirpath + '/' + file, dst=path)
        elif file.split('_')[4] == '1':
            path = '/home/delixus/Desktop/drowsiness_detection/data/train/open'
            if not os.path.exists(path): os.makedirs(path)
            shutil.copy(src=dirpath + '/' + file, dst=path)

四.源码及模型下载

闭眼检测tensorflow源码,h5训练模型,准确率达98%.Late Open Source and Models

原网站

版权声明
本文为[Starry-sky(jing)]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/221/202208090627136447.html