A testing method for physics experimental equipment in middle schools based on an improved YOLOv5
By improving the YOLOv5 network and combining it with ShuffleNet and Ghost-PAN structures, and optimizing the detection head and loss function, the accuracy and speed issues of detecting high school physics experimental equipment on low-computing-power devices were resolved, achieving more efficient detection results.
Patent Information
- Application Number
- CN202211510728.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-29
- Publication Date
- 2025-10-28
- Estimated Expiration
- 2042-11-29
AI Technical Summary
The existing YOLOv5 algorithm is difficult to meet the accuracy and speed requirements for testing high school physics experimental equipment on low-computing-power and low-power devices, especially on mobile devices, where the detection accuracy is not high and the computational complexity is too high.
An improved YOLOv5 network is adopted, with ShuffleNet network introduced as the backbone network. The FPN-PAN structure is replaced with Ghost-PAN structure, and the classification and regression tasks are decoupled in the detection head. An adaptive spatial task alignment module is added, and the loss function is optimized to improve detection accuracy and speed.
It significantly improves the accuracy and speed of testing high school physics experiment equipment on low-computing-power devices, reduces the amount of computation, and reduces the false detection rate, making it suitable for real-time testing on mobile devices.
Smart Images

Figure CN115937674B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of target detection technology, specifically relating to a detection method for middle school physics experimental equipment based on an improved YOLOv5. Background Technology
[0002] In recent years, with the widespread adoption of smart devices and the rapid development of target detection technology, the demand for deploying computer vision tasks on mobile terminals in teaching has been increasing. Currently, in intelligent high school physics experiment examinations, it is necessary to perform category detection and equipment positioning functions on low-computing-power, low-power mobile platforms to obtain the category and coordinate information of experimental equipment, thus providing a guarantee for judging circuit connection work.
[0003] Currently, mainstream object detection algorithms are mainly divided into two categories: two-stage detection algorithms and single-stage detection algorithms. A representative algorithm for two-stage detection is Faster R-CNN, which divides the detection problem into two stages: first, generating candidate regions; then, calculating class confidence and regressing the location within the candidate regions to obtain the accurate target result. While this type of algorithm has slightly higher accuracy, it is difficult to train and consumes too much memory, making it unsuitable for deployment on mobile devices. A representative algorithm for single-stage object detection is the YOLO series, which does not require generating candidate regions; it directly generates the target's location and classification confidence information through convolutional operations. Single-stage object detection algorithms are faster than two-stage detection algorithms and are more suitable for high real-time object detection tasks.
[0004] With continuous improvements to the YOLO series algorithms, the YOLOv5 algorithm has been widely used in target detection tasks due to its high detection accuracy and generalization ability. However, it still has a complex network structure and a large number of network parameters, requiring powerful GPUs to achieve real-time target detection. On mobile devices, it is difficult to meet the requirements of low latency and low complexity for a middle school physics experiment equipment detection system. Summary of the Invention
[0005] The technical problem to be solved by the present invention is to provide a detection method for physics experimental equipment in middle schools based on an improved YOLOv5, which addresses the shortcomings of the existing technology, so as to improve the detection accuracy and speed of physics experimental equipment on low computing power and low power consumption devices using YOLOv5.
[0006] To solve the above-mentioned technical problems, the present invention includes:
[0007] A testing method for high school physics experimental equipment based on an improved YOLOv5 includes the following steps:
[0008] S1. Obtain a dataset of physical experimental equipment photographed in various scenarios;
[0009] S2. Preprocess the collected dataset and divide it into training and test sets;
[0010] S3. Construct a detection model based on an improved YOLOv5 network. The improved YOLOv5 network is based on the original YOLOv5 network. The backbone network adopts the ShuffleNet network, and the neck network adopts the Ghost-PAN structure. The detection head of the original YOLOv5 network is decoupled, and an adaptive spatial task alignment module is introduced to enhance the interaction between classification and regression tasks and obtain localization or classification features that fuse different information.
[0011] S4. Train the detection model using the training set to obtain a trained detection model;
[0012] S5. Deploy the trained detection model to complete the detection of middle school physics experimental equipment.
[0013] Furthermore, in step S2, the dataset is preprocessed to adjust the captured images to a uniform resolution while ensuring that the aspect ratio remains consistent.
[0014] Furthermore, in step S2, the training set and test set are divided as follows: First, the captured images are labeled using the LabelImg annotation tool to obtain labeled XML files; then, the captured images and their XML files are stored in VOC format, creating Annotations and JPEGImages folders. The Annotations folder stores each label XML file, and the JPEGImages folder stores all images; the data format is converted to the txt format used by the YOLOv5 framework using a Python script; finally, the dataset is divided into training set and test set in a 4:1 ratio.
[0015] Furthermore, in step S3, the Ghost-PAN structure uses the GhostBlock module in GhostNet to process feature fusion between multiple layers, and its basic structural unit consists of a set of 1x1 convolutions and 3x3 depthwise separable convolutions.
[0016] Furthermore, in step S3, the adaptive spatial task alignment module is:
[0017] X task =w·X fpn
[0018] Among them, X task To integrate the positioning or classification features of different information, X fpn The output of the Ghost-PAN structure is the feature pyramid feature, where w is an adaptive parameter used to capture the dependencies between layers.
[0019] Furthermore, the adaptive parameter w is calculated based on the cross-layer task interaction features, as shown in the following formula:
[0020] w=σ((fc(x fpn )))
[0021] Where fc represents a fully connected layer, σ represents the sigmoid function, and x fpn It's X fpn The average pooling result.
[0022] Furthermore, from the location or classification feature X task The prediction yields the localization or classification result Y. task As shown in the following formula:
[0023] Y task =conv2(σ(conv1(X) task )))
[0024] Where conv1 and conv2 are 1×1 convolutional layers used for dimensionality reduction;
[0025] Finally, the sigmoid function is used to convert the classification or localization result Y. task Transformed into predicted scores or predicted bounding boxes.
[0026] Furthermore, in step S3, the output of the improved YOLOv5 network corresponds to two branches: a classification confidence branch and a regression branch, which respectively represent the category score and position offset of the predicted output of the improved YOLOv5 network. Based on the prediction results, the equipment category and position coordinates in the image are obtained.
[0027] Furthermore, in step S3, the loss function at the output of the improved YOLOv5 network includes two parts: the bounding box position error and the class quality prediction, wherein the regression loss L of the bounding box... box Using the CIOU loss function, the category quality assessment loss L obj&class Using the QFL loss function, the total loss function L Total The sum of the two is shown in the following formula:
[0028]
[0029] L obj&class =-|y-σ| 2 ((1-y)log(1-σ)+ylog(σ))
[0030]
[0031] Where B is the area of the predicted bounding box; Bgt ρ is the area of the ground truth bounding box; ρ is the Euclidean distance; b is the center point; c is the diagonal length of the minimum bounding box that covers both boxes. α is a parameter to balance positive numbers; v is a parameter to ensure consistent aspect ratio; y is the quality label from 0 to 1; σ is the network prediction; λ0 and λ1 are the weighting coefficients of the two losses; and i is the number of anchors in all grids.
[0032] The beneficial effects of this invention are:
[0033] This invention utilizes a dataset of physical experimental equipment captured in various scenarios to train and test an improved YOLOv5 network. The improved YOLOv5 network introduces a ShuffleNet network into the original YOLOv5 feature extraction network, introduces a Ghost Block module into the feature fusion module, decouples the output head and adds an adaptive spatial task alignment module, and merges the classification and confidence branches. This not only reduces computational load and improves network parallelism, but also makes the classification and regression tasks work more coordinated, reduces false detections of experimental equipment, and improves the detection speed of experimental equipment. Attached Figure Description
[0034] Figure 1 This is the overall algorithm flowchart of the present invention;
[0035] Figure 2 This is a network structure diagram of the improved algorithm of this invention;
[0036] Figure 3 These are the ShuffleNetV2 architecture diagrams with strides of 1 and 2.
[0037] Figure 4 This is a structural diagram of the detection head;
[0038] Figure 5 This is the structure diagram of the output end. Detailed Implementation
[0039] To facilitate understanding of the present invention, the invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. Those skilled in the art should understand that the embodiments described are merely illustrative of the invention and should not be considered as specific limitations thereof.
[0040] like Figure 1 As shown, this invention provides a testing method for high school physics experimental equipment based on an improved YOLOv5, comprising the following steps:
[0041] S1. Obtain a dataset of physical experimental equipment photographed in various scenarios;
[0042] S2. Preprocess the collected dataset and divide it into training and test sets;
[0043] S3. Construct a detection model based on an improved YOLOv5 network; the improved YOLOv5 network includes a backbone network, a neck network, a detection head, an output terminal, and a loss function. The improved YOLOv5 network is based on the original YOLOv5 network, with the backbone network using a ShuffleNet network and the neck network using a Ghost-PAN structure. The detection head of the original YOLOv5 network is decoupled, and an adaptive spatial task alignment module is introduced to enhance the interaction between classification and regression tasks, obtaining localization or classification features that fuse different information.
[0044] S4. Train the detection model using the training set to obtain a trained detection model;
[0045] S5. Deploy the trained detection model to complete the detection of middle school physics experimental equipment.
[0046] like Figure 2 The diagram shows the algorithm structure of the improved YOLOv5 network, which consists of four parts: feature extraction, feature fusion, training, and prediction.
[0047] First, a dataset was constructed using the MOKS camera and mobile phone to take experimental photos. The dataset was then preprocessed by adjusting the images to a uniform resolution while maintaining the same aspect ratio.
[0048] The dataset contains 7000 images across seven categories: Switch, Lightbulb, Resistance, Battery, Battery Bay, Voltmeter, and Ammeter. The images were then annotated using the LabelImg tool, resulting in an annotated XML file. This XML file contains the image name, image path, target name, and target location coordinates.
[0049] Next, the images and XML files were stored in VOC format, creating folders named Annotations and JPEGImages. The Annotations folder contained each tag's XML file, and the JPEGImages folder contained all the images. Then, a Python script was used to convert the data to the TXT format used by the YOLOv5 framework. Finally, the dataset was divided into training and test sets in a 4:1 ratio, with 5600 images used for training and 1400 images used for the test set. The image size was 416×416.
[0050] The image dataset with category labels obtained above is read using OpenCV functions. Data augmentation preprocessing is performed at the input to obtain feature maps. The preprocessed feature maps are then input into the backbone of the improved YOLOv5 network for feature extraction. The improved backbone network structure is as follows. Figure 3 As shown, a and b represent two cases with convolution strides of 1 and 2, respectively. This structure combines the ideas of depthwise separable convolution and channel splitting, enabling information exchange between channels while ensuring consistent output channel dimensions, and reducing computational cost by several times. It extracts feature maps of three different depths through the backbone network.
[0051] This invention replaces the original CSPDarkNet backbone network with a ShuffleNet network, simplifying the structure, reducing computational memory consumption, enabling faster model convergence, and improving detection speed. Based on the channel shuffle idea of ShuffleNetV2, it first fuses feature matrices of different dimensions, then divides the feature maps into different groups, and then uses depthwise convolution on the channels. Each channel is extracted by a convolutional kernel through a one-to-one correspondence. The feature maps obtained after combining depthwise convolutions using pointwise convolutions maintain dimensionality consistency. Finally, the channels are randomly mixed, and the result is output. Compared to the YOLOv5 backbone CSPDarkNet network, ShuffleNetV2's feature map processing involves fewer convolutional layers and adjusts the order and method of feature processing. By regrouping and fusing feature information, it reduces many convolutional operations and the number of parameters.
[0052] The feature map obtained from the ShuffleNet network is input into the feature fusion part of the improved YOLOv5 network to obtain a feature map that fuses information from different depths. Based on the feature output redundancy concept of GhostNet, this invention replaces the FPN-PAN structure in the original YOLOv5 feature fusion network with a Ghost-PAN structure. The GhostPAN structure uses GhostBlock from GhostNet as the module for handling feature fusion between multiple layers. Its basic structural unit consists of a set of 1x1 convolutions and 3x3 depthwise convolutions, replacing the ordinary convolutions in the original FPN+PAN structure. The computational cost is much lower than the original convolutions, further reducing computational consumption while ensuring output accuracy.
[0053] The feature maps obtained from the Ghost-PAN structure are input into the detection head of the improved YOLOv5 network. For each scale of feature map, it is then input into an adaptive spatial task alignment module. Addressing the issue of different focuses between the object detection classification and regression branches, this invention decouples the original YOLOv5 detection head. To avoid the lack of interaction after decoupling, an adaptive spatial task alignment method is introduced, enhancing the interaction between the two tasks while ensuring decoupling. This allows the two tasks to work more collaboratively, thereby adjusting their predictions more accurately.
[0054] Adaptive spatial task alignment modules, such as Figure 4 As shown, the definition is as follows:
[0055] X task =w·X fpn
[0056] Among them, X task To integrate the positioning or classification features of different information, X fpn The output features are the feature pyramid features of the Ghost-PAN structure, where w is an adaptive parameter used to capture the dependencies between layers.
[0057] The adaptive parameter w is calculated based on the cross-layer task interaction features, as shown in the following formula:
[0058] w=σ((fc(x fpn )))
[0059] Where fc represents a fully connected layer, σ represents the sigmoid function, and x fpn It's X fpn The average pooling result.
[0060] From location or classification features X task The prediction yields the localization or classification result Y. task As shown in the following formula:
[0061] Y task =conv2(σ(conv1(X) task )))
[0062] Where conv1 and conv2 are 1×1 convolutional layers used for dimensionality reduction;
[0063] Finally, the sigmoid function is used to convert the classification or localization result Y. task Transformed into predicted scores or predicted bounding boxes.
[0064] The output terminal after the above detection head calculation is as follows: Figure 5As shown, there are two branches: a classification confidence branch and a regression branch, representing the class score and location offset of the improved YOLOv5 network's prediction output, respectively. The equipment category and location coordinates in the image can be obtained from the prediction results. To ensure the accuracy of the network's predictions, the output of the improved network needs to be continuously updated using a loss function and backpropagation gradient calculation.
[0065] To address the inconsistency in score calculations during model training and inference in the original YOLOv5, this invention introduces a new representation for prediction and quality scores at the output. The quality score is merged into the category score, unifying the classification score with the Intersection over Union (IOU) between the predicted bounding box and the ground truth bounding box into a single joint variable. This allows for end-to-end training and direct use during inference, achieving consistency. The quality score of negative samples is suppressed to 0, resulting in more reliable model predictions.
[0066] Based on the modifications made to the original YOLOv5 output, this invention modifies the loss function accordingly. The improved loss function at the output of the YOLOv5 network includes two parts: the bounding box position error and the class quality prediction. The regression loss L of the bounding box... box Using the CIOU loss function, the category quality assessment loss L obj&class Using the QFL loss function, the total loss function L Total The sum of the two is shown in the following formula:
[0067]
[0068] L obj&class =-|y-σ| 2 ((1-y)log(1-σ)+ylog(σ))
[0069]
[0070] In the formula, B is the area of the prediction box; B gt ρ is the area of the ground truth bounding box; ρ is the Euclidean distance; b is the center point; c is the diagonal length of the minimum bounding box that covers both boxes. α is a parameter to balance positive numbers; v is a parameter to ensure consistent aspect ratio; y is the quality label from 0 to 1; σ is the network prediction; λ0 and λ1 are the weighting coefficients of the two losses; and i is the number of anchors in all grids.
[0071] Non-maximum suppression (NMS) is used to remove redundant bounding boxes, with the NMS algorithm specifically being DIOUNMS. NMS filters redundant detection boxes from the network output, primarily relying on two values: the classification confidence score and the Intersection over Union (IoU) between predicted boxes. First, all boxes in the network output are sorted according to their predicted scores. Then, boxes within the same category are sequentially compared with the box with the highest score to calculate the IoU. If the IoU value exceeds a certain range, the corresponding box's score is set to 0, thus eliminating it. This process continues until all boxes within the same category have been compared. The IoU is calculated using the DIOU method.
[0072] Finally, by training the improved algorithm model through specified rounds, a weight file in pt format is obtained. In order to deploy the model on edge devices with ARM CPU architecture and accelerate the model inference process, the pt format model needs to be converted into an NCNN format model that can be accelerated at the hardware level. This invention converts the model into an NCNN model through a model architecture conversion tool. Through the development of related APP, the camera is called for real-time image acquisition, and the experimental equipment is monitored in real-time by calling the model inference API, with a speed of about 32 frames per second.
[0073] Simulation experiment:
[0074] The experimental platform was compiled and tested using Python 3.7, with PyCharm 2020.2.2 as the development tool, Ubuntu 18.04 as the operating system, an i7-9700k eight-core processor with a clock speed of 3.6GHz, an Nvidia 1080Ti graphics card, 11GB of RAM, and 2TB of total storage. To better verify the effectiveness of the proposed algorithm, a Redmi K30 was used as the platform to perform testing on both mobile and embedded devices.
[0075] Mean accuracy (mAP) and detection speed (FPS) are used as evaluation metrics to measure the performance of the improved model after training. Mean accuracy is calculated by plotting a PR curve, which is a two-dimensional curve with precision and recall as the vertical and horizontal axes. Here, precision is the accuracy rate, and recall is the recall rate.
[0076] mAP is shown in the following formula:
[0077]
[0078]
[0079]
[0080]
[0081] Where: N TP N represents the correctly classified positive samples; FP These are misclassified positive samples; N FN These are misclassified negative samples; P(R) is the P-value in the PR curve, where R is the predicted recall and P is the predicted precision; N refers to the number of target object categories. Let AP be the AP value of n target classes.
[0082] Detection speed (FPS) refers to the number of images an algorithm can detect per second. The faster the inference speed, the better the real-time performance of the object detection network.
[0083] The dataset uses images of the aforementioned experimental equipment for training and testing. During training, there are 300 training epochs, with a batch size of 64, meaning each batch contains 64 original images. The initial learning rate is 0.001, the weight decay coefficient is 0.0001, and the learning rate momentum is set to 0.937.
[0084] To verify the superior performance of this invention, the same number of test sets were used under identical configuration conditions, and comparative experiments were conducted using several popular object detection networks: Faster R-CNN, SSD, YOLOv3-tiny, YOLOv4-tiny, YOLOv5, and an improved YOLOv5. SSD and the YOLO series are one-stage detection algorithms, while Faster R-CNN is a two-stage detection algorithm. Specific experimental results are shown in Table 1. As can be seen from the results in Table 1, this invention effectively improves the detection accuracy and speed for middle school physics experimental equipment. Compared to the original algorithm and other mainstream object detection algorithms, it is more suitable for deployment and real-time detection. Furthermore, this invention further improves the inference speed and detection accuracy of the YOLOv5 model, enabling fast and accurate detection of middle school physics experimental equipment on edge devices.
[0085] Table 1 Comparison of the improved model with different models
[0086]
Claims
1. A method for testing physics experimental equipment in middle school based on an improved YOLOv5, characterized in that, Includes the following steps: S1. Obtain a dataset of physical experimental equipment photographed in various scenarios; S2. Preprocess the collected dataset and divide it into training and test sets; S3. Construct a detection model based on an improved YOLOv5 network. The improved YOLOv5 network is based on the original YOLOv5 network. The backbone network adopts the ShuffleNet network, and the neck network adopts the Ghost-PAN structure. The detection head of the original YOLOv5 network is decoupled, and an adaptive spatial task alignment module is introduced to enhance the interaction between classification and regression tasks and obtain localization or classification features that fuse different information. The Ghost-PAN structure uses the GhostBlock module in GhostNet to handle feature fusion between multiple layers. Its basic structural unit consists of a set of 1x1 convolutions and 3x3 depthwise separable convolutions. The module for adaptive spatial task alignment is: X task =w·X fpn Among them, X task To integrate the positioning or classification features of different information, X fpn The feature pyramid features are output by the Ghost-PAN structure, and w is an adaptive parameter. The adaptive parameter w is calculated based on the cross-layer task interaction features, as shown in the following formula: w=σ((fc(x fpn ))) Where fc represents a fully connected layer, σ represents the sigmoid function, and x fpn It is X fpn Obtained by average pooling; From location or classification features X task The prediction yields the localization or classification result Y. task As shown in the following formula: AND task =conv2(σ(conv1(X task ))) Where conv1 and conv2 are 1×1 convolutional layers used for dimensionality reduction; Finally, the sigmoid function is used to convert the classification or localization result Y. task Converted into predicted scores or predicted bounding boxes; S4. Train the detection model using the training set to obtain a trained detection model; S5. Deploy the trained detection model to complete the testing of middle school physics experimental equipment.
2. The method for testing middle school physics experimental equipment based on improved YOLOv5 according to claim 1, characterized in that, In step S2, the dataset is preprocessed by adjusting the captured images to a uniform resolution while ensuring that the aspect ratio remains consistent.
3. The method for testing middle school physics experimental equipment based on improved YOLOv5 according to claim 1, characterized in that, In step S2, the training and test sets are divided as follows: First, the captured images are labeled using the LabelImg annotation tool to obtain labeled XML files; then, the captured images and their XML files are stored in VOC format, creating Annotations and JPEGImages folders. The Annotations folder stores each label XML file, and the JPEGImages folder stores all images; the data format is converted to the txt format used by the YOLOv5 framework using a Python script; finally, the dataset is divided into training and test sets in a 4:1 ratio.
4. The method for testing middle school physics experimental equipment based on improved YOLOv5 according to claim 1, characterized in that, In step S3, the output of the improved YOLOv5 network corresponds to two branches: a classification confidence branch and a regression branch, which respectively represent the category score and position offset of the predicted output of the improved YOLOv5 network. Based on the prediction results, the equipment category and position coordinates in the image are obtained.
5. The method for testing middle school physics experimental equipment based on improved YOLOv5 according to claim 1, characterized in that, In step S3, the loss function at the output of the improved YOLOv5 network includes two parts: the bounding box position error and the class quality prediction, wherein the regression loss L of the bounding box... box Using the CIOU loss function, the category quality assessment loss L obj&class Using the QFL loss function, the total loss function L Total The sum of the two is shown in the following formula: L obj&class =-|y-σ| 2 ((1-y)log(1-σ)+ylog(σ)) In the formula, B is the area of the prediction box; B gt ρ is the area of the ground truth box; ρ is the Euclidean distance; b is the center point; c is the diagonal length of the minimum box covering the two boxes; α is a parameter to balance positive numbers; v is a parameter to ensure consistent aspect ratio; y is the quality label from 0 to 1; σ is the network prediction; λ0 and λ1 are the weight coefficients of the two losses; and i is the number of anchors in all grids.