Lightweight target detection method, apparatus and device for embedded device, and medium
By replacing the C2f module with the GhostC2f module in the YOLOv8 network, and combining the ECA attention mechanism and the H-Swish activation function, a lightweight object detection model is built, which solves the problem of limited computing resources of embedded devices and realizes efficient deployment and training.
Patent Information
- Application Number
- CN202510598334.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-09
- Publication Date
- 2025-07-29
AI Technical Summary
Embedded devices have limited computing power and storage capacity, and traditional deep learning models require too high computing resources and memory, making it difficult to deploy lightweight object detection models on embedded devices.
The GhostC2f module is used to replace the C2f module of the YOLOv8 network, and combined the ECA attention mechanism layer and the H-Swish activation function to build a lightweight object detection model, and the model is converted through ONNX format and TRKNN Toolkit and deployed to embedded devices.
On the premise of ensuring detection accuracy, the number of model parameters and calculations is significantly reduced, making the model suitable for embedded device deployment, and improving deployment efficiency and training efficiency.
Smart Images

Figure CN120388168A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical fields of computer vision and artificial intelligence, and particularly to a lightweight object detection method, device, equipment and medium for embedded devices. Background Art
[0002] With the rapid progress and popularization of computer vision technology, object detection has become a core task in many application fields, covering autonomous driving, intelligent monitoring, UAV navigation, and face recognition, etc.
[0003] However, the computing power and storage capacity of embedded devices are often relatively limited. Traditional deep learning models require a large amount of computing resources and memory space to support the inference process, and a large amount of computing resources and memory space far exceed the carrying capacity of embedded devices. Therefore, for embedded devices, how to construct a lightweight object detection model and how to deploy a lightweight object detection model are both problems that need to be solved urgently. Summary of the Invention
[0004] The present invention provides a lightweight object detection method, device, computer equipment and storage medium for embedded devices to solve the technical problems of how to construct a lightweight object detection model and how to deploy a lightweight object detection model.
[0005] In a first aspect, a lightweight object detection method for an embedded device is provided, including: Obtain the backbone network in the YOLOv8 network, and replace the C2f module in the backbone network with a GhostC2f module; Select the backbone network using the GhostC2f module as the improved backbone network, and determine a lightweight object detection model based on the improved backbone network, an ECA attention mechanism layer, an activation function layer, and a classifier; Process a sample image through the improved backbone network to obtain a first image feature vector, process the first image feature vector through the ECA attention mechanism layer to obtain a second image feature vector, process the second image feature vector using the H-Swish activation function in the activation function layer to obtain a third image feature vector, and process the third image feature vector through the classifier to obtain the predicted category corresponding to the sample image; Obtain the loss value between the predicted category corresponding to the sample image and the true category corresponding to the sample image through a loss function; Train the lightweight object detection model through a predefined training method to obtain a trained lightweight object detection model; Based on a preset deployment method, determine the deployment file corresponding to the trained lightweight object detection model, and send the deployment file to the embedded device so that the embedded device loads the trained lightweight object detection model according to the deployment file.
[0006] Furthermore, selecting the backbone network using the GhostC2f module as the improved backbone network, and determining the lightweight object detection model based on the improved backbone network, the ECA attention mechanism layer, the activation function layer, and the classifier, includes: Select the backbone network using the GhostC2f module as the improved backbone network; Obtain a connection instruction, execute the connection instruction, connect the improved backbone network, the ECA attention mechanism layer, the activation function layer, and the classifier to obtain a lightweight object detection model.
[0007] Furthermore, processing the sample image through the improved backbone network to obtain a first image feature vector, processing the first image feature vector through the ECA attention mechanism layer to obtain a second image feature vector, using the H-Swish activation function in the activation function layer to process the second image feature vector to obtain a third image feature vector, and processing the third image feature vector through the classifier to obtain the predicted category corresponding to the sample image, includes: Input the sample image into the improved backbone network in the lightweight object detection model, process the sample image through the improved backbone network to obtain a first image feature vector, input the first image feature vector into the ECA attention mechanism layer, and process the first image feature vector through the ECA attention mechanism layer to obtain a second image feature vector; Input the second image feature vector into the activation function layer, obtain a configuration instruction from the configuration file, according to the configuration instruction, configure the activation function in the activation function layer as the H-Swish activation function, use the H-Swish activation function to process the second image feature vector to obtain a third image feature vector, input the third image feature vector into the classifier, and process the third image feature vector through the classifier to obtain the predicted category corresponding to the sample image.
[0008] Furthermore, obtaining the loss value between the predicted category corresponding to the sample image and the true category corresponding to the sample image through the loss function, includes: Read the loss function in the preset file; Through the loss function, obtain the loss value between the predicted category corresponding to the sample image and the true category corresponding to the sample image.
[0009] Furthermore, training the lightweight object detection model through a predefined training method to obtain the trained lightweight object detection model, includes: Update the original parameters of the lightweight object detection model by minimizing the loss function to obtain updated parameters; Select the lightweight object detection model using the updated parameters as the trained lightweight object detection model.
[0010] Furthermore, based on a preset deployment method, determine the deployment file corresponding to the trained lightweight object detection model, and send the deployment file to the embedded device so that the embedded device loads the trained lightweight object detection model according to the deployment file, including: Export the trained lightweight object detection model in ONNX format and input the trained lightweight object detection model into the model conversion tool; Convert the trained lightweight object detection model through the model conversion tool to obtain the deployment file corresponding to the trained lightweight object detection model, and send the deployment file to the embedded device so that the embedded device loads the trained lightweight object detection model according to the deployment file.
[0011] Furthermore, after determining the deployment file corresponding to the trained lightweight object detection model based on a preset deployment method, sending the deployment file to the embedded device so that the embedded device loads the trained lightweight object detection model according to the deployment file, the lightweight object detection method includes: Create a storage area, store the deployment file in the storage area, and create an access interface for the storage area.
[0012] In a second aspect, a lightweight object detection device for an embedded device is provided, including: A first acquisition module, configured to acquire the backbone network in the YOLOv8 network and replace the C2f module in the backbone network with a GhostC2f module; A determination module, configured to select the backbone network using the GhostC2f module as the improved backbone network, and determine a lightweight object detection model based on the improved backbone network, an ECA attention mechanism layer, an activation function layer, and a classifier; A processing module, configured to process a sample image through the improved backbone network to obtain a first image feature vector, process the first image feature vector through the ECA attention mechanism layer to obtain a second image feature vector, process the second image feature vector using the H-Swish activation function in the activation function layer to obtain a third image feature vector, and process the third image feature vector through the classifier to obtain the predicted category corresponding to the sample image; A second acquisition module, configured to obtain the loss value between the predicted category corresponding to the sample image and the true category corresponding to the sample image through a loss function; A training module, configured to train a lightweight object detection model through a predefined training method to obtain a trained lightweight object detection model; A deployment module, configured to determine a deployment file corresponding to the trained lightweight object detection model based on a preset deployment method, and send the deployment file to an embedded device, so that the embedded device loads the trained lightweight object detection model according to the deployment file.
[0013] In a third aspect, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the above-mentioned lightweight object detection method are implemented.
[0014] In a fourth aspect, a computer-readable storage medium is provided. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above-mentioned lightweight object detection method are implemented.
[0015] The present application provides a lightweight object detection method, device, computer device, and storage medium for an embedded device. The backbone network in YOLOv8 is obtained, and the C2f module in the backbone network is replaced with a GhostC2f module. The backbone network using the GhostC2f module is selected as the improved backbone network. Based on the improved backbone network, an ECA attention mechanism layer, an activation function layer, and a classifier, a lightweight object detection model is determined. The sample image is processed by the improved backbone network to obtain a first image feature vector. The first image feature vector is processed by the ECA attention mechanism layer to obtain a second image feature vector. The second image feature vector is processed by the H-Swish activation function in the activation function layer to obtain a third image feature vector. The third image feature vector is processed by the classifier to obtain the predicted category corresponding to the sample image. The loss value between the predicted category corresponding to the sample image and the true category corresponding to the sample image is obtained through a loss function. The lightweight object detection model is trained through a predefined training method to obtain a trained lightweight object detection model. Based on a preset deployment method, the deployment file corresponding to the trained lightweight object detection model is determined, and the deployment file is sent to the embedded device so that the embedded device loads the trained lightweight object detection model according to the deployment file. The beneficial effects are in three aspects. Firstly, the backbone network using the GhostC2f module is selected as the improved backbone network. Based on the improved backbone network, an ECA attention mechanism layer, an activation function layer, and a classifier, a lightweight object detection model is determined, solving the problem of how to construct a lightweight object detection model. Since the improved backbone network has a GhostC2f module, and the GhostC2f module uses GhostConv to replace the standard convolution in C2f, the improved backbone network can not only ensure the detection accuracy of the lightweight object detection model but also significantly reduce the number of parameters and the amount of computation of the lightweight object detection model, making the lightweight object detection model suitable for deployment on embedded devices with limited computing resources. Secondly, based on a preset deployment method, the deployment file corresponding to the trained lightweight object detection model is determined, and the deployment file is sent to the embedded device so that the embedded device loads the trained lightweight object detection model according to the deployment file, solving the problem of how to deploy the lightweight object detection model and being beneficial to improving the deployment efficiency of the trained lightweight object detection model. Thirdly, the H-Swish activation function replaces the Sigmoid function in the Swish function with a piecewise linear function, thereby reducing the amount of computation while maintaining the non-linear smooth characteristics of the Swish function. This design enables the H-Swish activation function to converge more quickly while maintaining the model performance, improving the training efficiency of the lightweight object detection model. Description of the Drawings
[0016] To more clearly illustrate the technical solutions of the embodiments of the present invention, the following will briefly introduce the drawings required for the description of the embodiments of the present invention. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0017] Figure 1 It is a schematic diagram of an application environment of a lightweight object detection method in an embodiment of the present invention; Figure 2 It is a schematic flowchart of a lightweight object detection method provided by an embodiment of the present invention; Figure 3 is Figure 2 A schematic flowchart of a specific implementation manner of step S23 in Figure 4 is Figure 2 A schematic flowchart of a specific implementation manner of step S25 in Figure 5 is Figure 2 A schematic flowchart of a specific implementation manner of step S26 in Figure 6 It is a schematic structural diagram of a lightweight object detection device in an embodiment of the present invention; Figure 7 It is a schematic structural diagram of a computer device in an embodiment of the present invention. Specific Embodiments
[0018] The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the drawings in the embodiments of the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the scope of protection of the present invention.
[0019] Please refer to Figure 1 , Figure 1 It is a schematic diagram of an application environment of a lightweight object detection method in an embodiment of the present invention. The lightweight object detection method provided by the embodiment of the present invention can be applied in an application environment such as Figure 1 , where the embedded device communicates with the server device through the network.
[0020] The server device obtains the backbone network in the YOLOv8 network and replaces the C2f module in the backbone network with a GhostC2f module; The server device selects the backbone network using the GhostC2f module as the improved backbone network, and determines a lightweight object detection model based on the improved backbone network, the ECA attention mechanism layer, the activation function layer, and the classifier; The server device processes the sample image through the improved backbone network to obtain a first image feature vector, processes the first image feature vector through the ECA attention mechanism layer to obtain a second image feature vector, uses the H-Swish activation function in the activation function layer to process the second image feature vector to obtain a third image feature vector, and processes the third image feature vector through the classifier to obtain the predicted category corresponding to the sample image; The server device obtains the loss value between the predicted category corresponding to the sample image and the true category corresponding to the sample image through the loss function; The server device trains the lightweight object detection model through a predefined training method to obtain a trained lightweight object detection model; The server device determines the deployment file corresponding to the trained lightweight object detection model based on a preset deployment method, and sends the deployment file to the embedded device so that the embedded device can load the trained lightweight object detection model according to the deployment file.
[0021] In the solution implemented by the above lightweight object detection method, device, equipment and medium, the beneficial effects are in three aspects. On the one hand, the backbone network using the GhostC2f module is selected as the improved backbone network. Based on the improved backbone network, ECA attention mechanism layer, activation function layer, and classifier, a lightweight object detection model is determined, solving the problem of how to construct a lightweight object detection model. Since the improved backbone network has the GhostC2f module, and the GhostC2f module replaces the standard convolution in C2f with GhostConv, the improved backbone network can not only ensure the detection accuracy of the lightweight object detection model, but also greatly reduce the number of parameters and computational amount of the lightweight object detection model, making the lightweight object detection model suitable for deployment on embedded devices with limited computing resources. On the second hand, based on the preset deployment method, the deployment file corresponding to the trained lightweight object detection model is determined, and the deployment file is sent to the embedded device so that the embedded device can load the trained lightweight object detection model according to the deployment file, solving the problem of how to deploy the lightweight object detection model, which is beneficial to improving the deployment efficiency of the trained lightweight object detection model. On the third hand, the H-Swish activation function replaces the Sigmoid function in the Swish function with a piecewise linear function, thereby reducing the computational amount while maintaining the non-linear smooth characteristics of the Swish function. This design enables the H-Swish activation function to converge more quickly while maintaining the model performance, improving the training efficiency of the lightweight object detection model.
[0022] Among them, the server device can be implemented by an independent server or a server cluster composed of multiple servers. The present invention will be described in detail through specific embodiments below.
[0023] Please refer to Figure 2 , Figure 2 which is a flowchart of a lightweight object detection method provided by an embodiment of the present invention, including the following steps: S21, obtain the backbone network in the YOLOv8 network, and replace the C2f module in the backbone network with a GhostC2f module; Among them, YOLOv8 is an object detection network. As the latest iteration of the YOLO series, YOLOv8 inherits the consistent efficiency and real-time performance of the YOLO series, and significantly improves the accuracy and speed of object detection by introducing more advanced network architectures and optimization strategies, such as enhanced feature extraction capabilities and more accurate anchor-free detection mechanisms.
[0024] Among them, the C2f module is a feature fusion module in the field of deep learning. The C2f module processes the input feature map using two convolutional layers to achieve effective feature fusion and extraction. This design not only maintains the lightweight of the model but also improves the feature expression ability and detection accuracy.
[0025] Among them, the GhostC2f module is a feature fusion module improved based on the Ghost module. The GhostC2f module combines the idea of the CSPNet architecture. The Chinese full name of CSPNet is Cross Stage Partial Networks, and the English full name of CSPNet is: Cross Stage Partial Networks.
[0026] Among them, the Ghost module greatly improves the computational efficiency through feature redundancy decoupling and cheap feature generation.
[0027] S22, select the backbone network using the GhostC2f module as the improved backbone network, and determine the lightweight object detection model based on the improved backbone network, ECA attention mechanism layer, activation function layer, and classifier; Among them, the Ghost module adopts a dual-path processing mechanism. The dual-path processing mechanism consists of a main path and an auxiliary path. The main path extracts a small amount of core features through conventional convolution, and the auxiliary path applies a lightweight linear transformation to the output of the main path to generate supplementary features. Finally, feature reconstruction is completed through channel concatenation. This design greatly reduces the computational amount and the number of parameters required by the traditional convolutional layer, while maintaining the feature expression ability of the improved backbone network. By introducing the Ghost module, the improved backbone network can achieve faster inference and lower resource consumption without sacrificing accuracy, and is especially suitable for scenarios with strict requirements for computational efficiency and storage space.
[0028] Among them, the step of selecting the backbone network using the GhostC2f module as the improved backbone network and determining the lightweight object detection model based on the improved backbone network, ECA attention mechanism layer, activation function layer, and classifier includes: Select the backbone network using the GhostC2f module as the improved backbone network; Obtain a connection instruction, execute the connection instruction, and connect the improved backbone network, ECA attention mechanism layer, activation function layer, and classifier to obtain the lightweight object detection model.
[0029] Among them, the lightweight object detection model is a lightweight object detection model.
[0030] Among them, the ECA (Efficient Channel Attention) attention mechanism layer is a lightweight channel attention module. The goal of the ECA attention mechanism layer is to improve the expressive ability and perception ability of the convolutional neural network while reducing computational complexity.
[0031] Among them, the ECA attention mechanism layer is achieved by performing adaptive local interaction in the channel dimension. Specifically, the ECA attention mechanism layer models the interdependence between channels by introducing a one-dimensional convolutional operation. This convolutional operation can be regarded as an adaptive sliding window average. The ECA attention mechanism layer averages the responses of adjacent channels at each position and then uses the result to adjust the weights of each channel.
[0032] Among them, the addition of the ECA attention mechanism layer only adds a small number of parameters but can obtain obvious performance gains. It can effectively avoid dimensionality reduction, capture information of cross-channel interaction, aims to ensure information efficiency and effectiveness, can improve the performance of the backbone network, and has good generalization ability in object detection and instance segmentation tasks. It realizes further enhancing the feature expression ability of the backbone network under the condition of lower computational complexity.
[0033] S23, process the sample image through the improved backbone network to obtain the first image feature vector, process the first image feature vector through the ECA attention mechanism layer to obtain the second image feature vector, process the second image feature vector with the H-Swish activation function in the activation function layer to obtain the third image feature vector, and process the third image feature vector through the classifier to obtain the predicted category corresponding to the sample image; Among them, the sample image is any image in the sample set. By providing rich and diverse sample images, the model can learn the target features under different scenarios, different lighting conditions, and different angles, thereby enhancing its adaptability to complex environments. These sample images help the lightweight object detection model establish a comprehensive understanding of the target, improve the recognition accuracy and generalization ability of the lightweight object detection model, enable the lightweight object detection model to detect the target more accurately in practical applications, and provide a reliable basis for subsequent analysis and decision-making.
[0034] S24, obtain the loss value between the predicted category corresponding to the sample image and the true category corresponding to the sample image through the loss function; Among them, the obtaining of the loss value between the predicted category corresponding to the sample image and the true category corresponding to the sample image through the loss function includes: Read the loss function in the preset file; Obtain the loss value between the predicted category corresponding to the sample image and the true category corresponding to the sample image through the loss function.
[0035] Among them, the loss function includes but is not limited to the cross-entropy loss function and the mean square error loss function.
[0036] Among them, the loss value is used to measure the degree of difference between the predicted category corresponding to the sample image and the true category corresponding to the sample image; the larger the loss value between the predicted category corresponding to the sample image and the true category corresponding to the sample image, the greater the degree of difference measured by the loss value between the predicted category corresponding to the sample image and the true category corresponding to the sample image; the smaller the loss value between the predicted category corresponding to the sample image and the true category corresponding to the sample image, the smaller the degree of difference measured by the loss value between the predicted category corresponding to the sample image and the true category corresponding to the sample image.
[0037] S25. Train the lightweight object detection model through a predefined training method to obtain the trained lightweight object detection model. Among them, training the detection model can significantly improve the performance and accuracy of the model. Through training, the model can learn the feature patterns in the sample images, so as to make more accurate predictions and identifications for unknown data. This not only improves the generalization ability of the lightweight object detection model, enabling the lightweight object detection model to better adapt to various complex scenarios, but also enhances the robustness of the lightweight object detection model.
[0038] S26. Based on a preset deployment method, determine the deployment file corresponding to the trained lightweight object detection model, and send the deployment file to the embedded device, so that the embedded device loads the trained lightweight object detection model according to the deployment file.
[0039] Among them, after determining the deployment file corresponding to the trained lightweight object detection model based on the preset deployment method, sending the deployment file to the embedded device, so that the embedded device loads the trained lightweight object detection model according to the deployment file, the lightweight object detection method includes: Step A. The embedded device loads the trained lightweight object detection model, and the trained lightweight object detection model includes a trained backbone network, a trained ECA attention mechanism layer, a trained activation function layer, and a trained classifier. The embedded device acquires the current image, inputs the current image into the trained backbone network, processes the current image through the improved backbone network to obtain the fourth image feature vector, inputs the fourth image feature vector into the trained ECA attention mechanism layer, processes the fourth image feature vector through the trained ECA attention mechanism layer to obtain the fifth image feature vector, inputs the fifth image feature vector into the trained activation function layer, processes the fifth image feature vector using the H-Swish activation function in the trained activation function layer to obtain the sixth image feature vector, and inputs the sixth image feature vector into the trained classifier. The trained classifier processes the sixth image feature vector to obtain the object detection result of the current image.
[0040] Among them, the current image is an image that does not belong to the sample set. The embedded device uses the trained lightweight object detection model to detect the current image, which can significantly accelerate the detection speed, reduce the processing time, and also ensure the stability of the embedded device when processing a large number of images or real-time video streams.
[0041] Among them, the H-Swish activation function is a variant based on the Swish activation function, aiming to simplify the calculation and improve the training efficiency of the model. The H-Swish activation function reduces the computational complexity by replacing the Sigmoid function in the Swish function with a piecewise linear function, while maintaining the non-linear smoothness characteristic of the Swish function. This design enables the H-Swish activation function to converge more quickly while maintaining the model performance, improving the training efficiency of the lightweight object detection model.
[0042] Among them, the embedded device includes but is not limited to drones, smartphones, and household appliances.
[0043] Among them, the drone integrates an embedded system inside, including a processor, sensors, communication modules, etc. These embedded components work together to enable the drone to achieve functions such as autonomous flight, precise positioning, and real-time data transmission.
[0044] Among them, the lightweight object detection model can significantly reduce the computational burden and energy consumption of the drone, enabling the drone to operate efficiently even under resource-constrained conditions. This means that the drone can carry a lighter battery, extend the flight time, and improve the task execution efficiency. In addition, the lightweight object detection model can improve the real-time performance of the drone, enabling the drone to process image data more quickly, achieve instant recognition and tracking of targets, and contribute to the intelligent level of the drone.
[0045] Among them, the smartphone is not only a tool for our daily communication but also integrates various sensors and applications, providing a rich user experience.
[0046] Among them, household appliances such as smart refrigerators, washing machines, and air conditioners are all equipped with embedded systems. Household appliances achieve automatic control and intelligent functions through built-in control systems and sensors.
[0047] Among them, after determining the deployment file corresponding to the trained lightweight object detection model based on the preset deployment method and sending the deployment file to the embedded device so that the embedded device loads the trained lightweight object detection model according to the deployment file, the lightweight object detection method includes: Step B: Create a storage area, store the deployment file in the storage area, and create an access interface for the storage area.
[0048] Among them, Step A can be executed before Step B, can also be executed after Step B, or Step A can be executed simultaneously with Step B. The specific execution order is not limited here.
[0049] In the embodiment of the present invention, the beneficial effects are in three aspects. On the one hand, the backbone network using the GhostC2f module is selected as the improved backbone network. Based on the improved backbone network, ECA attention mechanism layer, activation function layer, and classifier, a lightweight object detection model is determined, solving the problem of how to construct a lightweight object detection model. Since the improved backbone network has a GhostC2f module, and the GhostC2f module replaces the standard convolution in C2f with GhostConv, therefore, the improved backbone network can not only ensure the detection accuracy of the lightweight object detection model but also greatly reduce the number of parameters and computational amount of the lightweight object detection model, making the lightweight object detection model suitable for deployment on embedded devices with limited computing resources; on the second hand, based on the preset deployment method, the deployment file corresponding to the trained lightweight object detection model is determined and sent to the embedded device so that the embedded device loads the trained lightweight object detection model according to the deployment file, solving the problem of how to deploy the lightweight object detection model and being beneficial to improving the deployment efficiency of the trained lightweight object detection model; on the third hand, the H-Swish activation function replaces the Sigmoid function in the Swish function with a piecewise linear function, thereby reducing the computational amount while maintaining the non-linear smooth characteristics of the Swish function. This design enables the H-Swish activation function to converge more quickly while maintaining the model performance, improving the training efficiency of the lightweight object detection model.
[0050] Please refer to Figure 3 , Figure 3 is Figure 2 a schematic flowchart of a specific implementation manner of step S23 in S31. Input the sample image into the improved backbone network of the lightweight object detection model, process the sample image through the improved backbone network to obtain the first image feature vector, input the first image feature vector into the ECA attention mechanism layer, and process the first image feature vector through the ECA attention mechanism layer to obtain the second image feature vector; S32. Input the second image feature vector into the activation function layer, obtain the configuration instruction from the configuration file, configure the activation function in the activation function layer as the H-Swish activation function according to the configuration instruction, process the second image feature vector using the H-Swish activation function to obtain the third image feature vector, input the third image feature vector into the classifier, and process the third image feature vector through the classifier to obtain the predicted category corresponding to the sample image.
[0051] Among them, the configuration instruction is activation_type: H-Swish.
[0052] Among them, activation_type is a parameter used to specify the type of activation function.
[0053] In the embodiment of the present invention, by processing the third image feature vector through the classifier to obtain the predicted category corresponding to the sample image, the accuracy rate and generalization ability of the lightweight object detection model can be evaluated according to the predicted category.
[0054] Please refer to Figure 4 , Figure 4 which Figure 2 is a schematic flowchart of a specific implementation manner of step S25 in S41. Update the original parameters of the lightweight object detection model by minimizing the loss function to obtain the updated parameters; S42. Select the lightweight object detection model using the updated parameters as the trained lightweight object detection model.
[0055] In the embodiment of the present invention, selecting the lightweight object detection model using the updated parameters as the trained lightweight object detection model, when the trained lightweight object detection model is in the inference stage, it can utilize the updated parameters to make predictions quickly, effectively improving the generalization ability and practicality of the trained lightweight object detection model.
[0056] Please refer to Figure 5 , Figure 5 which Figure 2 is a schematic flowchart of a specific implementation manner of step S26 in S51. Export the trained lightweight object detection model in ONNX format and input the trained lightweight object detection model into the model conversion tool; Among them, ONNX (Open Neural Network Exchange) is a general open neural network exchange format. The ONNX format defines a set of standard formats that are independent of the environment and platform, aiming to enhance the interoperability of models.
[0057] Among them, adopting the ONNX format to export the trained lightweight object detection model facilitates the next step of transplantation.
[0058] S52. Through a model conversion tool, convert the trained lightweight object detection model to obtain a deployment file corresponding to the trained lightweight object detection model, and send the deployment file to the embedded device, so that the embedded device can load the trained lightweight object detection model according to the deployment file.
[0059] Among them, the format of the deployment file is the RKNN format. The model conversion tool can adopt the TRKNN Toolkit.
[0060] Among them, the TRKNN Toolkit is a model conversion tool provided by Rockchip. The TRKNN Toolkit converts the models trained by mainstream deep learning frameworks into the RKNN format.
[0061] Among them, the RKNN format is a neural network model format launched by Rockchip. The RKNN format is specifically designed for efficient inference on Rockchip's AI accelerators.
[0062] In the embodiments of the present invention, through a model conversion tool, convert the trained lightweight object detection model to obtain a deployment file corresponding to the trained lightweight object detection model, and send the deployment file to the embedded device, so that the embedded device can load the trained lightweight object detection model according to the deployment file, which is beneficial to improving the deployment efficiency of the trained lightweight object detection model.
[0063] Please refer to Figure 6 , Figure 6 which is a schematic structural diagram of the lightweight object detection device in an embodiment of the present invention. As Figure 6 shown, the lightweight object detection device includes a first acquisition module 101, a determination module 102, a processing module 103, a second acquisition module 104, a training module 105, and a deployment module 106. The detailed descriptions of each functional module are as follows: The first acquisition module 101 is used to acquire the backbone network in the YOLOv8 network and replace the C2f module in the backbone network with the GhostC2f module; The determination module 102 is used to select the backbone network using the GhostC2f module as the improved backbone network, and determine a lightweight object detection model based on the improved backbone network, the ECA attention mechanism layer, the activation function layer, and the classifier; The processing module 103 is used to process the sample image through the improved backbone network to obtain a first image feature vector, process the first image feature vector through the ECA attention mechanism layer to obtain a second image feature vector, use the H-Swish activation function in the activation function layer to process the second image feature vector to obtain a third image feature vector, and process the third image feature vector through the classifier to obtain the predicted category corresponding to the sample image; The second acquisition module 104 is used to obtain the loss value between the predicted category corresponding to the sample image and the true category corresponding to the sample image through the loss function; The training module 105 is used to train the lightweight object detection model through a predefined training method to obtain a trained lightweight object detection model; The deployment module 106 is used to determine the deployment file corresponding to the trained lightweight object detection model based on a preset deployment method, and send the deployment file to the embedded device so that the embedded device can load the trained lightweight object detection model according to the deployment file.
[0064] In one embodiment, the determination module 102 includes: The selection subunit is used to select the backbone network using the GhostC2f module as the improved backbone network; The determination subunit is used to obtain a connection instruction, execute the connection instruction, and connect the improved backbone network, the ECA attention mechanism layer, the activation function layer, and the classifier to obtain a lightweight object detection model.
[0065] In one embodiment, the processing module 103 includes: The first processing subunit is used to input the sample image into the improved backbone network in the lightweight object detection model, process the sample image through the improved backbone network to obtain a first image feature vector, input the first image feature vector into the ECA attention mechanism layer, and process the first image feature vector through the ECA attention mechanism layer to obtain a second image feature vector; A second processing subunit, configured to input the second image feature vector into an activation function layer, obtain a configuration instruction from a configuration file, and according to the configuration instruction, configure the activation function in the activation function layer as an H-Swish activation function, process the second image feature vector by using the H-Swish activation function to obtain a third image feature vector, input the third image feature vector into a classifier, and process the third image feature vector by the classifier to obtain a predicted category corresponding to the sample image.
[0066] In one embodiment, the second obtaining module 104 includes: A reading subunit, configured to read a loss function from a preset file; An obtaining subunit, configured to obtain a loss value between a predicted category corresponding to the sample image and a true category corresponding to the sample image by using the loss function.
[0067] In one embodiment, the training module 105 includes: An updating subunit, configured to update original parameters of the lightweight object detection model by minimizing the loss function to obtain updated parameters; A training subunit, configured to select the lightweight object detection model using the updated parameters as the trained lightweight object detection model.
[0068] In one embodiment, the deployment module 106 includes: An exporting subunit, configured to export the trained lightweight object detection model in ONNX format, and input the trained lightweight object detection model into a model conversion tool; A deploying subunit, configured to convert the trained lightweight object detection model by using the model conversion tool to obtain a deployment file corresponding to the trained lightweight object detection model, and send the deployment file to an embedded device, so that the embedded device loads the trained lightweight object detection model according to the deployment file.
[0069] In one embodiment, the lightweight object detection device further includes: A storage module, configured to create a storage area, store the deployment file in the storage area, and create an access interface for the storage area.
[0070] In the embodiments of the present invention, the beneficial effects are reflected in three aspects. On the one hand, the backbone network using the GhostC2f module is selected as the improved backbone network. Based on the improved backbone network, the ECA attention mechanism layer, the activation function layer, and the classifier, a lightweight object detection model is determined, solving the problem of how to construct a lightweight object detection model. Since the improved backbone network has the GhostC2f module, and the GhostC2f module replaces the standard convolution in C2f with GhostConv, the improved backbone network can not only ensure the detection accuracy of the lightweight object detection model, but also significantly reduce the number of parameters and the computational amount of the lightweight object detection model, making the lightweight object detection model suitable for deployment on embedded devices with limited computing resources. On the second hand, based on the preset deployment method, the deployment file corresponding to the trained lightweight object detection model is determined, and the deployment file is sent to the embedded device so that the embedded device can load the trained lightweight object detection model according to the deployment file, solving the problem of how to deploy the lightweight object detection model and facilitating the improvement of the deployment efficiency of the trained lightweight object detection model. On the third hand, the H-Swish activation function replaces the Sigmoid function in the Swish function with a piecewise linear function, thereby reducing the computational amount while maintaining the non-linear smooth characteristics of the Swish function. This design enables the H-Swish activation function to converge more quickly while maintaining the model performance, improving the training efficiency of the lightweight object detection model.
[0071] For the specific limitations of the lightweight object detection device, reference can be made to the limitations of the lightweight object detection method in the above text, which will not be elaborated here.
[0072] Each module in the above lightweight object detection device can be implemented in whole or in part by software, hardware, and their combination. The above modules can be embedded in the processor of the computer device in hardware form or be independent of it, or can be stored in the memory of the computer device in software form to facilitate the processor to call and execute the operations corresponding to the above respective modules.
[0073] Please refer to Figure 7 , Figure 7 is a schematic structural diagram of a computer device in an embodiment of the present invention. In one embodiment, a computer device is provided. This computer device is a server device, and its internal structural diagram can be as Figure 7As shown in the figure. The computer device includes a processor, a memory, a network interface, a display screen, and an input device connected via a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The network interface of the computer device is used to communicate with external devices.
[0074] When the computer program is executed by the processor, the following steps can be implemented: Obtain the backbone network in the YOLOv8 network, and replace the C2f module in the backbone network with the GhostC2f module; Select the backbone network using the GhostC2f module as the improved backbone network, and determine a lightweight object detection model based on the improved backbone network, the ECA attention mechanism layer, the activation function layer, and the classifier; Process the sample image through the improved backbone network to obtain a first image feature vector, process the first image feature vector through the ECA attention mechanism layer to obtain a second image feature vector, process the second image feature vector using the H-Swish activation function in the activation function layer to obtain a third image feature vector, and process the third image feature vector through the classifier to obtain the predicted category corresponding to the sample image; Obtain the loss value between the predicted category corresponding to the sample image and the true category corresponding to the sample image through the loss function; Train the lightweight object detection model through a predefined training method to obtain a trained lightweight object detection model; Based on a preset deployment method, determine the deployment file corresponding to the trained lightweight object detection model, and send the deployment file to the embedded device so that the embedded device can load the trained lightweight object detection model according to the deployment file.
[0075] In some embodiments, the processor is used to implement: Select the backbone network using the GhostC2f module as the improved backbone network; Obtain a connection instruction, execute the connection instruction, and connect the improved backbone network, the ECA attention mechanism layer, the activation function layer, and the classifier to obtain a lightweight object detection model.
[0076] In some embodiments, the processor is used to implement: Input the sample image into the improved backbone network of the lightweight object detection model, process the sample image through the improved backbone network to obtain the first image feature vector, input the first image feature vector into the ECA attention mechanism layer, and process the first image feature vector through the ECA attention mechanism layer to obtain the second image feature vector; Input the second image feature vector into the activation function layer, obtain the configuration instruction from the configuration file, configure the activation function in the activation function layer as the H-Swish activation function according to the configuration instruction, process the second image feature vector using the H-Swish activation function to obtain the third image feature vector, and input the third image feature vector into the classifier to process the third image feature vector to obtain the predicted category corresponding to the sample image.
[0077] In some embodiments, the processor is used to implement: Read the loss function in the preset file; Through the loss function, obtain the loss value between the predicted category corresponding to the sample image and the true category corresponding to the sample image.
[0078] In some embodiments, the processor is used to implement: Update the original parameters of the lightweight object detection model by minimizing the loss function to obtain the updated parameters; Select the lightweight object detection model using the updated parameters as the trained lightweight object detection model.
[0079] In some embodiments, the processor is used to implement: Export the trained lightweight object detection model in ONNX format, and input the trained lightweight object detection model into the model conversion tool; Through the model conversion tool, convert the trained lightweight object detection model to obtain the deployment file corresponding to the trained lightweight object detection model, and send the deployment file to the embedded device so that the embedded device can load the trained lightweight object detection model according to the deployment file.
[0080] In some embodiments, the processor is used to implement: Create a storage area, store the deployment file in the storage area, and create an access interface for the storage area.
[0081] The embodiment of the present application provides a computer-readable storage medium, and the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the above-mentioned various method embodiments can be implemented.
[0082] Obtain the backbone network in the YOLOv8 network, and replace the C2f module in the backbone network with the GhostC2f module; Select the backbone network using the GhostC2f module as the improved backbone network, and determine the lightweight object detection model based on the improved backbone network, ECA attention mechanism layer, activation function layer, and classifier; Process the sample image through the improved backbone network to obtain the first image feature vector, process the first image feature vector through the ECA attention mechanism layer to obtain the second image feature vector, use the H-Swish activation function in the activation function layer to process the second image feature vector to obtain the third image feature vector, and process the third image feature vector through the classifier to obtain the predicted category corresponding to the sample image; Obtain the loss value between the predicted category corresponding to the sample image and the true category corresponding to the sample image through the loss function; Train the lightweight object detection model through a predefined training method to obtain the trained lightweight object detection model; Based on a preset deployment method, determine the deployment file corresponding to the trained lightweight object detection model, and send the deployment file to the embedded device so that the embedded device can load the trained lightweight object detection model according to the deployment file.
[0083] It should be noted that the functions or steps that the above computer-readable storage medium or computer device can achieve can be referred to the relevant descriptions of the foregoing method embodiments. To avoid repetition, they will not be described one by one here.
[0084] The above processor can be a general-purpose processor, including a central processing unit (CPU), a graphics processing unit (GPU), and a network processor (NP); it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, and discrete hardware components.
[0085] The above description and the accompanying drawings fully illustrate the embodiments of the present disclosure, enabling those skilled in the art to practice them. Herein, each embodiment may focus on the differences from other embodiments, and the same or similar parts among the embodiments may be referred to each other. For the methods disclosed in the embodiments, if they correspond to the method parts disclosed in the embodiments, the relevant parts may refer to the description of the method parts.
[0086] Those skilled in the art can realize that the units and algorithm steps of the examples described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are executed in a hardware or software manner may depend on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods for each specific application to implement the described functions, but such implementation should not be considered to exceed the scope of the embodiments of the present disclosure. Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the systems, devices, and units described above can refer to the corresponding processes in the foregoing method embodiments, and will not be elaborated herein.
[0087] In the embodiments disclosed herein, the device embodiments described above are merely illustrative. For example, the division of units can be merely a logical function division, and there can be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some sub-samples can be ignored or not executed. Additionally, the displayed or discussed couplings or direct couplings or communication connections to each other can be through some interfaces, and the indirect couplings or communication connections of devices or units can be in electrical, mechanical, or other forms. The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they can be located in one place, or distributed to multiple network units. Some or all of the units can be selected according to actual needs to implement this embodiment. Additionally, in the embodiments of the present disclosure, the various functional units can be integrated in one processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit.
[0088] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer programs according to embodiments of the present disclosure. In this regard, each block in the flowchart or block diagram may represent a module, a segment of a program, or a portion of code that contains one or more executable instructions for implementing a specified logical function. In some alternative implementations, the functions noted in the blocks may occur in a different order than noted in the accompanying drawings. For example, two consecutive blocks may in fact be executed substantially in parallel, or they may sometimes be executed in the reverse order, depending on the functions involved. In the descriptions corresponding to the flowcharts and block diagrams in the accompanying drawings, the operations or steps corresponding to different blocks may also occur in a different order than disclosed in the description, and sometimes there is no specific order between different operations or steps. For example, two consecutive operations or steps may in fact be executed substantially in parallel, or they may sometimes be executed in the reverse order, depending on the functions involved. Each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented by a dedicated hardware-based system that performs the specified functions or actions, or can be implemented by a combination of dedicated hardware and computer instructions.
Claims
1. A lightweight object detection method for an embedded device, characterized in that, Including: Obtain the backbone network in the YOLOv8 network, and replace the C2f module in the backbone network with the GhostC2f module; Select the backbone network using the GhostC2f module as the improved backbone network, and determine the lightweight object detection model based on the improved backbone network, ECA attention mechanism layer, activation function layer, and classifier; Process the sample image through the improved backbone network to obtain the first image feature vector, process the first image feature vector through the ECA attention mechanism layer to obtain the second image feature vector, use the H-Swish activation function in the activation function layer to process the second image feature vector to obtain the third image feature vector, and process the third image feature vector through the classifier to obtain the predicted category corresponding to the sample image; Obtain the loss value between the predicted category corresponding to the sample image and the true category corresponding to the sample image through the loss function; Train the lightweight object detection model through a predefined training method to obtain the trained lightweight object detection model; Based on a preset deployment method, determine the deployment file corresponding to the trained lightweight object detection model, and send the deployment file to the embedded device so that the embedded device can load the trained lightweight object detection model according to the deployment file.
2. The lightweight object detection method according to claim 1, wherein The step of selecting the backbone network using the GhostC2f module as the improved backbone network and determining the lightweight object detection model based on the improved backbone network, ECA attention mechanism layer, activation function layer, and classifier includes: Select the backbone network using the GhostC2f module as the improved backbone network; Obtain the connection instruction, execute the connection instruction, and connect the improved backbone network, ECA attention mechanism layer, activation function layer, and classifier to obtain the lightweight object detection model.
3. The lightweight object detection method according to claim 1, wherein The step of processing the sample image through the improved backbone network to obtain the first image feature vector, processing the first image feature vector through the ECA attention mechanism layer to obtain the second image feature vector, using the H-Swish activation function in the activation function layer to process the second image feature vector to obtain the third image feature vector, and processing the third image feature vector through the classifier to obtain the predicted category corresponding to the sample image includes: Input the sample image into the improved backbone network in the lightweight object detection model, process the sample image through the improved backbone network to obtain the first image feature vector, input the first image feature vector into the ECA attention mechanism layer, and process the first image feature vector through the ECA attention mechanism layer to obtain the second image feature vector; Input the second image feature vector into the activation function layer, obtain the configuration instruction from the configuration file, configure the activation function in the activation function layer as the H-Swish activation function according to the configuration instruction, use the H-Swish activation function to process the second image feature vector to obtain the third image feature vector, input the third image feature vector into the classifier, and process the third image feature vector through the classifier to obtain the predicted category corresponding to the sample image.
4. The lightweight object detection method according to claim 1, characterized in that, Obtaining the loss value between the predicted category corresponding to the sample image and the true category corresponding to the sample image through the loss function includes: Reading the loss function in the preset file; Obtaining the loss value between the predicted category corresponding to the sample image and the true category corresponding to the sample image through the loss function.
5. The lightweight object detection method according to claim 1, wherein Training the lightweight object detection model through a predefined training method to obtain the trained lightweight object detection model, including: Updating the original parameters of the lightweight object detection model by minimizing the loss function to obtain updated parameters; Selecting the lightweight object detection model using the updated parameters as the trained lightweight object detection model.
6. The lightweight object detection method according to claim 1, wherein Based on a preset deployment method, determining the deployment file corresponding to the trained lightweight object detection model and sending the deployment file to the embedded device so that the embedded device loads the trained lightweight object detection model according to the deployment file, including: Exporting the trained lightweight object detection model in ONNX format and inputting the trained lightweight object detection model into the model conversion tool; Converting the trained lightweight object detection model through the model conversion tool to obtain the deployment file corresponding to the trained lightweight object detection model, and sending the deployment file to the embedded device so that the embedded device loads the trained lightweight object detection model according to the deployment file.
7. The lightweight object detection method according to claim 1, characterized in that After determining the deployment file corresponding to the trained lightweight object detection model based on a preset deployment method and sending the deployment file to the embedded device so that the embedded device loads the trained lightweight object detection model according to the deployment file, the lightweight object detection method includes: Creating a storage area, storing the deployment file in the storage area, and creating an access interface for the storage area.
8. A lightweight object detection device for an embedded device, characterized in that, Including: A first acquisition module for acquiring the backbone network in the YOLOv8 network and replacing the C2f module in the backbone network with a GhostC2f module; A determination module for selecting the backbone network using the GhostC2f module as the improved backbone network and determining the lightweight object detection model based on the improved backbone network, the ECA attention mechanism layer, the activation function layer, and the classifier; A processing module for processing the sample image through the improved backbone network to obtain a first image feature vector, processing the first image feature vector through the ECA attention mechanism layer to obtain a second image feature vector, processing the second image feature vector using the H-Swish activation function in the activation function layer to obtain a third image feature vector, and processing the third image feature vector through the classifier to obtain the predicted category corresponding to the sample image; A second acquisition module for obtaining the loss value between the predicted category corresponding to the sample image and the true category corresponding to the sample image through the loss function; A training module for training the lightweight object detection model through a predefined training method to obtain the trained lightweight object detection model; A deployment module, configured to determine a deployment file corresponding to the trained lightweight object detection model based on a preset deployment method, and send the deployment file to an embedded device, so that the embedded device loads the trained lightweight object detection model according to the deployment file.
9. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, the steps of the lightweight object detection method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, the steps of the lightweight object detection method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Lightweight vehicle and pedestrian detection method based on improved YOLOv8n
CN117746385A
Anti-collision early warning method and system of crane, electronic equipment and storage medium
CN119339315A