Oil pan deflagration early warning system based on InteloneAPI

Preface

In the home scene, the most likely cause of fire is not pulling electric wires privately, smoking in bed, or heating appliances, but the kitchen, where oil pans are the most likely to catch fire. Most of the oil pans caught fire and exploded. If not dealt with in time, the fire will spread quickly.

This system plans to use oneAPI AI development tools to design a housekeeping departure early warning system. Provide early warning for oil pan fires caused by unattended, high oil level, improper placement of pots, etc.

Use AI to identify deflagration flames and cooperate with the Internet of Things device gateway to perform actions such as gate closing and fire alarm. Realize emergency intervention in case of oil pan deflagration and reduce property losses for users.

1. Plan introduction

Insert image description here

1. System Overview

The oil pan deflagration warning system is a safety early warning device based on artificial intelligence technology. It is used to monitor the status of the oil pan and provide timely warning of the occurrence of oil pan deflagration accidents. The system uses deep learning algorithms, uses cameras + sensors to collect various data such as oil pan temperature, smoke, gas, and real-time images, and achieves deflagration warning through model reasoning.
This system consists of software and hardware modules such as IoT equipment, cameras, IoT gateways, AI analysis modules, and early warning systems. This article mainly introduces the AI ​​image analysis module implemented by Intel OneAPI.

2. Design ideas

Insert image description here

Intel OneAPI is a cross-platform and cross-architecture software development framework for high-performance computing and artificial intelligence. It supports multiple programming languages, such as C++, Python, etc., as well as multiple hardware platforms, such as Intel Xe, GPU, FPGA wait. Cross-platform high-performance computing and artificial intelligence applications can be easily implemented using Intel OneAPI.

For the design of the oil pan deflagration warning system, this time we used the Intel OneAPI AI tool to build a solution. Here are the basic steps of the program:

  1. Collect data: First, you need to collect data related to the deflagration of the oil pan, including temperature, smoke, gas and other sensor data. This time we introduce the image analysis module, which trains our model by collecting a large number of deflagration flame and non-flame images. We used the open source FIRESENSE dataset to select data.

  2. Data preprocessing: Preprocess the collected data, including cleaning, normalization, feature extraction and other operations.

    input_image = cv2.resize(frame, (224, 224))
    input_tensor = torch.tensor(input_image).permute(2, 0, 1).unsqueeze(0).float()
    input_tensor /= 255
    input_tensor -= torch.tensor([0.485, 0.456, 0.406]).reshape((1, 3, 1, 1))
    input_tensor /= torch.tensor([0.229, 0.224, 0.225]).reshape((1, 3, 1, 1))
  1. Model training: Use the collected data to train the machine learning model. We use Intel PyTorch, etc. to train the model. When training a model, factors such as model parameters, hyperparameters, and loss functions need to be considered.
  2. Model evaluation: Use the test data set to evaluate the performance of the model and evaluate the accuracy, stability and other indicators of the model.
  3. Early warning system: Integrate machine learning models into the early warning system, use sensor data to monitor the status of the oil pan in real time, and use model prediction results to issue early warnings.

2. Plan implementation

1.ResNet-18 model

ResNet-18 is a variant of the deep residual network (ResNet), consisting of 18 residual blocks. This model can be used for image recognition tasks.

First load the pretrained ResNet-18 model from the PyTorchvision library. We then defined the categories for flame recognition and loaded a test image. Next, we use transforms to preprocess the image, convert it into a tensor and feed it into the ResNet-18 model for inference.

...简单示意
model = torchvision.models.resnet18(pretrained=True)

2.Usage of Intel OneAPI AI Kit

1.Intel® Neural Compressor:

Intel® Neural Compressor is designed to provide popular model compression technologies such as quantization, pruning ( sparsity), distillation, and neural architecture search.

# 应用Intel® Neural Compressor压缩并保存压缩模型

compression_config = {
    'algorithm': 'Quantization',
    'params': {
        'precision': 8,
        'preserve_sparsity': False,
        'mode': 'ASYMMETRIC',
        'per_tensor_compression_ratio': 0.5
    }
}
compressed_model = apply_compression(model, compression_config)
torch.save(compressed_model, 'fire_quantized.pth')
quantized_model = torch.load('fire_quantized.pth')

2.Intel® Optimization for PyTorch*

PyTorch is a machine learning open source framework based on the mainstream Torch library. Intel® PyTorch* extensions provide additional optimizations for PyTorch,

  1. Install PyTorch: First, you need to install PyTorch. You can download and install the latest version of PyTorch from the official PyTorch website. Make sure your version of PyTorch supports Intel Optimization for PyTorch.

  2. Install Intel Optimization for PyTorch: Download and install the latest version of Intel Optimization for PyTorch from the official Intel website. You can use pip or conda to download Intel Optimization for PyTorch.

  3. Import PyTorch and the optimizer: In your Python code, import PyTorch and the Intel Optimization for PyTorch optimizer.

  4. Create a model and optimizer: Create a PyTorch model and an Intel Optimization for PyTorch optimizer. When creating an optimizer, you need to specify the type of optimizer to use (e.g. AdamW) and the hyperparameters.

#使用optimize函数进行优化
quantized_model = ipex.optimize(quantized_model)

# 在最后一层输出之前添加一个全连接层
num_ftrs = quantized_model.fc.in_features
quantized_model.fc = torch.nn.Linear(num_ftrs, 2)
# 将模型转换为推理模式
quantized_model.eval()

  1. Train the model: Use the optimizer to train your model. You can use PyTorch's built-in function train() or use your own training loop.
    # 使用量化模型进行推理
    with torch.no_grad():
        output = quantized_model(input_tensor)
        predictions = torch.softmax(output, dim=1)
        _, predicted_class = torch.max(predictions, dim=1)

    # 在图像上绘制结果
    cv2.putText(frame, classes[predicted_class.item()], (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)
    cv2.imshow('Fire Detection', frame)

  1. Test the model: Use the test dataset to test your model.

3. Solution value

  • Practical value:
    This system has a wide range of application scenarios and can be widely used in the home and housekeeping industries. Since smoke alarms are generally not installed in kitchens, wok deflagration detection has certain practical value. The user group includes individual household users, house rental companies, and long-term housekeeping service companies.
  • Risk Resistance:
    For shared housing and housekeeping companies, this system can reduce unnecessary fire safety risks for third parties, and retain images and videos as evidence of deflagration accidents that have occurred. It provides data support for the identification of subsequent accident liability, so the system has certain economic value and anti-risk capabilities.
  • Innovation:
    Through the use of Intel tools, the IoT gateway is combined with AI algorithms to be implemented in kitchen scenes and closely related to people's livelihood. This solution is different from the traditional single video algorithm or IoT alarm, and adopts a solution that combines software and hardware. It provides flexibility and scalability while ensuring the accuracy of identification of IoT devices.

Summarize

This demo implements the detection of wok deflagration using the pre-trained ResNet-18 model through intel-aikit-pytorch.
And the efficiency of the overall model is improved by using tools such as ipex and apply_compression.
After this competition, I learned to use Intel's development kit and gained a lot.
The subsequent addition of IoT functions and face capture functions can improve the system application.

Guess you like

Origin blog.csdn.net/weixin_50077637/article/details/131353937