Two-dimensional code detection model lightweight method, two-dimensional code detection method and two-dimensional code detection device

By pruning, fine-tuning and quantizing the QR code detection model, a lightweight target detection model is generated, which solves the problem that the model size is large in the prior art and is not suitable for end-side deployment, and efficient and accurate QR code detection is achieved.

CN120218096APending Publication Date: 2025-06-27GUANGZHOU LIZHI NETWORK TECH CO LTD (GUANGDONG)
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311805460.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-12-25
Publication Date
2025-06-27

AI Technical Summary

Technical Problem

The existing QR code detection method is based on deep learning, with a large model size and is not suitable for offline deployment on the end side.

Method used

By obtaining the first detection model trained based on the training sample after the enhancement processing, pruning it using a lightweight network, and fine-tuning the pruned model to generate a second detection model. The second detection model is converted into an inference model, and quantified it to generate an object detection model.

Benefits of technology

While compressing the detection model, it ensures the accuracy and speed of model detection, suitable for deployment on the end side, and ensures the accuracy of detection in the event of interference between the QR code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120218096A_ABST
    Figure CN120218096A_ABST
Patent Text Reader

Abstract

The invention relates to a two-dimensional code detection model lightweight method, a two-dimensional code detection method and a two-dimensional code detection device. The method comprises the steps of obtaining a first detection model; the first detection model is obtained by training an initial detection model based on the enhanced training sample, pruning the first detection model by using a lightweight network, finely tuning the pruned first detection model to generate a second detection model, converting the second detection model into a corresponding reasoning model, and performing reasoning on the second detection model to obtain a reasoning result; performing quantification operation on the reasoning model to generate a target detection model; the target detection model is used for detecting the two-dimensional code. According to the scheme provided by the invention, the accuracy of two-dimensional code detection can be ensured under the condition that the two-dimensional code has interference, the precision of model detection can be ensured and the speed of model detection can be improved while the detection model is compressed, and the method is more suitable for end-side deployment.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer vision technology, and particularly to a method for lightweighting a QR code detection model, a QR code detection method, and a device therefor. Background Art

[0002] A QR Code is a coding method, which is a graph composed of specific geometric figures distributed in a certain pattern on a plane (in two-dimensional directions), black and white, and recording data symbol information. With the increasingly wide use of QR Codes in scenarios such as scanning payment, marketing, and e-commerce platforms, QR code scanning and detection has become an important task in the field of computer vision, aiming to identify and decode QR Codes from images.

[0003] Currently, related QR code detection methods, such as deep learning-based methods, mainly use a model to detect QR Codes, but the model has a large volume and is not suitable for offline deployment on the edge side. Summary of the Invention

[0004] To solve or partially solve the problems existing in the related art, the present application provides a method for lightweighting a QR code detection model, a QR code detection method, and a device therefor, which can compress the detection model while ensuring the accuracy of model detection and improving the speed of model detection.

[0005] The first aspect of the present application provides a method for lightweighting a QR code detection model, including:

[0006] Obtaining a first detection model; the first detection model is obtained by training an initial detection model based on enhanced training samples;

[0007] Pruning the first detection model using a lightweight network;

[0008] Fine-tuning the pruned first detection model to generate a second detection model;

[0009] Converting the second detection model into a corresponding inference model, and performing a quantization operation on the inference model to generate a target detection model; the target detection model is used to detect QR Codes.

[0010] Optionally, the first detection model includes a detection algorithm module and a model head; the step of pruning the first detection model using a lightweight network includes:

[0011] Using the lightweight network as the backbone network of the detection algorithm module;

[0012] Using a pixel aggregation network as the model head of the first detection model.

[0013] Optionally, the step of fine-tuning the first detection model after pruning includes:

[0014] Reallocating channels of convolutional layers in the lightweight network;

[0015] Replacing a target convolutional module in the lightweight network with a squeeze-and-excitation network and a convolutional block attention module.

[0016] Optionally, the step of reallocating channels of convolutional layers in the lightweight network includes:

[0017] Obtaining a preset scaling factor of the channels and output results of the channels;

[0018] Jointly training the channels and the preset scaling factor;

[0019] Determining a target scaling factor based on training results;

[0020] Removing channels corresponding to the target scaling factor.

[0021] Optionally, the steps after fine-tuning the first detection model after pruning to generate a second detection model include:

