A water surface floating object detection method and device based on a Raspberry Pi and an improved YOLOv5 algorithm

By integrating the transformer module and CBAM attention mechanism into the YOLOv5 algorithm, and pruning the Botteleneck module, an improved floating object detection model was constructed, solving the problems of detection efficiency and accuracy, and achieving real-time high-precision detection on Raspberry Pi.

CN115512245BActive Publication Date: 2026-01-06WUHAN UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202211118669.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-13
Publication Date
2026-01-06
Estimated Expiration
2042-09-13

AI Technical Summary

Technical Problem

Existing target detection technologies cannot improve detection efficiency while ensuring detection accuracy in the detection of floating objects on the water surface, especially on performance-limited embedded devices such as Raspberry Pi, where efficient real-time detection is difficult to achieve.

Method used

An improved object detection model was constructed by integrating a transformer module and adding a CBAM attention mechanism into the backbone network of the YOLOv5 algorithm, and pruning the Bottleneck module. The model was then deployed on a Raspberry Pi for real-time detection.

Benefits of technology

It improves detection accuracy and speed, reduces hardware costs, and enables real-time high-precision detection of floating objects on the water surface, reducing the false negative rate and image transmission time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115512245B_ABST
    Figure CN115512245B_ABST
Patent Text Reader

Abstract

The application discloses a water surface floating object detection method and device based on a Raspberry Pi and an improved YOLOv5 algorithm, wherein the method comprises the following steps: first, on the basis of the original YOLOv5, a CBAM attention mechanism and a transformer module are integrated, and the model is pruned; second, the model is trained on a computer, and when the loss of the model no longer decreases and the accuracy no longer increases, the training is stopped; third, the trained model is deployed on a Raspberry Pi carried on a UAV; and fourth, a camera carried on the UAV is used to shoot a water surface photo, and the Raspberry Pi is used to detect water surface floating objects in the photo in real time. On the one hand, the improved YOLOv5 algorithm is used to detect water surface floating objects in real time, and the detection accuracy and the resource occupation of the model are optimized while the detection speed is ensured; on the other hand, the detection algorithm is realized based on the Raspberry Pi, the cost of using a graphics card and an edge device is saved, and the application has practical significance and commercial value in the field of UAV cruising.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of embedded systems and computer vision technology, and in particular to a method and apparatus for detecting floating objects on the water surface based on Raspberry Pi and an improved YOLOv5 algorithm. Background Technology

[0002] As people's living standards improve, public awareness of environmental protection is gradually increasing. Floating debris on the water surface is an important indicator of water pollution. To better monitor water quality, some researchers have applied target detection technology to detect floating debris, especially in embedded devices such as unmanned cleaning boats and drones, which has significant commercial value. Currently, target detection technology has achieved good results in many tasks, but it still needs improvement in the detection of floating debris. Existing methods, when applied to performance-constrained embedded devices such as Raspberry Pi, cannot guarantee both improved detection efficiency and accuracy. Summary of the Invention

[0003] This invention provides a method and apparatus for detecting floating objects on the water surface based on Raspberry Pi and an improved YOLOv5 algorithm, which solves or at least partially solves the technical problem in the prior art that it is impossible to improve detection efficiency while ensuring detection accuracy.

[0004] To address the aforementioned technical problems, the first aspect of this invention provides a method for detecting floating objects on the water surface based on a Raspberry Pi and an improved YOLOv5 algorithm, comprising:

[0005] S1: An improved target detection model is constructed based on the original YOLOv5 algorithm as a floating object detection model. The improved target detection model integrates a transformer module into the last CSP module of the backbone network in the original YOLOv5 algorithm network structure, sets the number of Bottleneck modules in other CSP modules to 1, and adds a CBAM attention mechanism module after the Bottleneck module. The transformer module is used to capture global contextual information through self-attention mechanism, and the CBAM attention mechanism module enables the neural network to focus on more important information while acquiring global information.

[0006] S2: Train the floating object detection model on the computer. When the model's bounding box loss, target loss, and classification loss on the validation set no longer decrease, and the model's accuracy curve tends to be stable, the model converges, training stops, and the trained model is saved.

[0007] S3: Deploy the trained model on a Raspberry Pi mounted on a drone;

