Improvement of LeNet-5 model based on InceptionV1 model


Through the study of the principle of reference [1] in Fire detection based on HSV color model and CNN, I plan to use LeNet-5 model to learn the outline of the fire, and further expand to the combination of its color. Finally, we can get a comprehensive result. However, compared with VGG model, LeNet-5 model is obviously less accurate. Therefore, this paper will build LeNet-5 model and optimize this model based on InceptionV1 model.

LeNet-5 model

Framework

LeNet-5 has 7 layers, including 2 convolution layers, 2 pooling layers, and 3 fully connected layers. The figure shows the learning process of MNIST data set.
在这里插入图片描述

Disadvantages

  • The features extracted by low-level feature extractors are not fully utilized.
  • The recognition effect of small objects is poor.

In order to solve these problems, according to the research in reference [1], the features extracted from H2, the first pooling layer of the network, are propagated backward and connected with the features extracted from H7, the full connection layer, which can make full use of the detailed features extracted from the network at the low level and realize the fusion of multi-level features.

InceptionV1 model

In order to extract the multi-scale features of the image, we can parallel the convolution kernel of different scales. In reference [1], we can do this by embedding the InceptionV1 model and InceptionV1 is improved and divided into four branches:

  1. Use a convolution layer of 1 × 1
  2. Use a convolution layer of 1 × 1, and then to use a convolution layer of 3 × 3, which is equal to two transformations
  3. Similarly, Use a convolution layer of 1 × 1, and then to use a convolution layer of 5 × 5
  4. Use a maximum pooling layer of 3 × 3, and then to use a convolution layer of 1 × 1

在这里插入图片描述

How to improve LeNet-5 model?

Based on the above description, the original LeNet-5 model is improved as follows, in which the Inception layer is the InceptionV1 model.
在这里插入图片描述
Due to the data set of the fire has not been sorted out yet, so MNIST data set is used for this experiment, and the process is as follows:

Code:

import numpy as np
import os
from keras.datasets import mnist
from keras.utils import np_utils
from keras.models import Sequential, Model
from keras.layers import Dense, Activation, Convolution2D, MaxPooling2D, Flatten, Input, Conv2D, MaxPool2D, concatenate
from keras.optimizers import SGD
np.random.seed(1337)
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'


def inception_v1(input_shape=(16, 5, 5)):
    input_ = Input(shape=input_shape)

    # Branches layers
    # Branches 1
    branch_1 = Conv2D(
        16,
        kernel_size=(1, 1),
        strides=(1, 1),
        activation='relu',
        padding='same',
        data_format='channels_first'
    )(input_)

    # Branches 2

    branch_2 = Conv2D(
        4,
        kernel_size=(1, 1),
        strides=(1, 1),
        activation='relu',
        padding='same',
        data_format='channels_first'
    )(input_)
    branch_2 = Conv2D(
        16,
        kernel_size=(3, 3),
        strides=(1, 1),
        activation='relu',
        padding='same',
        data_format='channels_first'
    )(branch_2)

    # Branches 3
    branch_3 = Conv2D(
        4,
        kernel_size=(1, 1),
        strides=(1, 1),
        activation='relu',
        padding='same',
        data_format='channels_first'
    )(input_)
    branch_3 = Conv2D(
        16,
        kernel_size=(5, 5),
        strides=(1, 1),
        activation='relu',
        padding='same',
        data_format='channels_first'
    )(branch_3)

    # Branches 4
    branch_4 = MaxPool2D(
        pool_size=(3, 3),
        strides=(1, 1),
        padding='same',
        data_format='channels_first'
    )(input_)
    branch_4 = Conv2D(
        16,
        kernel_size=(1, 1),
        strides=(1, 1),
        activation='relu',
        padding='same',
        data_format='channels_first'
    )(branch_4)

    output_ = concatenate([branch_1, branch_2, branch_3, branch_4], axis=1)
    model1 = Model(input_, output_)

    return model1


(X_train, y_train), (X_test, y_test) = mnist.load_data()

# data pre-processing
X_train = X_train.reshape(-1, 1, 28, 28)/255.
X_test = X_test.reshape(-1, 1, 28, 28)/255.
y_train = np_utils.to_categorical(y_train, num_classes=10)
y_test = np_utils.to_categorical(y_test, num_classes=10)

model = Sequential()

model.add(Convolution2D(
    batch_input_shape=(None, 1, 28, 28),
    filters=6,
    kernel_size=5,
    strides=1,
    padding='same',
    data_format='channels_first',
))
model.add(Activation('relu'))

model.add(MaxPooling2D(
    pool_size=3,
    strides=2,
    padding='same',
    data_format='channels_first',
))

model.add(Convolution2D(
    16,
    5,
    strides=1,
    padding='same',
    data_format='channels_first'
))
model.add(Activation('relu'))

model.add(MaxPooling2D(
    3,
    2,
    'same',
    data_format='channels_first'
))

# Inception layer 
model.add(inception_v1())

model.add(MaxPooling2D(
    3,
    2,
    'same',
    data_format='channels_first'
))

model.add(Flatten())
model.add(Dense(256))
model.add(Activation('relu'))

model.add(Dense(10))
model.add(Activation('softmax'))

model.compile(
    loss='categorical_crossentropy',
    optimizer=SGD(lr=0.1),
    metrics=['accuracy']
)

print('Training ------------')

model.fit(X_train, y_train, epochs=2, batch_size=64,)

print('\nTesting ------------')

loss, accuracy = model.evaluate(X_test, y_test)

print('\ntest loss: ', loss)
print('\ntest accuracy: ', accuracy)

Result:

test loss:  0.06726912458259612

test accuracy:  0.9769999980926514

Conclusion

  • When using the fire data set, it is necessary to change the relevant parameters in the model. Thus, it is necessary to identify the flame and verify the accuracy of the model.
  • The next step is to use contour sag and optical flow estimation to enhance the segmentation of the fire RIO region. More importantly, it is to improve the accuracy of CNN network, so as to reduce the dependence on RIO region segmentation and improve the accuracy of flame recognition from the whole.

Reference

[1]刘金利,张培玲.改进LeNet-5网络在图像分类中的应用[J].计算机工程与应用,2019,55(15):32-37+95.
LIU Jinli,ZHANG Peiling.Application of LeNet-5 neural network in image classification[J].Computer Engineering and Applications,2019,55(15):32-37.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值