[0022] Training the second detection model with the enhanced training samples.

[0023] Optionally, the step of converting the second detection model into a corresponding inference model includes:

[0024] Performing multiple format conversions on the second detection model through a preset model deployment framework to generate the inference model.

[0025] Optionally, the inference model has a first accuracy, and the step of quantizing the inference model includes:

[0026] Based on a preset command, converting the first accuracy of the inference model into a second accuracy; where the first accuracy is greater than the second accuracy.

[0027] A second aspect of the present application provides a QR code detection method, including:

[0028] Obtaining QR code data to be recognized;

[0029] Use a target detection model to detect the two-dimensional code data; the target detection model is obtained by acquiring a first detection model; the first detection model is obtained by training an initial detection model based on enhanced training samples; use a lightweight network to prune the first detection model; fine-tune the pruned first detection model to generate a second detection model; convert the second detection model into a corresponding inference model, and perform quantization operations on the inference model to generate;

[0030] Generate the detection result of the two-dimensional code data.

[0031] The third aspect of this application provides a two-dimensional code detection model lightweight device, including:

[0032] A first acquisition module, configured to acquire a first detection model; the first detection model is obtained by training an initial detection model based on enhanced training samples;

[0033] A pruning module, configured to prune the first detection model using a lightweight network;

[0034] A fine-tuning module, configured to fine-tune the pruned first detection model to generate a second detection model;

[0035] A first generation module, configured to convert the second detection model into a corresponding inference model, and perform quantization operations on the inference model to generate a target detection model; the target detection model is used to detect two-dimensional codes.

[0036] The fourth aspect of this application provides a two-dimensional code detection device, including:

[0037] A second acquisition module, configured to acquire two-dimensional code data to be recognized;

[0038] A detection module, configured to detect the two-dimensional code data using a target detection model; the target detection model is obtained by acquiring a first detection model; the first detection model is obtained by training an initial detection model based on enhanced training samples; use a lightweight network to prune the first detection model; fine-tune the pruned first detection model to generate a second detection model; convert the second detection model into a corresponding inference model, and perform quantization operations on the inference model to generate;

[0039] A second generation module, configured to generate the detection result of the two-dimensional code data.

[0040] The fifth aspect of this application provides an electronic device, including:

[0041] A processor; and

[0042] A memory stores executable code which, when executed by the processor, causes the processor to execute the method as described above.

[0043] The sixth aspect of the present application provides a computer-readable storage medium storing executable code which, when executed by a processor of an electronic device, causes the processor to execute the method as described above.

[0044] The technical solution provided by the present application may include the following beneficial effects: by obtaining a first detection model, which is obtained by training an initial detection model based on enhanced training samples, pruning the first detection model using a lightweight network, fine-tuning the pruned first detection model to generate a second detection model, converting the second detection model into a corresponding inference model, and performing a quantization operation on the inference model to generate a target detection model. The target detection model is used to detect two-dimensional codes, which can ensure the accuracy of two-dimensional code detection in the presence of interference, and can ensure the detection accuracy of the model while compressing the detection model, improve the detection speed of the model, and is more suitable for deployment on the edge side.

[0045] It should be understood that the above general description and the following detailed description are only exemplary and explanatory, and cannot limit the present application. Description of the Drawings

[0046] By describing the exemplary embodiments of the present application in more detail in conjunction with the drawings, the above and other objects, features, and advantages of the present application will become more obvious. Among them, in the exemplary embodiments of the present application, the same reference numerals generally represent the same components.

[0047] Figure 1 is a flowchart showing the method for lightweighting a two-dimensional code detection model according to an embodiment of the present application;

[0048] Figure 2 is another flowchart showing the method for lightweighting a two-dimensional code detection model according to an embodiment of the present application;

[0049] Figure 3 is a structural diagram showing the target detection model according to an embodiment of the present application;

[0050] Figure 4 is a flowchart showing the two-dimensional code detection method according to an embodiment of the present application;

[0051] Figure 5 is a structural diagram showing the device for lightweighting a two-dimensional code detection model according to an embodiment of the present application;

[0052] Figure 6It is a schematic structural diagram of the QR code detection model lightweight device shown in the embodiments of the present application;

[0053] Figure 7 It is a schematic structural diagram of the electronic device shown in the embodiments of the present application. Detailed implementation manners