[0008] S4: Use the camera mounted on the drone to take photos of the water surface, and use the Raspberry Pi to detect floating objects in the water surface photos in real time.

[0009] In one implementation, after integrating the transformer module into the last CSP module of the backbone network in the original YOLOv5 algorithm network structure, a transformer-based CSP module TR_CSP module is obtained. The TR_CSP module includes three CBS modules and one transformer module, but does not contain the Bottleneck module.

[0010] In one implementation, the processing procedure of the TR_CSP module includes:

[0011] The input is divided into two branches. One branch passes through the CBS module and the transformer module in sequence, and the other branch passes through the CBS module. Then, the two branches are concatenated along the channel direction, and finally, the output is passed through another CBS module. The CBS module includes convolutional blocks, normalization processing, and activation functions to extract features from the input image. The transformer module uses a self-attention mechanism to capture global contextual information.

[0012] In one implementation, the number of Bottleneck modules in the CSP module of the backbone network and neck is set to 1. After adding a CBAM attention mechanism module after the Bottleneck module, a CSP module based on the CBAM attention mechanism is obtained: C_CSP module. C_CSP module includes three CBS modules, one CBAM module and one Bottleneck module without residuals.

[0013] In one implementation, the processing procedure of the C_CSP module includes:

[0014] The input is divided into two branches. One branch passes through the CBS module, the Bottleneck module without residual connections, and the CBAM module in sequence, while the other branch passes through the CBS module. Then, these two branches are concatenated along the channel direction, and finally, the output is passed through a CBS module. The CBAM attention mechanism consists of channel attention and spatial attention mechanisms, which are implemented through global average pooling and global max pooling. It is used to assign higher weights to regions or channels in the image that contain target features, so that the neural network pays more attention to regions and channels containing important features.

[0015] In one implementation, during the model training process of S2, the model is first trained on the MS COCO dataset, and then trained on the floating objects dataset.

[0016] In one implementation, the model is trained on a computer using the Ubuntu 18.04 operating system, equipped with an Intel Xeon Silver 4110 CPU, a Quadro P6000 graphics card with 24GB of video memory, CUDA version 11.0, and the deep learning framework PyTorch 1.7.0.

[0017] Based on the same inventive concept, a second aspect of the present invention provides a water surface floating object detection device based on a Raspberry Pi and an improved YOLOv5 algorithm, comprising:

[0018] The model building module is used to build an improved target detection model based on the original YOLOv5 algorithm, serving as a floating object detection model for water surfaces. The improved target detection model integrates a transformer module into the last CSP module of the backbone network in the original YOLOv5 algorithm network structure, sets the number of Bottleneck modules in the other CSP modules to 1, and adds a CBAM attention mechanism module after the Bottleneck module. The transformer module is used to capture global contextual information through a self-attention mechanism, and the CBAM attention mechanism module enables the neural network to focus on more important information while acquiring global information.

[0019] The model training module is used to train the floating object detection model on a computer. When the bounding box loss, target loss and classification loss of the model on the validation set no longer decrease and the accuracy curve of the model tends to be stable, the model converges, training stops, and the trained model is saved.

[0020] The model deployment module is used to deploy trained models on a Raspberry Pi mounted on a drone.

[0021] The detection module is used to take photos of the water surface using a camera mounted on a drone, and then uses a Raspberry Pi to detect floating objects in the photos in real time.

[0022] Based on the same inventive concept, a third aspect of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed, implements the method described in the first aspect.

[0023] Based on the same inventive concept, a fourth aspect of the present invention provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method described in the first aspect.

[0024] Compared with the prior art, the advantages and beneficial technical effects of the present invention are as follows:

