opencv 识别火灾_使用深度学习和OpenCV早期火灾探测系统

opencv 识别火灾

深度学习| OpenCV (Deep learning | OpenCV)

Recent advancements in embedded processing have allowed vision-based systems to detect fire using Convolutional Neural Networks during surveillance. In this article, two custom CNN models have been implemented for a cost-effective fire detection CNN architecture for surveillance videos. The first model is a customized basic CNN architecture inspired by AlexNet architecture. We will implement and see its output and limitations and create a customized InceptionV3 model. To balance the efficiency and accuracy, the model is fine-tuned considering the nature of the target problem and fire data. We are going to use three different datasets for training our models. The links for the datasets are available at the end of this article. Let’s get to the coding part.

嵌入式处理技术的最新进展已使基于视觉的系统可以在监视过程中使用卷积神经网络检测火灾。 在本文中,已经实现了两个定制的CNN模型,以实现用于监视视频的经济有效的火灾探测CNN体系结构。 第一个模型是受AlexNet架构启发的定制的基本CNN架构。 我们将实现并查看其输出和限制,并创建一个定制的InceptionV3模型。 为了平衡效率和准确性,考虑目标问题和火灾数据的性质对模型进行了微调。 我们将使用三个不同的数据集来训练我们的模型。 数据集的链接在本文结尾处可用。 让我们进入编码部分。

1.创建定制的CNN架构 (1. Creating the customized CNN architecture)

We are going to use TensorFlow API Keras for building our model. Let’s first create our ImageDataGenerator for labeling our data. [1] and [2] datasets are used here for training. Finally, we will have 980 images for training and 239 images for validation. We are going to use data augmentation as well.

我们将使用TensorFlow API Keras构建模型。 首先创建用于标记数据的ImageDataGenerator。 [1]和[2]数据集在这里用于训练。 最后,我们将提供980张训练图像和239张验证图像。 我们还将使用数据增强。

import tensorflow as tf
import keras_preprocessing
from keras_preprocessing import image
from keras_preprocessing.image import ImageDataGeneratorTRAINING_DIR = "Train"
training_datagen = ImageDataGenerator(rescale = 1./255,
horizontal_flip=True,
rotation_range=30,
height_shift_range=0.2,
fill_mode='nearest')VALIDATION_DIR = "Validation"
validation_datagen = ImageDataGenerator(rescale = 1./255)
train_generator = training_datagen.flow_from_directory(TRAINING_DIR,
target_size=(224,224),
class_mode='categorical',
batch_size = 64)validation_generator = validation_datagen.flow_from_directory(
VALIDATION_DIR,
target_size=(224,224),
class_mode='categorical',
batch_size= 16)

In the above code, 3 data augmentation techniques are applied — horizontal flipping, rotation, and height shifting.

在上面的代码中,应用了3种数据增强技术-水平翻转,旋转和高度移位。

Now, we will create our CNN model. The model contains three Conv2D-MaxPooling2D layers pairs followed by 3 Dense layers. To overcome the problem of overfitting we will also add dropout layers. The last layer is the softmax layer which will give us the probability distribution for both the classes — Fire and Nonfire. One can also use ‘sigmoid’ activation function at the last layer by changing the number of classes to 1.

现在,我们将创建我们的CNN模型。 该模型包含三个Conv2D-MaxPooling2D层对,然后是3个密集层。 为了克服过度拟合的问题,我们还将添加辍学层。 最后一层是softmax层,它将为我们提供火灾和非火灾两类的概率分布。 通过将类数更改为1,还可以在最后一层使用“ Sigmoid”激活功能。

from tensorflow.keras.optimizers import Adam
model = tf.keras.models.Sequential([
tf.keras.layers.Conv2D(96, (11,11), strides=(4,4), activation='relu', input_shape=(224, 224, 3)), tf.keras.layers.MaxPooling2D(pool_size = (3,3), strides=(2,2)),
tf.keras.layers.Conv2D(256, (5,5), activation='relu'),
tf.keras.layers.MaxPooling2D(pool_size = (3,3), strides=(2,2)),
tf.keras.layers.Conv2D(384, (5,5), activation='relu'),<
  • 3
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值