[0054] The embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although the embodiments of the present application are shown in the drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to make the present application more thorough and complete, and to fully convey the scope of the present application to those skilled in the art.

[0055] The terms used in the present application are only for the purpose of describing specific embodiments and are not intended to limit the present application. The singular forms of "a", "the" and "said" used in the present application and the appended claims are also intended to include the plural forms unless the context clearly dictates otherwise. It should also be understood that the term "and / or" as used herein refers to and includes any or all possible combinations of one or more of the associated listed items.

[0056] It should be understood that although the terms "first", "second", "third", etc. may be used in the present application to describe various information, such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Thus, the features defined with "first" and "second" may explicitly or implicitly include one or more of such features. In the description of the present application, "a plurality" means two or more unless otherwise specifically defined.

[0057] In the currently related QR code detection methods, such as the method based on deep learning, mainly a model is used to detect the QR code, but the model has a large volume and is not suitable for off-line deployment on the edge side.

[0058] In view of the above problems, the embodiments of the present application provide a QR code detection model lightweight method, which can ensure the accuracy of model detection while compressing the detection model.

[0059] The technical solutions of the embodiments of the present application will be described in detail below with reference to the accompanying drawings.

[0060] Figure 1 It is a schematic flow diagram of the QR code detection model lightweight method shown in the embodiments of the present application.

[0061] See Figure 1 and the method includes:

[0062] Step 101: Obtain a first detection model. The first detection model is obtained by training an initial detection model based on the training samples after enhancement processing.

[0063] Traditional QR code detection methods are limited by image quality, the orientation and angle of the QR code, are sensitive to noise and blurred images, may require complex post-processing, and have poor performance in cases of uneven illumination or low contrast. Also, they handle multi-two-dimensional detection poorly. To overcome the above problems, in this application, the training samples are processed for augmentation. The enhancement processing may include the following methods:

[0064] (1) Apply random hue adjustment to the training samples. By converting the RGB (RGB color model) image to the HSV (Hue, Saturation, Value, HSV color model) format, adjust each random noise under HSV respectively, adjust the saturation, and adjust the exposure, ensuring the robustness of detection in different lighting environments.

[0065] (2) Apply operations such as random rotation, scaling, translation, shear vertical projection, and perspective transformation to the training samples, ensuring the robustness of detection under different angles and with a shaking lens.

[0066] (3) Apply random splicing, fusion, segmentation and filling to the training data pictures, ensuring the robustness of detection in the case of multiple QR codes.

[0067] One or more of the above methods can be selected to perform enhancement processing on the training samples. The initial detection model is trained using the training samples after enhancement processing, so that the model has better detection effects and accuracy in different lighting environments, with a shaking lens, and in the case of multiple QR codes.

[0068] Step 102: Prune the first detection model using a lightweight network.

[0069] The lightweight network (shuffleNetV2) plays a role in extracting image features during the process of QR code recognition. shuffleNetV2 has more efficient computing performance, specifically reflected in that the network reduces element-wise operations during convolution, such as adding features and the ReLU (Rectified linear unit) operation of the activation function. At the same time, the number of channels remains consistent during the convolution process for input and output, as well as multi-branch parallelism, etc. The memory access consumption (MAC) is lower, and it has more efficient performance, enabling faster operation on terminal devices. In the embodiments of this application, the first detection model is pruned using the lightweight network, thereby initially compressing the volume of the model.

[0070] Step 103: Fine-tune the pruned first detection model to generate a second detection model;

[0071] After pruning the first detection model, in order to reduce the model size, runtime memory occupancy, reduce the number of computational operations and not reduce the accuracy, recalibrate the channel feature responses to enhance the network's representation ability, and continuously apply channel attention and spatial attention on the feature map, the pruned first detection model can be fine-tuned and optimized to generate a second detection model.

[0072] Step 104: Convert the second detection model into a corresponding inference model, and perform quantization operations on the inference model to generate a target detection model; the target detection model is used to detect QR codes.

[0073] Normally, the trained model cannot be directly applied to terminal devices (such as smartphones). The model needs to be converted into a model that can run on terminal devices. At the same time, in order to further compress the model volume, quantization operations can be performed on the inference model, thereby generating a target detection model. The target detection model can be used to detect QR codes.