[0025] A method for detecting floating objects on the water surface based on Raspberry Pi and an improved YOLOv5 algorithm is proposed. The network structure of the original YOLOv5 algorithm is improved by integrating a transformer module into the last CSP module of the backbone network. The number of Bottleneck modules in all CSP modules except the last CSP module (including all CSP modules in the backbone network except the last CSP module and all CSP modules contained in the neck) is set to 1. A CBAM attention mechanism module is added after the Bottleneck module. The transformer module is used to capture global contextual information through a self-attention mechanism, and the CBAM attention mechanism module enables the neural network to focus on more important information while acquiring global information. Compared to other improved algorithms, this invention improves model accuracy by integrating the CBAM attention mechanism and transformer module into YOLOv5. It also improves model speed by pruning certain convolutional layers (setting the number of Bottleneck modules to 1, reducing the number of Bottleneck modules). Finally, the improved YOLOv5 algorithm is deployed on a Raspberry Pi to achieve real-time detection of floating objects on the water surface. Compared to detection methods using GPU-equipped water cleaning boats, this saves hardware costs and offers higher detection accuracy and a lower false negative rate. Furthermore, compared to detection methods using edge servers, it reduces the time required to transmit images, enabling real-time detection of floating objects on the water surface. Attached Figure Description

[0026] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0027] Figure 1 This is a flowchart of a method for detecting floating objects on the water surface based on Raspberry Pi and an improved YOLOv5 algorithm, provided in an embodiment of the present invention.

[0028] Figure 2 This is the overall network structure diagram of the improved YOLOv5 (floating object detection model) provided in the embodiments of the present invention;

[0029] Figure 3 This is the overall network structure diagram of the original YOLOv5 in the existing technology;

[0030] Figure 4 This is a schematic diagram of the CBS module in the original YOLOv5 network structure;

[0031] Figure 5 This is a schematic diagram of the CSP module in the original YOLOv5 network structure;

[0032] Figure 6 This is a schematic diagram of Bottleneck with and without residual connections in the original YOLOv5 network structure;

[0033] Figure 7 This is a schematic diagram of the structure of the C_CSP module in an embodiment of the present invention;

[0034] Figure 8 This is a schematic diagram of the structure of the TR_CSP module in an embodiment of the present invention;

[0035] Figure 9 A schematic diagram of the structure of a computer-readable storage medium provided in an embodiment of the present invention;

[0036] Figure 10 This is a schematic diagram of the structure of a computer device provided in an embodiment of the present invention. Detailed Implementation

[0037] While existing object detection algorithms improve upon YOLOv5, they primarily employ grouped convolutions and channel attention mechanisms, which still suffer from slow processing speeds. The improved method in this invention employs model pruning (reducing the number of Bottleneck modules in the CSP module and setting them to have no residual connections, etc.) to improve detection speed. It also integrates a transformer module and a CBAM attention mechanism module. The transformer can capture global contextual information through self-attention, establishing long-range dependencies on the target and enhancing the neural network's feature extraction capabilities. The CBAM attention mechanism module allows the neural network to focus on more important information while acquiring global information, thus improving detection accuracy. Furthermore, the improved model can be directly deployed on a Raspberry Pi 4B, detecting one image per second, demonstrating high speed.

[0038] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0039] Example 1

[0040] This invention provides a method for detecting floating objects on the water surface based on Raspberry Pi and an improved YOLOv5 algorithm, comprising:

[0041] S1: An improved target detection model is constructed based on the original YOLOv5 algorithm as a floating object detection model. The improved target detection model integrates a transformer module into the last CSP module of the backbone network in the original YOLOv5 algorithm network structure, sets the number of Bottleneck modules in other CSP modules to 1, and adds a CBAM attention mechanism module after the Bottleneck module. The transformer module is used to capture global contextual information through self-attention mechanism, and the CBAM attention mechanism module enables the neural network to focus on more important information while acquiring global information.

[0042] S2: Train the floating object detection model on the computer. When the model's bounding box loss, target loss, and classification loss on the validation set no longer decrease, and the model's accuracy curve tends to be stable, the model converges, training stops, and the trained model is saved.

[0043] S3: Deploy the trained model on a Raspberry Pi mounted on a drone;

[0044] S4: Use the camera mounted on the drone to take photos of the water surface, and use the Raspberry Pi to detect floating objects in the water surface photos in real time.

[0045] Please see Figure 1 This is a flowchart of a method for detecting floating objects on the water surface based on Raspberry Pi and an improved YOLOv5 algorithm, provided in an embodiment of the present invention.

[0046] Specifically, the other CSP modules are all the CSP modules in the original YOLOv5 algorithm network structure except for the last CSP module in the backbone network. The original YOLOv5 algorithm network structure and the improved YOLOv5 algorithm network structure are as follows: Figure 3 and Figure 2 As shown.

