Intelligent supervision patrol early warning system
By designing an intelligent supervision and inspection and early warning system that integrates behavior analysis, face analysis, business disposal and early warning linkage, the problems of monitoring fatigue, insufficient display and poor warning timeliness in the existing supervision system are solved, and 24-hour uninterrupted monitoring and rapid early warning linkage disposal are achieved, improving the monitoring and handling efficiency of violations.
Patent Information
- Application Number
- CN202510026841.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-08
- Publication Date
- 2025-04-29
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing regulatory system has problems such as visual fatigue, insufficient display, difficulty in analysis, passive monitoring, poor timeliness for transmission of violations and poor real-time linkage, making it difficult to effectively monitor and handle violations.
An intelligent supervision and inspection early warning system was designed, integrating functions such as behavioral analysis, face analysis, business disposal and early warning linkage. Through the image acquisition and storage module, data analysis module and early warning linkage treatment module, 24-hour uninterrupted monitoring and rapid early warning linkage treatment are achieved.
It solves the problem of manual inspection being unable to remain vigilant and the number of cameras and monitors not matching, realizes joint handling of surveillance, active monitoring and rapid early warning, and improves the efficiency of discovery and handling of violations.
Smart Images

Figure CN119906875A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of intelligent supervision systems, and in particular to an intelligent supervision, patrol and early warning system. Background Art
[0002] At present, cameras are being installed more and more widely in various regions, especially in large-scale supervision sites and key supervision areas, where a large number of cameras have been installed, video surveillance systems and monitoring duty rooms have been established, and 24-hour uninterrupted monitoring is achieved, using manual viewing and video rotation mode for surveillance. However, there are many problems in the operation of this mode.
[0003] 1) Visual fatigue: unable to stay alert, unable to maintain attention, easy to miss important screen information. According to the survey, the staff on duty stared at the monitoring screen for 22 minutes and ignored 95% of the subsequent screen information.
[0004] 2) Insufficient display: The number of cameras is far greater than the number of monitors. Instead of using a 1:1 display method, a polling display and multiple small images are used. There are large inspection blind spots, and it is very likely that abnormal phenomena will be missed and the situation will be allowed to develop.
[0005] 3) Difficulty in analysis: Monitoring and video recording are separated, so it is impossible to "capture the moment" or quickly retrieve video recordings for analysis. Especially when the staff on duty are tired at midnight, it is difficult for them to concentrate on analyzing, judging, and eliminating doubts about the abnormal behavior that just occurred.
[0006] 4) Passive monitoring: The current video content is only for reference after the fact. The probability of discovery before and during the event is low, and the losses and impacts caused are not proportional to the investment. It is completely a "passive monitoring" of "closing the fold after the sheep have been bolted".
[0007] 5) Poor timeliness of violation warning transmission: Warning discovery is often reflected in a single duty room, and it is impossible to quickly and accurately transmit warning events to related units and leaders.
[0008] 6) Poor real-time linkage: When routine inspections discover violations, most of the time they are called through intercoms to on-duty personnel to deal with them. There is a lack of linkage equipment at the scene of the violation, making it impossible to stop or warn in the first place.
[0009] In view of the defects and shortcomings of existing technologies and models, it is hoped to provide a regulatory system that can solve the above-mentioned technical problems. Summary of the invention
[0010] The purpose of the present invention is to provide an intelligent supervision, inspection and early warning system in response to the defects and shortcomings of the prior art. It is a business system that integrates behavior analysis, face analysis, business disposal and early warning linkage. It can monitor daily violations 24 hours a day and realize a working mode of rapid discovery, rapid warning and linkage disposal of violations.
[0011] To achieve the above-mentioned purpose, the present invention adopts the following technical scheme: it includes an image acquisition and storage module, a data analysis module, and an early warning linkage disposal module; the image acquisition and storage module includes surveillance camera A, surveillance camera B, surveillance camera C, surveillance camera D, surveillance camera E, surveillance camera F, optical terminal switch A, network switch A, network switch B, and hard disk recorder A, surveillance camera A, surveillance camera B, and surveillance camera C are connected to network switch A, machine A is linked to network switch A, network switch A is connected to surveillance camera D, surveillance camera E, and surveillance camera F connected to optical terminal switch A, optical terminal switch hard disk recorder A, hard disk recorder A is connected to network switch B, and video data is transmitted through data transmission. The data is pushed to the data analysis module; the data analysis module includes behavior analysis server A, face analysis server A, network switch C, client computer A, business processing server A, storage server A, and network switch D. The video stream pushed by the image acquisition and storage module is connected to the behavior analysis server A and face analysis server A. The behavior analysis server A and face analysis server A are connected to the network switch C. The client computer A, business processing server A, and storage server A are connected to the network switch C at the same time. The business processing server A is connected to the network switch D, and the early warning linkage processing module is connected through the network switch D. The early warning linkage processing module includes the early warning processing platform, system pop-up window + sound and light alarm, large screen display, and broadcasting system. The network switch D is directly connected to the early warning processing platform, system pop-up window + sound and light alarm, large screen display, and broadcasting system.
[0012] Furthermore, the connections between the various component devices are all 5G electrical signal connections.
[0013] Furthermore, the behavior analysis server A is composed of a high-performance processor, a high-speed solid-state hard drive, running data analysis software, and a machine learning framework.
[0014] Furthermore, the face analysis server A is composed of a high-performance graphics processing unit GPU and a computer vision library and a deep learning framework.
[0015] Furthermore, the operating data analysis software and machine learning framework use data analysis scripts written in Python and are combined with machine learning frameworks such as TensorFlow or PyTorch for behavioral modeling.
[0016] Furthermore, the high-speed solid-state hard drive is used to store and manage behavior data using MySQL or MongoDB.
[0017] Furthermore, the high-performance graphics processing unit GPU is used to accelerate the operation of deep learning algorithms;
[0018] Furthermore, the running computer vision library is the OpenCV computer vision library.
[0019] Furthermore, the deep learning framework is TensorFlow or PyTorch.
[0020] The working principle of the present invention is as follows: the monitoring camera obtains the front-end video screen and transmits it to the network switch through a network cable or optical fiber. The network link input end of the network switch receives the video data and outputs it to the hard disk recorder through several network links. The behavior analysis server and the face analysis server obtain the real-time video screen from the hard disk recorder through the network link of the network switch and perform analysis and comparison. When a set violation event is found, the video image is intercepted and packaged in combination with the early warning monitoring information. The data packet is transmitted to the business disposal server through the TCP / IP communication protocol. The business disposal server screens and classifies the data, and sends the data and signals to the early warning disposal platform and the large-screen display end according to the corresponding classification. The system pop-up window + sound and light alarm are synchronously called to remind the check-in personnel. The early warning information is quickly sent to the early warning point in combination with the broadcasting system to remind the personnel to handle it.
[0021] After adopting the above technical scheme, the beneficial effects of the present invention are as follows: it can solve the problem that manual surveillance cannot maintain constant vigilance and attention is difficult to sustain, can achieve 24-hour uninterrupted monitoring of daily violations, solve the problem of unequal number of cameras and monitors, and realize monitoring without viewing angles. There is no need to separate monitoring from recording, which makes it convenient for staff to concentrate on analyzing and judging abnormal images and eliminate suspicion; and it can realize active monitoring, with high timeliness of violation warning transmission and very high real-time linkage, realizing a working mode of rapid discovery, rapid warning, and linkage disposal of violations. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0023] Figure 1 It is a schematic diagram of the structural framework of the present invention. DETAILED DESCRIPTION
[0024] See also Figure 1 As shown, the technical solution adopted in this specific implementation is: it includes an image acquisition and storage module, a data analysis module, and an early warning linkage disposal module; the image acquisition and storage module includes surveillance camera A, surveillance camera B, surveillance camera C, surveillance camera D, surveillance camera E, surveillance camera F, optical terminal switch A, network switch A, network switch B, and hard disk recorder A, surveillance camera A, surveillance camera B, and surveillance camera C are connected to network switch A, machine A is linked to network switch A, network switch A is connected to surveillance camera D, surveillance camera E, and surveillance camera F connected to optical terminal switch A, optical terminal switch hard disk recorder A, hard disk recorder A is connected to network switch B, and video data is transmitted through data transmission. Push to the data analysis module; the data analysis module includes behavior analysis server A, face analysis server A, network switch C, client computer A, business processing server A, storage server A, network switch D, the video stream pushed by the image acquisition storage module is connected to the behavior analysis server A and face analysis server A, the behavior analysis server A and face analysis server A are connected to the network switch C, the client computer A, business processing server A, storage server A are connected to the network switch C at the same time, the business processing server A is connected to the network switch D, and the early warning linkage processing module is connected through the network switch D; the early warning linkage processing module includes the early warning processing platform, system pop-up window + sound and light alarm, large screen display, and broadcasting system. The network switch D is directly connected to the early warning processing platform, system pop-up window + sound and light alarm, large screen display, and broadcasting system.
[0025] Furthermore, the connections between the various component devices are all 5G electrical signal connections; 5G signals can meet the needs of these devices to connect simultaneously and transmit data, realize the vision of the Internet of Everything, ensure the accuracy and stability of data transmission, and avoid serious consequences caused by network failures. Compared with 4G, it can support device communication with lower power consumption.
[0026] Furthermore, the behavior analysis server A is composed of a high-performance processor, a high-speed solid-state hard drive, running data analysis software, and a machine learning framework; it can collect data from multiple channels, including but not limited to network traffic data, user operation records (such as mouse clicks, keyboard input), device status information (such as sensor readings), etc., clean, organize and format the collected raw data, and use machine learning, data mining and other technologies to establish a behavior model. It can monitor behavior data in real time and issue alarms or feedback in a timely manner when specific behavior patterns or abnormal situations are found.
[0027] Furthermore, the face analysis server A is composed of a high-performance graphics processing unit GPU and a running computer vision library and deep learning framework; a target monitoring algorithm based on deep learning is adopted. Advanced computer vision and artificial intelligence technologies are used to process the input face image or video stream to extract various valuable information. It can accurately locate the face in a complex image or video background, recognize the identity difference between different faces, analyze the facial expressions, including happiness, sadness, anger, surprise, etc., estimate the age and gender of the person based on the features of the face, and determine the posture of the face, including the rotation, pitch and tilt angle of the head.
[0028] Furthermore, the operating data analysis software and machine learning framework use data analysis scripts written in Python and are combined with machine learning frameworks such as TensorFlow or PyTorch for behavioral modeling.
[0029] Furthermore, the high-speed solid-state hard disk is used to store and manage the behavior data, using MySQL or MongoDB. MySQL is suitable for structured data storage, while MongoDB is more suitable for storing unstructured or semi-structured behavior records. At the same time, message queue software (such as RabbitMQ) may also be needed to manage the inflow and processing order of data.
[0030] Furthermore, the high-performance graphics processing unit GPU is used to accelerate the operation of deep learning algorithms;
[0031] Furthermore, the operating computer vision library is the OpenCV computer vision library, which is used for basic image operations and some traditional face detection algorithms.
[0032] Furthermore, the deep learning framework is TensorFlow or PyTorch, which is used to train and deploy neural network models related to face analysis.
[0033] The basic process of using Python combined with TensorFlow for simple behavior modeling (taking user purchase behavior prediction as an example):
[0034] 1. Data Collection and Preprocessing
[0035] 1. Data Collection
[0036] First, you need to collect data related to user behavior. For example, to predict user purchase behavior, you can collect data such as the user's historical purchase records, browsing history, and product reviews. This data can come from a database, log file, or third-party data provider. Assume that the data is stored in a CSV file, and each row represents the relevant behavior data of a user, including user ID, purchased product category, browsing time, etc.
[0037] You can use Python's pandas library to read the data. The sample code is as follows:
[0038] import pandas as pd
[0039] data=pd.read_csv("user_behavior_data.csv")
[0040] 2. Data Preprocessing
[0041] Handling missing values: Check if there are missing values in the data. If so, you can use the mean, median, or most frequently occurring value to fill the missing values. For example, for a numeric browsing time column, if there are missing values, you can use the mean to fill them.
[0042] #Assume the browsing time column is named 'browsing_time'
[0043] mean_browsing_time=data['browsing_time'].mean()
[0044] data['browsing_time'].fillna(mean_browsing_time,inplace=True)
[0045] Data standardization or normalization: To make the numerical ranges of different features comparable, standardize the data (for example, convert the data to a distribution with a mean of 0 and a standard deviation of 1) or normalize the data (map the data to the interval 0-1). For numerical features such as browsing time and purchase price, you can use StandardScaler or MinMaxScaler from the scikit-learn library.
[0046] from sklearn.preprocessing import StandardScaler
[0047] scaler = StandardScaler()
[0048] numerical_features=['browsing_time','purchase_price']
[0049] data[numerical_features]=scaler.fit_transform(data[numerical_features])
[0050] Categorical data encoding: If the data contains categorical features, such as product categories, it needs to be converted into numerical representation. One-Hot Encoding can be used.
[0051] from sklearn.preprocessing import OneHotEncoder
[0052] encoder=OneHotEncoder(sparse=False)
[0053] category_features=['product_category']
[0054] encoded_categories=encoder.fit_transform(data[category_features])
[0055] #Merge the encoded category data into the original data
[0056] data=pd.concat([data.drop(category_features,axis=1),pd.DataFrame(encoded_categories)],axis=1)
[0057] 2. Dividing the Dataset
[0058] 1. Split the data
[0059] The preprocessed data is divided into training set, validation set and test set. The training set is used to train the model, the validation set is used to adjust the model's hyperparameters, and the test set is used to evaluate the final performance of the model. It can usually be divided in a ratio of 70%:15%:15%.
[0060] from sklearn.model_selection import train_test_split
[0061] X = data.drop('purchase_decision',axis = 1) #Feature data, assuming the last column is the purchase decision
[0062] y=data['purchase_decision']#Target data
[0063] X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.3,random_state=42)
[0064] X_val,X_test,y_val,y_test=train_test_split(X_test,y_test,test_size=0.5,random_state=42)
[0065] 3. Build the model (using TensorFlow)
[0066] 1. Import the library and define the model architecture
[0067] Import the TensorFlow library and define a simple neural network model. For example, build a multi-layer perceptron (MLP) model with one input layer, one hidden layer, and one output layer.
[0068] import tensorflow as tf
[0069] model = tf.keras.Sequential([
[0070] tf.keras.layers.Dense(128,activation='relu',input_shape=(X_train.shape[1],)),
[0071] tf.keras.layers.Dense(1,activation='sigmoid') ])
[0073] Here, the first hidden layer has 128 neurons, uses the ReLU activation function, and the input shape is determined by the number of features in the training data. The output layer has 1 neuron and uses the Sigmoid activation function for binary classification (predicting whether the user will buy).
[0074] 2. Before training the model, you need to compile the model, specify the loss function, optimizer, and evaluation metrics.
[0075] model.compile(loss='binary_crossentropy',
[0076] optimizer = 'adam',
[0077] metrics = ['accuracy'])
[0078] For the binary classification problem, binary cross entropy (binary_crossentropy) is used as the loss function, adam is used as the optimizer, and accuracy is selected as the evaluation indicator.
[0079] 4. Model training and verification
[0080] 1. Model training
[0081] Use the training set to train the model, specify the number of training rounds (epochs) and batch size (batch_size).
[0082] history=model.fit(X_train,y_train,
[0083] epochs=10,
[0084] batch_size=32,
[0085] validation_data=(X_val,y_val))
[0086] During the training process, the model will adjust the weights according to the training data. After each round of training, the model performance will be evaluated on the validation set, and the loss and accuracy during the training process will be recorded. These indicators can be viewed through the history object.
[0087] 2. Model Validation
[0088] After training is complete, you can view the performance of the model on the validation set. For example, you can plot the loss curve and accuracy curve for training and validation to see whether the model is overfitting or underfitting.
[0089] import matplotlib.pyplot as plt
[0090] plt.plot(history.history['loss'],label="Training Loss")
[0091] plt.plot(history.history['val_loss'],label='Validation Loss')
[0092] plt.xlabel('Epoch')
[0093] plt.ylabel('Loss')
[0094] plt.legend()
[0095] plt.show()
[0096] plt.plot(history.history['accuracy'],label="Training Accuracy")
[0097] plt.plot(history.history['val_accuracy'],label='ValidationAccuracy')
[0098] plt.xlabel('Epoch')
[0099] plt.ylabel('Accuracy')
[0100] plt.legend()
[0101] plt.show()
[0102] 5. Model Evaluation and Application
[0103] 1. Model Evaluation
[0104] The model is finally evaluated using the test set to get the performance of the model on unseen data.
[0105] test_loss,test_accuracy=model.evaluate(X_test,y_test)
[0106] print(f"Test Loss:{test_loss},Test Accuracy:{test_accuracy}")
[0107] 2. Model Application
[0108] Once the model performance meets the requirements, the model can be applied to actual scenarios. For example, for new user behavior data, the model can be used to predict purchase behavior.
[0109] new_user_data = [...] # New user behavior data, needs to be in the same format as training data
[0110] prediction=model.predict(new_user_data)
[0111] if prediction>0.5:
[0112] print("Users may buy")
[0113] else:
[0114] print("Users may not buy").
[0115] RabbitMQ) to manage the inflow and processing order of data:
[0116] 1. Producer sends message process
[0117] Establishing a connection
[0118] First, the producer (the application sending the message) needs to establish a connection with the RabbitMQ server. This is achieved by using a suitable client library (such as the pika library in Python). When establishing a connection, you need to specify the RabbitMQ server's host name, port number (the default is 5672), username and password.
[0119] For example, the code to establish a connection using the pika library in Python is as follows:
[0120] import pika
[0121] connection=pika.BlockingConnection(pika.ConnectionParameters('localhost',5672,' / ',pika.PlaintextCredentials('guest','guest')))
[0122] channel=connection.channel()
[0123] Declare queue
[0124] After the connection is established, the producer can declare one or more queues. A queue is a place where messages are stored and has a unique name. If the queue does not exist, the declaration operation will create it; if the queue already exists, the declaration operation will only confirm the properties of the queue.
[0125] For example, the code to declare a queue named my_queue is as follows:
[0126] channel.queue_declare(queue='my_queue')
[0127] Send Message
[0128] The producer sends the message to the specified queue. The message can be data in any format and is usually serialized into a byte array. When sending a message, you need to specify the queue name, message properties (such as message persistence settings, etc.) and message content.
[0129] For example, the code to send a simple text message is as follows:
[0130] message = 'Hello, RabbitMQ! '
[0131] channel.basic_publish(exchange=", routing_key='my_queue', body=message.encode('utf-8'))
[0132] Here, exchange="" means using the default exchanger (simple exchanger), the value of routing_key is the queue name, body is the message content, and the message content is encoded as a byte array because RabbitMQ requires messages to be sent in byte form.
[0133] 2. Message storage process in RabbitMQ server
[0134] When a message is sent to a queue, the RabbitMQ server stores the message in memory or on disk, depending on the configuration of the queue and the load on the server.
[0135] If the queue is configured to be persistent (by setting the queue's properties), the message will be written to disk to ensure that the message is not lost in the event of a server restart, etc. RabbitMQ uses Erlang's storage mechanism to manage the storage of messages, and it arranges the storage location of the message in the queue based on factors such as the priority and order of the message.
[0136] At the same time, RabbitMQ maintains the metadata of the message, such as the message ID, sending time, receiving time and other information, which can be used for message tracking and management.
[0137] 3. Consumer receiving message process
[0138] Establish a connection and declare a queue (similar to producers)
[0139] The consumer (the application that receives the message) also needs to establish a connection with the RabbitMQ server and declare the queue to receive the message. This process is basically the same as the steps for the producer to establish a connection and declare the queue.
[0140] Set the message callback function
[0141] Consumers need to set a message callback function, which will be called when a message arrives in the queue and is assigned to the consumer. The main task of the callback function is to process the received message, such as deserializing the message content and executing the corresponding business logic.
[0142] For example, the code to set the message callback function in Python is as follows:
[0143] def callback(ch,method,properties,body):
[0144] print("Received message:",body.decode('utf-8'))
[0145] Start receiving messages
[0146] The consumer starts receiving messages by calling the basic_consume method. This method requires specifying the queue name and the message callback function. When a message arrives in the queue, RabbitMQ will distribute the message to the consumer, and the consumer's callback function will be called to process the message.
[0147] For example, the code to start receiving messages from the my_queue queue is as follows:
[0148] channel.basic_consume(queue='my_queue', on_message_callback=callback, auto_ack=True)
[0149] channel.start_consuming()
[0150] Here, auto_ack = True means automatic confirmation of the message. In actual applications, if the business logic is complex, you may need to manually confirm the message to ensure that the message is not lost. When the consumer successfully processes the message, it will send a confirmation signal to the RabbitMQ server. After receiving the confirmation signal, the server will delete the message from the queue.
[0151] Use TensorFlow to train and deploy neural network models related to face analysis:
[0152] 1. Data preparation stage
[0153] Data Collection:
[0154] Collect datasets containing face images, such as the publicly available LFW (Labeled Faces in the Wild) dataset, CelebA dataset, etc. These datasets contain face images with different angles, lighting conditions, expressions, etc.
[0155] Data preprocessing:
[0156] Normalize the image and normalize the pixel values to a suitable range, such as converting the pixel value range of an RGB image from 0-255 to 0-1. This can be achieved using the tf.image module, for example:
[0157] import tensorflow as tf
[0158] def preprocess_image(image):
[0159] image=tf.cast(image,tf.float32) / 255.0
[0160] return image
[0161] Data augmentation is also important to increase data diversity and prevent model overfitting. Random flipping, rotation, cropping, etc. can be performed. For example:
[0162] def augment_image(image):
[0163] image=tf.image.random_flip_left_right(image)
[0164] image=tf.image.random_rotate(image,0.2)
[0165] return image
[0166] 2. Model building phase
[0167] Choose the appropriate model architecture:
[0168] For face recognition, you can use a convolutional neural network (CNN)-based architecture, such as ResNet, Inception, etc. Take a simple custom CNN as an example:
[0169] model = tf.keras.Sequential([
[0170] tf.keras.layers.Conv2D(32,(3,3),activation='relu',input_shape=(image_height,image_width,3)),
[0171] tf.keras.layers.MaxPooling2D((2,2)),
[0172] tf.keras.layers.Conv2D(64,(3,3),activation='relu'),
[0173] tf.keras.layers.MaxPooling2D((2,2)),
[0174] tf.keras.layers.Flatten(),
[0175] tf.keras.layers.Dense(128,activation='relu'),
[0176] tf.keras.layers.Dense(num_classes,activation='softmax') ])
[0178] Here we assume that it is a multi-classification face identification task, and num_classes is the number of face categories.
[0179] Compile the model:
[0180] Select appropriate loss functions, optimizers, and evaluation indicators. For classification tasks, the cross entropy loss function is commonly used, such as tf.keras.losses.CategoricalCrossentropy, the optimizer can be Adam, and the evaluation indicator can be accuracy.
[0181] model.compile(loss=tf.keras.losses.CategoricalCrossentropy(),
[0182] optimizer=tf.keras.optimizers.Adam(),
[0183] metrics = ['accuracy'])
[0184] 3. Model training phase
[0185] Train the model:
[0186] Use the training set data to train the model, specify the number of training rounds (epochs) and batch size (batch_size). For example:
[0187] history=model.fit(train_dataset,epochs=10,batch_size=32,validation_data=val_dataset)
[0188] 4. Model evaluation phase
[0189] Evaluate model performance:
[0190] Use the test set to evaluate the final performance of the model and calculate indicators such as accuracy and recall. For example:
[0191] test_loss,test_acc=model.evaluate(test_dataset)
[0192] print('Test accuracy:',test_acc)
[0193] 5. Model deployment phase
[0194] Save the model:
[0195] Save the trained model in a suitable format, such as .h5 format.
[0196] model.save('face_analysis_model.h5')
[0197] Load the model for prediction:
[0198] In actual applications, load the saved model to analyze new face images. For example:
[0199] loaded_model=tf.keras.models.load_model('face_analysis_model.h5')
[0200] new_image=preprocess_image(new_image_data)
[0201] prediction=loaded_model.predict(new_image[tf.newaxis,...])
[0202] Use PyTorch to train and deploy neural network models related to face analysis:
[0203] 1. Data preparation stage
[0204] Data collection and loading:
[0205] Similarly, collect the face image dataset and load it into memory. You can use the torchvision.datasets module to load common datasets, such as ImageFolder to load custom datasets. For example:
[0206] import torchvision.datasets as datasets
[0207] import torchvision.transforms as transforms
[0208] train_dataset=datasets.ImageFolder(root='train_data_path',transform=transforms.Compose([
[0209] transforms.ToTensor(),
[0210] transforms.Normalize((0.5,0.5,0.5),(0.5,0.5,0.5)) ]))
[0212] Here transforms are used for data preprocessing, converting images into tensors and normalizing them.
[0213] Data partitioning:
[0214] Use the torch.utils.data.random_split function to divide the dataset into training, validation, and test sets. For example:
[0215] from torch.utils.data import random_split
[0216] train_size=int(0.7*len(train_dataset))
[0217] val_size=int(0.2*len(train_dataset))
[0218] test_size=len(train_dataset)-train_size-val_size
[0219] train_dataset,val_dataset,test_dataset=random_split(train_dataset,[train_size,val_size,test_size])
[0220] 2. Model building phase
[0221] Define the model architecture:
[0222] In PyTorch, you need to define a class that inherits from torch.nn.Module to build a model. Take a simple CNN as an example:
[0223] import torch.nn as nn
[0224] class FaceAnalysisModel(nn.Module):
[0225] def__init__(self,num_classes):
[0226] super(FaceAnalysisModel,self).__init__()
[0227] self.conv1=nn.Conv2D(32,(3,3),padding=1)
[0228] self.relu1 = nn.ReLU()
[0229] self.pool1=nn.MaxPool2D((2,2))
[0230] self.conv2=nn.Conv2D(64,(3,3),padding=1)
[0231] self.relu2 = nn.ReLU()
[0232] self.pool2=nn.MaxPool2D((2,2))
[0233] self.fc1=nn.Linear(64*image_height*image_width / / 16,128)
[0234] self.relu3 = nn.ReLU()
[0235] self.fc2=nn.Linear(128,num_classes)
[0236] def forward(self,x):
[0237] x = self.conv1(x)
[0238] x = self.relu1(x)
[0239] x = self.pool1(x)
[0240] x = self.conv2(x)
[0241] x = self.relu2(x)
[0242] x = self.pool2(x)
[0243] x=x.view(-1,64*image_height*image_width / / 16)
[0244] x = self.fc1(x)
[0245] x = self.relu3(x)
[0246] x = self.fc2(x)
[0247] return x
[0248] model=FaceAnalysisModel(num_classes)
[0249] Define the loss function and optimizer:
[0250] For classification tasks, the loss function can be cross entropy loss, such as nn.CrossEntropyLoss, and the optimizer can be torch.optim.Adam. For example:
[0251] criterion=nn.CrossEntropyLoss()
[0252] optimizer=torch.optim.Adam(model.parameters(),lr=0.001)
[0253] 3. Model training phase
[0254] Training loop:
[0255] Set the number of training rounds. In each round, traverse the training data set, perform forward propagation, calculate loss, back propagate, and update weights. For example:
[0256] for epoch in range(num_epochs):
[0257] running_loss=0.0
[0258] for i,(inputs,labels)in enumerate(train_loader):
[0259] optimizer.zero_grad()
[0260] outputs = model (inputs)
[0261] loss=criterion(outputs,labels)
[0262] loss.backward()
[0263] optimizer.step()
[0264] running_loss+=loss.item()
[0265] print('Epoch[%d / %d],Loss:%.4f'%(epoch+1,num_epochs,running_loss / len(train_loader)))
[0266] 4. Model evaluation phase
[0267] Evaluate model performance:
[0268] Use the test set to evaluate the performance of the model and calculate indicators such as accuracy. For example:
[0269] correct=0
[0270] total=0
[0271] with torch.no_grad():
[0272] for inputs,labels in test_loader:
[0273] outputs = model (inputs)
[0274] _,predicted=torch.max(outputs.data,1)
[0275] total+=labels.size(0)
[0276] correct+=(predicted==labels).sum().item()
[0277] print('Accuracy of the model on the test images:%d%%'%(100*correct / total))
[0278] 5. Model deployment phase
[0279] Save the model:
[0280] Use the torch.save function to save the model's state dictionary (including the model's weights and other information). For example:
[0281] torch.save(model.state_dict(),'face_analysis_model.pth')
[0282] Load the model for prediction:
[0283] In actual applications, load the saved model to analyze new face images. For example:
[0284] loaded_model=FaceAnalysisModel(num_classes)
[0285] loaded_model.load_state_dict(torch.load('face_analysis_model.pth'))
[0286] loaded_model.eval()
[0287] new_image=preprocess_image(new_image_data)
[0288] with torch.no_grad():
[0289] prediction=loaded_model(new_image[None,...])
[0290] The above description is only used to illustrate the technical solution of the present invention rather than to limit it. Other modifications or equivalent substitutions made to the technical solution of the present invention by ordinary technicians in this field should be included in the scope of the claims of the present invention as long as they do not depart from the spirit and scope of the technical solution of the present invention.
Claims
1. Intelligent supervision and inspection early warning system, characterized by: It includes an image acquisition and storage module, a data analysis module, and an early warning linkage disposal module; the image acquisition and storage module includes surveillance camera A, surveillance camera B, surveillance camera C, surveillance camera D, surveillance camera E, surveillance camera F, optical switch A, network switch A, network switch B, and hard disk recorder A. Surveillance camera A, surveillance camera B, and surveillance camera C are connected to network switch A, machine A is connected to network switch A, network switch A is connected to surveillance camera D, surveillance camera E, and surveillance camera F connected to optical switch A, optical switch hard disk recorder A, hard disk recorder A is connected to network switch B, and video data is pushed to the data analysis module through data transmission. The data analysis module includes a behavior analysis server A, a face analysis server A, a network switch C, a client computer A, a business processing server A, a storage server A, and a network switch D. The video stream pushed by the image acquisition storage module is connected to the behavior analysis server A and the face analysis server A. The behavior analysis server A and the face analysis server A are connected to the network switch C. The client computer A, the business processing server A, and the storage server A are connected to the network switch C at the same time. The business processing server A is connected to the network switch D, and the early warning linkage processing module is connected through the network switch D. The early warning linkage processing module includes an early warning processing platform, a system pop-up window + sound and light alarm, a large screen display, and a broadcasting system. The network switch D is directly connected to the early warning processing platform, the system pop-up window + sound and light alarm, a large screen display, and a broadcasting system.
2. The intelligent supervision, inspection and early warning system according to claim 1 is characterized by: The connections between the various component devices are all 5G electrical signal connections.
3. The intelligent supervision, inspection and early warning system according to claim 1 is characterized by: The behavior analysis server A is composed of a high-performance processor, a high-speed solid-state hard disk, running data analysis software, and a machine learning framework.
4. The intelligent supervision, inspection and early warning system according to claim 1 is characterized by: The face analysis server A is composed of a high-performance graphics processing unit GPU and a computer vision library and a deep learning framework.
5. The intelligent supervision, inspection and early warning system according to claim 3 is characterized by: The operating data analysis software and machine learning framework use data analysis scripts written in Python and are combined with machine learning frameworks such as TensorFlow or PyTorch for behavior modeling.
6. The intelligent supervision, inspection and early warning system according to claim 3 is characterized by: The high-speed solid-state hard disk is used to store and manage behavior data, using MySQL or MongoDB.
7. The intelligent supervision, inspection and early warning system according to claim 4 is characterized by: The high-performance graphics processing unit GPU is used to accelerate the operation of deep learning algorithms.
8. The intelligent supervision, inspection and early warning system according to claim 4 is characterized by: The running computer vision library is the OpenCV computer vision library.
9. The intelligent supervision, inspection and early warning system according to claim 4 is characterized by: The deep learning framework is TensorFlow or PyTorch.