[0074] The embodiment of the present application discloses a method for lightweighting a QR code detection model. By obtaining a first detection model, which is trained from an initial detection model based on enhanced training samples, pruning the first detection model using a lightweight network, fine-tuning the pruned first detection model to generate a second detection model, converting the second detection model into a corresponding inference model, and performing quantization operations on the inference model to generate a target detection model, the target detection model is used to detect QR codes, so as to ensure the accuracy of QR code detection in the case of interference with QR codes, and at the same time, while compressing the detection model, ensure the detection accuracy of the model, improve the detection speed of the model, and be more suitable for deployment on the edge side.

[0075] Figure 2 It is another process schematic diagram of the method for lightweighting the QR code detection model shown in the embodiment of the present application.

[0076] See Figure 2 , the method includes:

[0077] Step 201: Obtain a first detection model; the first detection model is trained from an initial detection model based on enhanced training samples;

[0078] Training the initial detection model with enhanced training samples enables the first detection model to have better detection effects and accuracy in different lighting environments, different shaking lenses, multiple QR codes, etc.

[0079] Step 202: Prune the first detection model using a lightweight network;

[0080] The first detection model is pruned using a lightweight network, thus initially compressing the volume of the model.

[0081] In an alternative embodiment of the present application, the first detection model includes a detection algorithm module and a model head; step 202 includes:

[0082] Sub-step S11, using a lightweight network as the backbone network of the detection algorithm module;

[0083] Sub-step S12, using a pixel aggregation network as the model head of the first detection model.

[0084] The first detection model includes a detection algorithm module (nanodet) and a model head (model head). Among them, nanodet is a general term for the entire detection algorithm, which includes a backbone network (backbone). In the embodiment of the present application, the feature extraction network shufflenetV2 is used as the backbone network of the detection algorithm module.

[0085] Using shufflenetV2 as the backbone network can meet the requirements of feature extraction in terms of speed, but the accuracy will decrease in a particularly complex detection environment. Therefore, using a pixel aggregation network (PAN, Pyramid Attention Network) as the model head can improve the accuracy of the final detection result. PAN adds a bottom-up information path on the basis of FPN (Feature Pyramid Network) to enhance the semantic information of the low-level feature map. The traditional FPN mainly transmits high-level features to the low-level feature map through a top-down path, while PAN adds a bottom-up path on this basis, enabling the low-level feature map to also receive high-level semantic information from the upper layer. It improves the network structure of the Feature Pyramid Network (FPN) and has a better effect in capturing features at different scales of the picture. By using a pixel aggregation network as the model head of the first detection model, multi-scale feature fusion can be performed, enabling the model to better process features at different scales; the enhanced low-level features improve the semantic expression ability; it improves flexibility and adaptability and can be easily combined with different basic network architectures; it has better detection ability and segmentation performance.

[0086] Step 203, fine-tuning the pruned first detection model to generate a second detection model;

[0087] After pruning the first detection model, in order to reduce the model size, runtime memory occupancy, reduce the number of computational operations and not reduce the accuracy, and recalibrate the channel feature responses to enhance the network's representation ability, and continuously apply channel attention and spatial attention on the feature map, the pruned first detection model can be fine-tuned and optimized to generate a second detection model.

[0088] In an alternative embodiment of the present application, step 203 includes:

[0089] Sub-step S21, reallocating the channels of the convolutional layers in the lightweight network;

[0090] Sub-step S22, replacing the target convolutional module in the lightweight network with a squeeze-and-excitation network and a convolutional block attention module.

[0091] After pruning, in order to reduce the model size, runtime memory occupancy, reduce the number of computational operations and not reduce the accuracy, channel reallocation can be performed on each convolutional layer of ShuffleNetV2 to remove the channels that do not contribute to object detection.

[0092] In order to recalibrate the channel feature responses to enhance the network's representation ability, and continuously apply channel attention and spatial attention on the feature map, the 3x3 convolutional module in ShuffleNetV2 can be replaced with a squeeze-and-excitation network (SENet, Squeeze-and-Excitation Networks) and a convolutional block attention module (CBAM, convolutional block attention module).

[0093] In an alternative embodiment of the present application, sub-step S21 includes:

[0094] Sub-step S211, obtaining a preset scaling factor for the channels and the output results of the channels;