[0047] This invention improves the last CSP module of the YOLOv5 backbone network by replacing the original Bottleneck module with a transformer module. The transformer can capture global contextual information through a self-attention mechanism, thereby establishing long-range dependencies on the target and enhancing the feature extraction capability of the neural network. It also improves the general CSP module in YOLOv5 by integrating the CBAM attention mechanism module into the original Bottleneck module and then integrating it into the main branch. This allows the neural network to focus on more important information while acquiring global information. The integrated CBAM attention mechanism module includes channel attention and spatial attention mechanisms. Since convolutions typically have multiple channels, the features of certain channels have a greater impact on the final target detection result; therefore, these channels should be assigned higher weights. Similarly, an image has many regions, and spatial attention helps the model determine which regions have more important features. The channel attention and spatial attention mechanisms are mainly implemented through global average pooling and global max pooling.

[0048] In one implementation, after integrating the transformer module into the last CSP module of the backbone network in the original YOLOv5 algorithm network structure, a transformer-based CSP module TR_CSP module is obtained. The TR_CSP module includes three CBS modules and one transformer module, but does not contain the Bottleneck module.

[0049] Specifically, CBS is an abbreviation for Conv (convolutional block), BatchNorm2d (normalization), and SiLU activation function. The module's function is to extract image features, and its structure is as follows: Figure 4 As shown.

[0050] In one implementation, the processing procedure of the TR_CSP module includes:

[0051] The input is divided into two branches. One branch passes through the CBS module and the transformer module in sequence, and the other branch passes through the CBS module. Then, the two branches are concatenated along the channel direction, and finally, the output is passed through another CBS module. The CBS module includes convolutional blocks, normalization processing, and activation functions to extract features from the input image. The transformer module uses a self-attention mechanism to capture global contextual information.

[0052] Please see Figure 5 This is a schematic diagram of the CSP module in the original YOLOv5 network structure; please refer to [link / reference]. Figure 8This is a schematic diagram of the TR_CSP module in an embodiment of the present invention.

[0053] Specifically, this invention integrates the transformer module into the last CSP module of the YOLOv5 backbone network to obtain the TR_CSP module. The TR_CSP module mainly consists of the CBS module and the transformer module. The difference between the TR_CSP module and the C_CSP module is that the TR_CSP module does not contain the Bottleneck module. The advantage of the transformer is that it uses a self-attention mechanism to capture global contextual information, thereby establishing a long-distance dependency on the target and improving the feature extraction capability of the neural network.

[0054] In one implementation, the number of Bottleneck modules in the CSP module of the backbone network and neck is set to 1. After adding a CBAM attention mechanism module after the Bottleneck module, a CSP module based on the CBAM attention mechanism is obtained: C_CSP module. C_CSP module includes three CBS modules, one CBAM module and one Bottleneck module without residuals.

[0055] In one implementation, the processing procedure of the C_CSP module includes:

[0056] The input is divided into two branches. One branch passes through the CBS module, the Bottleneck module without residual connections, and the CBAM module in sequence, while the other branch passes through the CBS module. Then, these two branches are concatenated along the channel direction, and finally, the output is passed through a CBS module. The CBAM attention mechanism consists of channel attention and spatial attention mechanisms, which are implemented through global average pooling and global max pooling. It is used to assign higher weights to regions or channels in the image that contain target features, so that the neural network pays more attention to regions and channels containing important features.

[0057] Please see Figure 6 This is a schematic diagram of Bottleneck with and without residual connections in the original YOLOv5 network structure. Bottleneck(true) represents the Bottleneck structure with residuals, and Bottleneck(False) represents the Bottleneck structure without residuals. Please refer to [link to documentation]. Figure 7 This is a schematic diagram of the structure of the C_CSP module in an embodiment of the present invention.

[0058] This invention integrates the CBAM attention mechanism into the YOLOv5 CSP general module to obtain the C_CSP module. The C_CSP module mainly consists of a CBS module, a Bottleneck module without residual connections, and a CBAM module. The CBAM attention mechanism comprises channel attention and spatial attention mechanisms, primarily implemented through global average pooling and global max pooling. It can assign higher weights to regions or channels in the image containing target features, thus enabling the neural network to focus more on regions and channels containing important features and suppress irrelevant information, thereby improving the accuracy of target detection.