[0095] Sub-step S212, jointly training the channels and the preset scaling factor;

[0096] Sub-step S213, determining the target scaling factor based on the training results;

[0097] Sub-step S214, removing the channels corresponding to the target scaling factor.

[0098] Introduce a preset scaling factor γ for each channel, multiply the output of the channel by the preset scaling factor γ, jointly train the channel and the preset scaling factor γ, and perform sparse regularization training on the preset scaling factor γ. Finally, determine the preset scaling factor with a smaller training result as the target scaling factor, and remove the channel corresponding to the target scaling factor, so as to delete unimportant channels without seriously affecting the generalization performance.

[0099] After pruning optimization, the model size is reduced from 17m to 13m, while the model accuracy only drops by 0.13%. The drop in model accuracy is within an acceptable range and has negligible impact on the final detection results.

[0100] In an optional embodiment of the present application, the steps after step 203 include:

[0101] Train the second detection model using the enhanced training samples.

[0102] After generating the second detection model, the second detection model can be continuously trained using the enhanced training samples.

[0103] Step 204, perform multiple format conversions on the second detection model through a preset model deployment framework to generate an inference model.

[0104] Generally, the trained model cannot be directly applied to terminal devices (such as smartphones), and the model needs to be converted. Multiple format conversions can be performed on the second detection model through a preset model deployment framework (ncnn framework) to generate an inference model. The process of format conversion is as follows: Use pytorch to train the model and save the model in the ".pt" model format; convert the ".pt" model format to the ".torchscript" format. The ".torchscript" format is a format of pytorch that contains a computational graph; use pnnx to convert the ".torchscript" format model into ".param" and ".bin" files. Among them, ".param" is the ncnn model structure file, and ".bin" is the ncnn model weight file. The ncnn framework deeply optimizes various model operators on terminal devices and supports various terminal device cpu (Central Processing Unit) architectures, ensuring that the model can efficiently operate on mobile phones.

[0105] Step 205, perform quantization operation on the inference model to generate a target detection model; the target detection model is used to detect two-dimensional codes.

[0106] To further compress the volume of the model, a quantization operation can be performed on the inference model to generate a target detection model. The target detection model can be used to detect two-dimensional codes.

[0107] In an alternative embodiment of the present application, the inference model has a first precision, and step 205 includes:

[0108] Based on a preset command, convert the first precision of the inference model into a second precision; where the first precision is greater than the second precision.

[0109] The model usually obtains the first precision (float32 precision) during server training, and ncnn converts it into the first precision (float16 precision). The specific command is:

[0110] Ncnnoptimize

[0111] nanodet_plus.param

[0112] nanodet_plus.binnanodet_plus-opt.paramnanodet_plus-opt.bin 65536.

[0113] In the embodiment of the present application, a half-precision quantization method is adopted. The float16 precision halves the precision of the model weight parameters, and the size of the model can be compressed by half. The final model size is reduced to 2.3m, and the inference speed on the terminal device cpu is about 40ms, about 25fps, which not only compresses the volume of the model, but also improves the detection speed.

[0114] As Figure 3 shown, it is a schematic structural diagram of the object detection model, including a backbone network, PAN, a prediction head, and an assignment guidance module (Assign Guidance Module). Among them, the path marked with S is "stop-gradient" (to avoid the collapsed solution), and the path marked with T is only used for the training of the model. The remaining paths can be used for training and inference, and the assignment guidance module is only used in the training process.

[0115] The embodiment of the present application discloses a method for lightweighting a two-dimensional code detection model. By obtaining a first detection model, the first detection model is obtained by training an initial detection model based on enhanced training samples, pruning the first detection model using a lightweight network, fine-tuning the pruned first detection model to generate a second detection model, performing multiple format conversions on the second detection model through a preset model deployment framework to generate an inference model, and performing a quantization operation on the inference model to generate an object detection model. The object detection model is used to detect two-dimensional codes, so as to ensure the accuracy of two-dimensional code detection in the case of interference with two-dimensional codes, and to ensure the detection accuracy of the model and improve the detection speed of the model while compressing the detection model, which is more suitable for deployment on the edge side.

[0116] Figure 4 It is a schematic flowchart of the QR code detection method shown in the embodiments of the present application.

[0117] See Figure 4 , the method includes:

[0118] Step 401, obtain the QR code data to be recognized;