[0059] This invention sets the number of Bottleneck modules in all C_CSP modules to 1, which reduces the number of convolutional layers. Then, the Bottleneck(True) of the backbone network is modified to Bottleneck(False), that is, residual connection structures are not used in the Bottleneck. The improved CSP module consists of a CBS module and a Bottleneck module without residual connections. This module first divides the input into two branches. One branch passes through the CBS module and the Bottleneck module without residual connections in sequence, and the other branch passes through the CBS module. Then, the two branches are concatenated along the channel direction, and finally, the result is output through a CBS module. This pruning method can greatly reduce the floating-point calculation and resource consumption during model detection, thereby improving the detection speed of the model.

[0060] In one implementation, during the model training process of S2, the model is first trained on the MS COCO dataset, and then trained on the floating objects dataset.

[0061] This invention uses transfer learning when training the model. The model is first pre-trained on the MS COCO dataset, and then the pre-trained model is trained on the floating objects dataset. This can accelerate the model convergence.

[0062] In one implementation, the model is trained on a computer using the Ubuntu 18.04 operating system, equipped with an Intel Xeon Silver 4110 CPU, a Quadro P6000 graphics card with 24GB of video memory, CUDA version 11.0, and the deep learning framework PyTorch 1.7.0.

[0063] In the specific implementation process, in step S3 of this invention, a floating object detection model is deployed on a Raspberry Pi 4B. The Raspberry Pi 4B uses Ubuntu 20.10 operating system or higher, Python version 3.7, and PyTorch version 1.8.0.

[0064] In step S4 of this invention, a Raspberry Pi is mounted on a drone, and a camera is connected to the CSI interface of the Raspberry Pi. The program calls the CSI camera to take pictures of the river and compresses the pictures, saving them in JPG format. Then, a floating object detection program is called to detect the pictures in real time, and finally the detected pictures are saved to a designated location.

[0065] In practical implementation, the improved YOLOv5 algorithm was applied to the real-time detection of floating objects on the water surface, and a comparative experiment was conducted with the original YOLOv5 series algorithms. The evaluation metrics for this invention include average accuracy, frames per second detected on a graphics card, time required to detect one image on a Raspberry Pi, floating-point computation, number of model parameters, and model size. Compared to the original YOLOv5 series algorithms, the improved YOLOv5 algorithm shows better overall performance in detecting floating objects on the water surface, with mAP@0.5, mAP@0.5:0.95, number of model parameters, and model size. The improved YOLOv5 algorithm outperforms the original YOLOv5 series algorithms in terms of both size and floating-point computation. The improved YOLOv5 algorithm has mAP@0.5 and mAP@0.5:0.95 values ​​of 0.842 and 0.545, respectively, which are 2.5% and 0.9% higher than the original YOLOv5n. The detection speed of this algorithm is similar to that of the YOLOv5n algorithm. It takes an average of 1.18 seconds to detect an image on a Raspberry Pi and 147 frames per second on a graphics card. This shows that the improved YOLOv5 algorithm can perform real-time, high-precision detection of floating objects on the water surface.

[0066] Specifically, in step four, the present invention applies the improved YOLOv5 algorithm to the real-time detection of floating objects on the water surface and conducts a comparative experiment with the original YOLOv5 series algorithms. The evaluation indicators of the present invention include average accuracy, the number of frames detected per second on the graphics card, the time required to detect an image on the Raspberry Pi, floating-point operation volume, number of model parameters, and model size.

[0067] To verify the effectiveness of the algorithm proposed in this invention, the algorithm of this invention was tested with the YOLOv5 series algorithms on the same platform and the same test set. The results of the comparison of some common performance indicators are shown in the table below.

[0068]

[0069]

[0070] The meanings of each indicator are as follows:

[0071] mAP@0.5: Mean accuracy of IoU (overlap) threshold of 0.5;

[0072] mAP@0.5:0.95: Mean accuracy;

[0073] Parameter: The number of model parameters;

[0074] Model size: The size of the model;

[0075] GFLOP: The number of floating-point operations performed on the model;