[0119] Obtain the QR code data to be recognized and input the QR code data into the target detection model.

[0120] In the embodiments of the present application, the model can be loaded and inferred using C++. First, load the model through the following command: "ncnn::Net nanodetplus;

[0121] nanodetplus.load_param(param.c_str());

[0122] nanodetplus.load_model(bin.c_str());".

[0123] Optionally, input the QR code data to be recognized through the following command:

[0124] "ncnn::Extractor ex = nanodetplus.create_extractor();

[0125] ex.input(\"data\", in);".

[0126] Step 402, detect the QR code data using the target detection model; the target detection model is obtained by acquiring a first detection model; the first detection model is trained based on the enhanced training samples for the initial detection model; pruning is performed on the first detection model using a lightweight network; fine-tuning is performed on the pruned first detection model to generate a second detection model; the second detection model is converted into a corresponding inference model, and quantization operation is performed on the inference model to generate;

[0127] Detect the QR code data using the target detection model, where the target detection data is obtained by acquiring a first detection model; the first detection model is trained based on the enhanced training samples for the initial detection model; pruning is performed on the first detection model using a lightweight network; fine-tuning is performed on the pruned first detection model to generate a second detection model; the second detection model is converted into a corresponding inference model, and quantization operation is performed on the inference model to generate.

[0128] The detection can be executed through the following command to obtain the output:

[0129] "ncnn::Mat out;

[0130] ex.extract(\"output\", out);"

[0131] Step 403: Generate the detection result of the QR code data.

[0132] Finally, based on the result output by the object detection model, it is parsed to generate the detection result of the QR code data.

[0133] The output result can be parsed through the following command:

[0134] "decode_infer(out)".

[0135] The embodiment of the present application discloses a QR code detection method, which includes obtaining the QR code data to be recognized; detecting the QR code data by using an object detection model; the object detection model is obtained by obtaining a first detection model; the first detection model is trained based on the enhanced training samples for the initial detection model; pruning the first detection model by using a lightweight network; fine-tuning the pruned first detection model to generate a second detection model; converting the second detection model into a corresponding inference model and performing quantization operation on the inference model to generate; generating the detection result of the QR code data, thereby improving the speed of QR code detection.

[0136] Corresponding to the foregoing embodiment of the application function implementation method, the present application also provides a QR code detection model lightweight device, a QR code detection device, an electronic device, and corresponding embodiments.

[0137] Figure 5 It is a schematic structural diagram of the QR code detection model lightweight device shown in the embodiment of the present application.

[0138] See Figure 5 , the device includes:

[0139] The first acquisition module 501 is used to acquire a first detection model; the first detection model is trained based on the enhanced training samples for the initial detection model;

[0140] The pruning module 502 is used to prune the first detection model by using a lightweight network;

[0141] The fine-tuning module 503 is used to fine-tune the pruned first detection model to generate a second detection model;

[0142] The first generation module 504 is used to convert the second detection model into a corresponding inference model and perform quantization operation on the inference model to generate an object detection model; the object detection model is used to detect QR codes.

[0143] In an alternative embodiment of the present application, the first detection model includes a detection algorithm module and a model head; the pruning module 502 includes:

[0144] A backbone network sub-module for using a lightweight network as the backbone network of the detection algorithm module;

[0145] A model head sub-module for using a pixel aggregation network as the model head of the first detection model.

[0146] In an alternative embodiment of the present application, the fine-tuning module 503 includes:

[0147] An allocation sub-module for reallocating the channels of the convolutional layers in the lightweight network;

[0148] A replacement sub-module for replacing the target convolutional module in the lightweight network with a squeeze-and-excitation network and a convolutional block attention module.

[0149] In an alternative embodiment of the present application, the allocation sub-module is further configured to obtain a preset scaling factor of the channels and the output result of the channels; jointly train the channels and the preset scaling factor to determine a target scaling factor based on the training result; and remove the channels corresponding to the target scaling factor.

[0150] In an alternative embodiment of the present application, the device further includes:

[0151] A training module for training the second detection model using the enhanced training samples.

[0152] In an alternative embodiment of the present application, the first generation module 504 includes:

[0153] A first conversion sub-module for performing multiple format conversions on the second detection model through a preset model deployment framework to generate an inference model.

[0154] In an alternative embodiment of the present application, the inference model has a first accuracy, and the first generation module 504 further includes:

[0155] A second conversion sub-module for converting the first accuracy of the inference model into a second accuracy based on a preset command; where the first accuracy is greater than the second accuracy.

[0156] An embodiment of the present application discloses a device for lightweighting a QR code detection model. By obtaining a first detection model, which is obtained by training an initial detection model based on enhanced training samples, pruning the first detection model using a lightweight network, fine-tuning the pruned first detection model to generate a second detection model, converting the second detection model into a corresponding inference model, and performing quantization operations on the inference model to generate a target detection model. The target detection model is used to detect QR codes, thereby ensuring the accuracy of QR code detection in the presence of interference, and being able to compress the detection model while ensuring the detection accuracy of the model and improving the detection speed of the model.

[0157] Figure 6 It is a schematic structural diagram of the QR code detection device shown in the embodiment of the present application.

[0158] See Figure 6 , the device includes:

[0159] A second acquisition module 601, configured to acquire QR code data to be recognized;

[0160] A detection module 602, configured to detect the QR code data using the target detection model. The target detection model is obtained by obtaining a first detection model, which is obtained by training an initial detection model based on enhanced training samples, pruning the first detection model using a lightweight network, fine-tuning the pruned first detection model to generate a second detection model, converting the second detection model into a corresponding inference model, and performing quantization operations on the inference model to generate;

[0161] A second generation module 603, configured to generate a detection result of the QR code data.

[0162] An embodiment of the present application discloses a QR code detection device. By obtaining QR code data to be recognized, detecting the QR code data using a target detection model. The target detection model is obtained by obtaining a first detection model, which is obtained by training an initial detection model based on enhanced training samples, pruning the first detection model using a lightweight network, fine-tuning the pruned first detection model to generate a second detection model, converting the second detection model into a corresponding inference model, and performing quantization operations on the inference model to generate; generating a detection result of the QR code data, improving the detection speed of the QR code.

[0163] Regarding the device in the above embodiment, the specific manners in which each module performs operations have been described in detail in the embodiment related to the method, and will not be elaborated here.

[0164] Figure 7 It is a schematic structural diagram of the electronic device shown in the embodiment of the present application.

[0165] See Figure 7 , the electronic device 700 includes a memory 710 and a processor 720.

[0166] The processor 720 can be a Central Processing Unit (CPU), or can also be other general-purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field-Programmable Gate Arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc.

[0167] The memory 710 can include various types of storage units, such as system memory, read-only memory (ROM), and permanent storage devices. Among them, the ROM can store static data or instructions required by the processor 720 or other modules of the computer. The permanent storage device can be a readable and writable storage device. The permanent storage device can be a non-volatile storage device that does not lose the stored instructions and data even when the computer is powered off. In some embodiments, the permanent storage device uses a mass storage device (such as a magnetic or optical disk, flash memory) as the permanent storage device. In some other embodiments, the permanent storage device can be a removable storage device (such as a floppy disk, optical drive). The system memory can be a readable and writable storage device or a volatile readable and writable storage device, such as dynamic random access memory. The system memory can store some or all of the instructions and data required by the processor during operation. In addition, the memory 710 can include any combination of computer-readable storage media, including various types of semiconductor storage chips (such as DRAM, SRAM, SDRAM, flash memory, programmable read-only memory), and magnetic disks and / or optical disks can also be used. In some embodiments, the memory 710 can include a removable storage device that is readable and / or writable, such as a compact disc (CD), read-only digital versatile disc (such as DVD-ROM, dual-layer DVD-ROM), read-only Blu-ray disc, ultra-density disc, flash memory card (such as SD card, min SD card, Micro-SD card, etc.), magnetic floppy disk, etc. The computer-readable storage medium does not include carrier waves and instantaneous electronic signals transmitted wirelessly or wired.

[0168] An executable code is stored on the memory 710, and when the executable code is processed by the processor 720, it can cause the processor 720 to execute some or all of the methods described above.

[0169] In addition, the method according to the present application can also be implemented as a computer program or a computer program product, which includes computer program code instructions for performing some or all of the steps in the above method of the present application.

[0170] Alternatively, the present application can also be implemented as a computer-readable storage medium (or a non-transitory machine-readable storage medium or a machine-readable storage medium), on which executable code (or a computer program or computer instruction code) is stored. When the executable code (or the computer program or computer instruction code) is executed by a processor of an electronic device (or a server, etc.), the processor is caused to execute some or all of the steps of the above method according to the present application.

[0171] The various embodiments of the present application have been described above. The above description is exemplary and not exhaustive, and is also not limited to the disclosed embodiments. Many modifications and variations are obvious to those of ordinary skill in the art in the technical field without departing from the scope and spirit of the described embodiments. The choice of terms used herein is intended to best explain the principles of the embodiments, practical applications, or improvements to the technologies in the market, or to enable other ordinary skill in the art in the technical field to understand the disclosed embodiments.

Claims

1. A method for lightweighting a QR code detection model, characterized in that: Obtain a first detection model; the first detection model is obtained by training an initial detection model based on enhanced training samples; Prune the first detection model using a lightweight network; Fine-tune the pruned first detection model to generate a second detection model; Convert the second detection model into a corresponding inference model, and perform a quantization operation on the inference model to generate a target detection model; the target detection model is used to detect QR codes.

2. The method according to claim 1, characterized in that The first detection model includes a detection algorithm module and a model head; the step of pruning the first detection model using a lightweight network includes: Use the lightweight network as the backbone network of the detection algorithm module; Use a pixel aggregation network as the model head of the first detection model.

3. The method according to claim 2, wherein The step of fine-tuning the pruned first detection model includes: Reallocate the channels of the convolutional layers in the lightweight network; Replace the target convolutional module in the lightweight network with a squeeze-and-excitation network and a convolutional block attention module.

4. The method according to claim 3, wherein The step of reallocating the channels of the convolutional layers in the lightweight network includes: Obtain a preset scaling factor for the channels and the output result of the channels; Jointly train the channels and the preset scaling factor; Determine a target scaling factor based on the training result; Remove the channels corresponding to the target scaling factor.

5. The method according to claim 1 or 3, characterized in that The steps after fine-tuning the pruned first detection model to generate a second detection model include: Train the second detection model using the enhanced training samples.

6. The method according to claim 1, characterized in that, The step of converting the second detection model into a corresponding inference model includes: Perform multiple format conversions on the second detection model through a preset model deployment framework to generate the inference model.

7. The method according to claim 1 or 6, characterized in that, The inference model has a first accuracy, and the step of performing a quantization operation on the inference model includes: Based on a preset command, convert the first accuracy of the inference model into a second accuracy; where the first accuracy is greater than the second accuracy.

8. A QR code detection method, characterized in that: Obtain QR code data to be recognized; Detect the QR code data using a target detection model; the target detection model is obtained by obtaining a first detection model; the first detection model is obtained by training an initial detection model based on enhanced training samples; pruning the first detection model using a lightweight network; fine-tuning the pruned first detection model to generate a second detection model; converting the second detection model into a corresponding inference model, and performing a quantization operation to generate; Generate a detection result of the QR code data.

9. A device for lightweighting a QR code detection model, characterized in that: A first acquisition module for acquiring a first detection model; the first detection model is obtained by training an initial detection model based on enhanced training samples; A pruning module for pruning the first detection model using a lightweight network; A fine-tuning module for fine-tuning the pruned first detection model to generate a second detection model; A first generation module, configured to convert the second detection model into a corresponding inference model, perform a quantization operation on the inference model, and generate a target detection model; the target detection model is used to detect two-dimensional codes.

10. A two-dimensional code detection device, characterized in that: A second acquisition module, configured to acquire two-dimensional code data to be recognized; A detection module, configured to detect the two-dimensional code data by using the target detection model; The target detection model is obtained by acquiring a first detection model; the first detection model is obtained by training an initial detection model based on enhanced training samples; pruning the first detection model by using a lightweight network; fine-tuning the pruned first detection model to generate a second detection model; converting the second detection model into a corresponding inference model, and performing a quantization operation on the inference model to generate; A second generation module, configured to generate a detection result of the two-dimensional code data.

11. An electronic device, characterized in that, Including: A processor; And A memory, on which executable code is stored, and when the executable code is executed by the processor, the processor is caused to execute the method according to any one of claims 1-8.

12. A computer-readable storage medium, on which executable code is stored, and when the executable code is executed by a processor of an electronic device, the processor is caused to execute the method according to any one of claims 1-8.