[0076] FPS GPU The number of images the model detects per second on the graphics card;

[0077] Detection time Raspberry: The time it takes for the model to detect an image on a Raspberry Pi 4B.

[0078] In the table, compared to the original YOLOv5 series algorithms, the algorithm of this invention performs better overall in detecting floating objects on the water surface. mAP@0.5, mAP@0.5:0.95, the number of model parameters, the model size, and the floating-point computation cost are all superior to the original YOLOv5 series algorithms. Based on the original YOLOv5n algorithm, mAP@0.5 and mAP@0.5:0.95 are improved by 2.5% and 0.9%, respectively. The detection speed of the algorithm proposed in this invention is similar to that of the YOLOv5n algorithm, requiring an average of 1.18 seconds to detect one image on a Raspberry Pi and 147 frames per second on a graphics card.

[0079] Example 2

[0080] Based on the same inventive concept, this embodiment provides a water surface floating object detection device based on Raspberry Pi and an improved YOLOv5 algorithm, including:

[0081] The model building module is used to build an improved target detection model based on the original YOLOv5 algorithm, serving as a floating object detection model for water surfaces. The improved target detection model integrates a transformer module into the last CSP module of the backbone network in the original YOLOv5 algorithm network structure, sets the number of Bottleneck modules in the other CSP modules to 1, and adds a CBAM attention mechanism module after the Bottleneck module. The transformer module is used to capture global contextual information through a self-attention mechanism, and the CBAM attention mechanism module enables the neural network to focus on more important information while acquiring global information.

[0082] The model training module is used to train the floating object detection model on a computer. When the bounding box loss, target loss and classification loss of the model on the validation set no longer decrease and the accuracy curve of the model tends to be stable, the model converges, training stops, and the trained model is saved.

[0083] The model deployment module is used to deploy trained models on a Raspberry Pi mounted on a drone.

[0084] The detection module is used to take photos of the water surface using a camera mounted on a drone, and then uses a Raspberry Pi to detect floating objects in the photos in real time.

[0085] Since the device described in Embodiment 2 of this invention is the same device used in implementing the water surface floating object detection method based on Raspberry Pi and the improved YOLOv5 algorithm in Embodiment 1 of this invention, those skilled in the art can understand the specific structure and variations of this device based on the method described in Embodiment 1 of this invention, and therefore will not be repeated here. All devices used in the method of Embodiment 1 of this invention fall within the scope of protection of this invention.

[0086] Example 3

[0087] Based on the same inventive concept, please refer to Figure 9 The present invention also provides a computer-readable storage medium 300 having a computer program 311 stored thereon, which, when executed, implements the method described in Embodiment 1.

[0088] Since the computer-readable storage medium described in Embodiment 3 of this invention is the same computer-readable storage medium used in the method for detecting floating objects on the water surface based on Raspberry Pi and the improved YOLOv5 algorithm in Embodiment 1 of this invention, those skilled in the art can understand the specific structure and variations of this computer-readable storage medium based on the method described in Embodiment 1 of this invention, and therefore will not be repeated here. All computer-readable storage media used in the method of Embodiment 1 of this invention fall within the scope of protection of this invention.

[0089] Example 4

[0090] Based on the same inventive concept, this application also provides a computer device, such as... Figure 10 As shown, it includes a memory 401, a processor 402, and a computer program 403 stored in the memory and executable on the processor. When the processor executes the program, it implements the method in Embodiment 1.

[0091] Since the computer device described in Embodiment 4 of this invention is the same computer device used to implement the water surface floating object detection method based on Raspberry Pi and the improved YOLOv5 algorithm in Embodiment 1 of this invention, those skilled in the art can understand the specific structure and variations of this computer device based on the method described in Embodiment 1 of this invention, and therefore will not be described again here. All computer devices used in the method of Embodiment 1 of this invention fall within the scope of protection of this invention.

[0092] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0093] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0094] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the invention.

[0095] Obviously, those skilled in the art can make various modifications and variations to the embodiments of the present invention without departing from the spirit and scope of the embodiments of the present invention. Thus, if these modifications and variations to the embodiments of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention also intends to include these modifications and variations.

Claims

1. A water surface floating object detection method based on Raspberry Pi and improved YOLOv5 algorithm, characterized in that, The method comprises the following steps: S1: an improved target detection model is constructed based on an original YOLOv5 algorithm as a water surface floating object detection model, wherein the improved target detection model integrates a transformer module in the last CSP module of the backbone network in the network structure of the original YOLOv5 algorithm to obtain a TR_CSP module based on the transformer, the TR_CSP module includes three CBS modules and one transformer module and does not include a bottleneck module; the number of bottleneck modules in other CSP modules is set to 1, and a CBAM attention mechanism module is added after the bottleneck module to obtain a C_CSP module, the C_CSP module includes three CBS modules, one CBAM module and one bottleneck module without residual connection, and the processing process of the TR_CSP module comprises: the input is divided into two branches, one branch sequentially passes through a CBS module and a transformer module, and the other branch passes through a CBS module, then the two branches are spliced along the channel direction, and finally a CBS module is used to output a result, wherein the CBS module includes a convolution block, normalization processing and an activation function, and is used to extract features of the input image, and the transformer module uses a self-attention mechanism to capture global context information; the processing process of the C_CSP module comprises: the input is divided into two branches, one branch sequentially passes through a CBS module, a bottleneck module without residual connection and a CBAM module, and the other branch passes through a CBS module; then the two branches are spliced along the channel direction, and finally a CBS module is used to output a result, the CBAM attention mechanism is composed of a channel attention mechanism and a spatial attention mechanism, is realized through global average pooling and global maximum pooling, and is used to set a higher weight for a region or a channel containing a target feature in an image, so that the neural network pays more attention to the region and the channel containing important features; S2: the water surface floating object detection model is trained on a computer, when the bounding box loss, target loss and classification loss of the model on a verification set no longer decrease, and the precision curve of the model tends to be in a stable state, the model converges, the training is stopped, and the trained model is saved; S3: the trained model is deployed on a Raspberry Pi carried on a drone; S4: a camera carried on the drone is used to shoot a water surface photo, and the Raspberry Pi is used to detect water surface floating objects in the water surface photo in real time.

2. The Raspberry Pi and improved YOLOv5 algorithm-based water surface floating object detection method according to claim 1, characterized in that, In the model training process of S2, the model is first trained in an MS COCO dataset, and then the model is trained in a water surface floating object dataset.

3. The Raspberry Pi and improved YOLOv5 algorithm-based water surface floating object detection method according to claim 1, characterized in that, When the model is trained on the computer, an Ubuntu 18.04 operating system is used, an Intel Xeon Silver 4110 CPU is provided, a Quadro P6000 graphics card is used for operation, the size of the video memory of the graphics card is 24 GB, the CUDA version is 11.0, and the deep learning framework is Pytorch 1.7.

0.

4. A water surface floating object detection device based on Raspberry Pi and improved YOLOv5 algorithm, characterized in that, The water surface floating object detection method based on the Raspberry Pi and the improved YOLOv5 algorithm according to claim 1 is implemented, and the detection device comprises: A model construction module is configured to construct an improved target detection model based on an original YOLOv5 algorithm as a water surface floating object detection model, wherein the improved target detection model integrates a transformer module in the last CSP module of a backbone network in the network structure of the original YOLOv5 algorithm, sets the number of Bottleneck modules in other CSP modules to 1, and increases a CBAM attention mechanism module after the Bottleneck module, the transformer module is configured to capture global context information through a self-attention mechanism, and the CBAM attention mechanism module enables the neural network to focus on more important information while obtaining global information; A model training module is configured to train the water surface floating object detection model on a computer, and when the bounding box loss, target loss and classification loss of the model on a verification set no longer decrease and the precision curve of the model tends to be in a stable state, the model converges, the training is stopped, and the trained model is saved; A model deployment module is configured to deploy the trained model on a Raspberry Pi carried on a UAV; A detection module is configured to use a camera carried on the UAV to take a water surface photo, and use the Raspberry Pi to detect water surface floating objects in the water surface photo in real time.

5. A computer-readable storage medium having stored thereon a computer program, characterized in that, The program is executed to implement the method according to any one of claims 1 to 3.

6. A computer device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, The processor implements the method according to any one of claims 1 to 3 when executing the program.