Forestry log visual recognition method based on improved YOLOv5
Patent Information
- Application Number
- CN202611139354.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-29
- Publication Date
- 2026-10-30
AI Technical Summary
①骨干网络对特征的提取能力有限,尤其是原木表面纹理细腻、缺陷区域与正常区域的对比度低,标准卷积层难以有效区分前景和背景中的细粒度特征差异;
①通过在骨干网络中引入CBAM注意力模块,增强了模型对细粒度特征的提取能力,使其在复杂背景下能够更准确地聚焦目标区域;
Smart Images

Figure CN123016197A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of machine vision technology, specifically relating to a visual recognition method for forest logs based on an improved YOLOv5. Background Technology
[0002] The traditional forestry industry chain encompasses multiple upstream stages, including logging, timber collection, transportation, measurement, and processing. For a long time, these stages have heavily relied on manual labor: loggers operate in complex forest environments, facing significant safety risks such as fallen trees and mechanical injuries; timber gauges manually measure the diameter, length, and defects of each log, resulting in high labor intensity and low efficiency; and timber processing decisions depend on personal experience, making it difficult to optimize timber utilization. With continuously rising labor costs and increasingly stringent safety requirements, the automation transformation of the forestry industry has become an inevitable trend.
[0003] In this transformation process, "vision" capability is a core bottleneck. To automate logging, transportation, and measurement, machines first need to accurately "see and understand" logs—that is, precisely identify the location, outline, surface defects, and various processing features of logs from images captured by cameras. However, this task faces numerous technical challenges: the surface texture of logs is complex and varied, natural lighting conditions are uncontrollable, target scales vary greatly, and background interference is severe. At the same time, the lack of large-scale publicly available labeled datasets in the forestry field restricts the application of deep learning-based vision methods in this area.
[0004] Current mainstream object detection algorithms are mainly divided into two categories: ① Two-stage detection algorithms, represented by the Faster R-CNN series. These algorithms first generate candidate regions (Region Proposals), then classify and regress each candidate region. While achieving high detection accuracy, they inherently suffer from high computational cost and slow inference speed, making them unsuitable for real-time detection. ② One-stage detection algorithms, represented by the YOLO (You Only Look Once) series and SSD (Single Shot MultiBox Detector). These algorithms directly perform dense sampling and prediction on the image, eliminating the need for candidate region generation and significantly improving inference speed. Among these, the YOLO series, through multiple iterations, has achieved an excellent balance between detection speed and accuracy, becoming one of the most widely used object detection frameworks in industry.
[0005] Since its inception in 2016, the YOLO algorithm has evolved through several versions, including YOLOv3, YOLOv4, YOLOv5, YOLOv6, and YOLOv8. In practical deployments, YOLOv5 offers the following significant advantages: ① A mature and stable model structure, a well-developed community ecosystem, and a large number of pre-trained models and tool support; ② It provides various model variants of different sizes (n / s / m / l / x), allowing for flexible selection based on computing resources; ③ It boasts highly readable and modular code, facilitating customized improvements for specific tasks. More importantly, many low-end embedded computing devices in industrial settings (such as Jetson Nano, Raspberry Pi, and edge computing boxes) are limited by computing power and driver compatibility, making them unable to run newer versions of the algorithm framework or larger models. YOLOv5, with its lightweight design and excellent hardware compatibility, has become the most practical choice for these scenarios.
[0006] Despite YOLOv5's excellent performance, its standard model still has the following shortcomings when dealing with complex scenarios such as forestry: ① The backbone network has limited ability to extract features, especially when the surface texture of logs is fine and the contrast between defective and normal areas is low. Standard convolutional layers have difficulty effectively distinguishing the fine-grained feature differences between the foreground and background. ② The Spatial Pyramid Pooling Module (SPPF) simply splices pooling features at all scales, failing to optimize for the extremely uneven distribution of forestry target scales (from large log cross-sections to tiny saw marks); ③ The upsampling operation in the neck network uses nearest neighbor interpolation, which cannot adaptively adjust according to the content of the feature map, resulting in limited quality of multi-scale feature fusion; ④ The detection head adopts a coupled structure, and the classification and localization tasks share the same set of convolution parameters, which leads to task competition and affects detection accuracy.
[0007] To address the aforementioned issues, this invention proposes an improved solution that enhances the target detection and instance segmentation performance of the YOLOv5 model in complex scenarios such as forestry by introducing an attention mechanism, optimizing the spatial pyramid pooling structure, and employing content-aware upsampling and decoupled detection heads. Summary of the Invention
[0008] The purpose of this invention is to provide a visual recognition method for forest logs based on an improved YOLOv5, in order to solve the problems existing in the background technology.
[0009] To achieve the above-mentioned technical objectives, the technical solution adopted by the present invention is as follows: The visual recognition method for forest logs based on the improved YOLOv5 includes the following steps: S100: Obtain the training image dataset and preprocess it, dividing the preprocessed image dataset into training set, validation set and test set; S200: Constructing an improved model: S210: Construct a backbone network for feature extraction. Embed a convolutional block attention module (CBAM) at the end of the backbone network of the YOLOv5 model. The CBAM performs weighted enhancement on the feature map through a series of channel attention sub-modules and spatial attention sub-modules. S220: Construct a spatial pyramid pooling module SPPF-A at the output of the backbone network for feature pooling, replacing the pyramid pooling module SPPF in the standard YOLOv5 model. S230: Construct a neck network for feature fusion, using the content-aware upsampling module CARAFE to replace the nearest neighbor interpolation upsampling operation in the standard YOLOv5 model; S240: Construct a decoupled detection head for target prediction, which includes a shared feature extraction layer and four independent task branches, replacing the coupled detection head of the standard YOLOv5 model; S300: Train the improved model, initialize the parameters of the improved model, train using the training set, and update the model parameters; S400: Utilizing an improved model for object detection and segmentation.
[0010] As a further limitation of the technical solution of the present invention, in step S210, the channel attention submodule and the spatial attention submodule sequentially execute the following sub-steps: S211: The channel attention submodule performs global average pooling and global max pooling on the input feature map respectively, and inputs the two channel descriptors obtained into a shared multilayer perceptron; S212: The two channel attention feature maps output by the multilayer perceptron are added element by element, and then channel attention weights are generated by Sigmoid activation; S213: Multiply the channel attention weights element-wise with the input feature map to obtain the feature map after channel attention weighting; S214: Calculate the average and maximum values of the feature map after channel attention weighting in the channel dimension to obtain two two-dimensional spatial feature descriptors; S215: Two two-dimensional spatial feature descriptors are concatenated to obtain the concatenated feature map; S216: Spatial attention weights are generated by performing convolution and sigmoid activation on the concatenated feature map. S217: Multiply the spatial attention weights element-wise with the feature map after channel attention weighting to obtain the final enhanced feature map.
[0011] As a further limitation of the technical solution of the present invention, in step S220, the spatial pyramid pooling module SPPF-A includes a 1×1 convolutional dimensionality reduction layer, four cascaded 5×5 max pooling layers and a 1×1 convolutional fusion layer. The Spatial Pyramid Pooling Module SPPF-A performs the following operations: S221: After the enhanced feature map is input, it undergoes channel dimensionality reduction through a 1×1 convolutional dimensionality reduction layer; S222: Pooling operations are performed sequentially through four cascaded 5×5 max pooling layers to obtain the original feature, the first pooling feature, the second pooling feature, the third pooling feature, and the fourth pooling feature, respectively. S223: The first pooling feature and the third pooling feature are concatenated along the channel dimension, and the concatenated feature map is channel-fused through the 1×1 convolutional fusion layer to output the pooling feature map.
[0012] As a further limitation of the technical solution of the present invention, in step S230, the content-aware upsampling module CARAFE includes a kernel prediction submodule and a content-aware reconstruction submodule, wherein: The kernel prediction submodule activates the input pooled feature map through an activation function and predicts the original upsampling kernel through a convolutional layer. Then, it generates the corresponding upsampling kernel by pixel recombination and finally normalizes the upsampling kernel by the Softmax function. The content-aware recombination submodule extracts feature blocks from the neighborhood of each location in the input pooled feature map, and then performs a weighted summation of the upsampling kernel and the corresponding feature blocks to generate new feature values.
[0013] As a further limitation of the technical solution of the present invention, in step S240, the shared feature extraction layer consists of two cascaded 3×3 convolutional layers, and the four task branches are as follows: The regression branch outputs the coordinate offset of the target bounding box; the target degree branch outputs the probability of the target's existence; the classification branch outputs the probability of the target belonging to each category; and the mask coefficient branch outputs the instance segmentation mask coefficients. The decoupled detection head also includes a prototype mask generation submodule, which is used to generate a prototype mask map from the shallow feature map output by the backbone network.
[0014] As a further limitation of the technical solution of the present invention, step S300 specifically includes: S310: YOLOv5m-seg pre-trained weights are used to initialize the parameters of the backbone network and the neck network, and the new parameters of the decoupled detection head are randomly initialized; S320: Perform end-to-end training on the improved YOLOv5 neural network model using the training set, and update the model parameters through the backpropagation algorithm and stochastic gradient descent optimizer.
[0015] As a further limitation of the technical solution of the present invention, step S400 specifically includes: S410: Acquire the image to be detected; S420: Input the image to be detected into the improved model, extract features through the backbone network, and output the enhanced feature map after being enhanced by the convolutional block attention module CBAM. S430: The enhanced feature map is fused by the Spatial Pyramid Pooling Module (SPPF-A) to obtain the pooled feature map; S440: The pooling feature map is obtained by fusing features from the neck network of the improved model. S450: The decoupled detection head performs target prediction on the fused feature map, and outputs the target detection box, class confidence and instance segmentation mask based on the prediction results.
[0016] Compared with the prior art, the present invention has the following advantages: ① By introducing the CBAM attention module into the backbone network, the model's ability to extract fine-grained features is enhanced, enabling it to focus on the target region more accurately in complex backgrounds; ② By designing the SPPF-A spatial pyramid pooling module and adopting a selective feature stitching strategy, the feature representation of targets at extreme scales is enhanced, thereby improving multi-scale detection capabilities while maintaining computational efficiency; ③ By adopting the CARAFE content-aware upsampling module, adaptive recombination of features was achieved, improving the quality of multi-scale feature fusion in the feature pyramid; ④ By adopting a decoupled detection head structure, the competition problem between classification, localization and mask prediction tasks is eliminated, and each task branch can independently learn the optimal features, which significantly improves the detection accuracy; ⑤ By combining the synergistic effects of the four improvement modules, under the premise of controllable growth in the number of model parameters, a comprehensive improvement in detection accuracy and segmentation accuracy has been achieved, which is particularly suitable for fine-grained target recognition tasks in complex scenarios such as forestry and timber processing. ⑥ The method of this invention is based on the YOLOv5 framework, has excellent hardware compatibility, and can run efficiently on low-end embedded computing devices such as Jetson Nano, meeting the deployment needs of forestry field automation equipment. Attached Figure Description
[0017] The present invention can be further illustrated by the non-limiting embodiments given in the accompanying drawings.
[0018] Figure 1 This is a schematic diagram of the overall process of the present invention; Figure 2 This is a schematic diagram of the overall structure of the improved model of the present invention; Figure 3 This is a schematic diagram of the spatial pyramid pooling module SPPF-A of the present invention; Figure 4 This is a schematic diagram of the decoupling detection head of the present invention; Figure 5 A comparison chart of the improved model of this invention and the standard YOLOv5 model; Figure 6 A comparison chart of the improved model of this invention with the standard YOLOv5 model and the individual modules of the standard YOLOv5+; Figure 7 This is a diagram illustrating the actual identification effect of wood according to the present invention. Detailed Implementation
[0019] To enable those skilled in the art to better understand the present invention, the technical solution of the present invention will be further described below in conjunction with the accompanying drawings and embodiments.
[0020] I. The technical solution of this invention is described in detail below: A visual recognition method for forest logs based on an improved YOLOv5 includes the following steps: S100: Obtain the training image dataset and preprocess it, dividing the preprocessed image dataset into training set, validation set and test set; Specifically, preprocessing operations include image size normalization, data augmentation, and other operations.
[0021] S200: Constructing an improved model: S210: Construct a backbone network for feature extraction. Embed a convolutional block attention module (CBAM) at the end of the backbone network of the YOLOv5 model. The CBAM performs weighted enhancement on the feature map through a series of channel attention sub-modules and spatial attention sub-modules. In this step, the channel attention submodule and the spatial attention submodule execute the following sub-steps in sequence: S211: Input feature map is processed by the channel attention submodule. Global average pooling and global max pooling are performed separately, and the resulting two channel descriptors are input into a shared multilayer perceptron. Specifically, the multilayer perceptron consists of two 1×1 convolutional layers. The first convolutional layer compresses the number of channels to 1 / 16 of the original number and activates it using ReLU. The second convolutional layer restores the number of channels to the original number. S212: The two channel attention feature maps output by the multilayer perceptron are added element-wise, and then channel attention weights are generated by sigmoid activation. ; S213: Adjust channel attention weights With input feature map Element-wise multiplication yields the feature map after channel attention weighting. ; S214: Feature map after channel attention weighting The average and maximum values are calculated in the channel dimension to obtain two two-dimensional spatial feature descriptors, each with a size of 1×H×W. S215: Two two-dimensional spatial feature descriptors are concatenated to obtain a concatenated feature map with a size of 2×H×W; S216: The concatenated feature maps are subjected to a convolution operation. The convolution operation maps the concatenated feature maps to a 1×H×W single-channel feature map through a 7×7 convolutional layer, and then generates spatial attention weights after Sigmoid activation. ; S217: Adjust spatial attention weights Feature map after channel attention weighting Element-wise multiplication yields the final enhanced feature map. .
[0022] The benefits of the above improvements are that by using channel attention and spatial attention in series, the Convolutional Block Attention (CBAM) module can simultaneously focus on "what features are meaningful" and "which positions in the feature map are important", effectively enhancing the backbone network's ability to express fine-grained features.
[0023] S220: Construct a spatial pyramid pooling module SPPF-A at the output of the backbone network for feature pooling, replacing the pyramid pooling module SPPF in the standard YOLOv5 model. In this step, the Spatial Pyramid Pooling Module SPPF-A includes a 1×1 convolutional dimensionality reduction layer, four cascaded 5×5 max pooling layers, and a 1×1 convolutional fusion layer. The Spatial Pyramid Pooling Module SPPF-A performs the following operations: S221: Enhanced Feature Map After input, the channel dimensionality is reduced by a 1×1 convolutional dimensionality reduction layer, compressing the number of channels to half of the original. S222: Pooling operations are performed sequentially through four cascaded max pooling layers with a kernel size of 5×5, a stride of 1, and a fill size of 2, to obtain the original feature x, the first pooling feature p1, the second pooling feature p2, the third pooling feature p3, and the fourth pooling feature p4, respectively. S223: Concatenate the first pooling feature p1 and the third pooling feature p3 along the channel dimension, and then perform channel fusion on the concatenated feature map through a 1×1 convolutional fusion layer to output the pooling feature map.
[0024] Therefore, the concatenation strategy in this step is to concatenate the first pooling feature p1 (corresponding to the small-scale receptive field) and the third pooling feature p3 (corresponding to the large-scale receptive field) along the channel dimension, discarding the medium-scale second pooling feature p2 and the fourth pooling feature p4. The advantage of this design is that in actual object detection tasks, target features that are too small or too large are more likely to be ignored, while medium-scale target features can be effectively captured by standard convolutional layers. By selectively focusing on pooling features of extreme scales, the SPPF-A module can enhance the feature representation ability of extremely small and extremely large targets without adding additional parameters.
[0025] S230: Construct a neck network for feature fusion, using the content-aware upsampling module CARAFE to replace the nearest neighbor interpolation upsampling operation in the standard YOLOv5 model; In this step, the content-aware upsampling module CARAFE includes a kernel prediction submodule and a content-aware reconstruction submodule, wherein: The kernel prediction submodule activates the input pooled feature map through an activation function and predicts the original upsampling kernel through a convolutional layer. Then, it generates the corresponding upsampling kernel by pixel recombination and finally normalizes the upsampling kernel by the Softmax function. Specifically, the kernel prediction submodule compresses the input pooled feature map to a preset intermediate number of channels (e.g., the preset number of channels is 64) through a 1×1 convolution, activates it with the SiLU activation function, and then predicts the original upsampled kernel through a 1×1 convolutional layer. The size of the original upsampled kernel is (scale×k_up). 2 ×H×W, where scale is the upsampling factor (default is 2x), k_up is the upsampling kernel size (default is 5×5), H and W are the height and width of the input feature map; the original upsampling kernel size is transformed to k_up through pixel recombination. 2 ×H×scale×W×scale, so that each target location (a total of H×scale×W×scale) corresponds to a k_up×k_up upsampling kernel; finally, the Softmax function is applied in the channel dimension to normalize each upsampling kernel to ensure that the sum of the kernel weights is 1; The content-aware recombination submodule extracts feature blocks from the neighborhood of each location in the input pooled feature map, and then performs a weighted summation of the upsampling kernel and the corresponding feature blocks to generate new feature values; Specifically, the content-aware recombination submodule extracts the k_up×k_up neighborhood feature blocks around each position from the input pooled feature map using a sliding window approach. Then, it performs a weighted summation of the upsampled kernel predicted by the kernel prediction submodule with the corresponding feature blocks to generate a new feature value for each target position. It should be noted that for position (i,j) in the feature map, its upsampled scale×scale target positions share the feature blocks of the neighborhood of the input position, but each target position uses a different upsampled kernel weight, thereby achieving content-aware upsampling.
[0026] Compared with traditional nearest neighbor interpolation and bilinear interpolation, the above improvements include dynamic generation of the upsampling kernel based on the feature map content, which is adaptive; the receptive field of the upsampling kernel is larger (k_up×k_up), which can utilize a wider range of contextual information; and the number of computational parameters is small, resulting in low overhead.
[0027] S240: Construct a decoupled detection head for target prediction, which includes a shared feature extraction layer and four independent task branches, replacing the coupled detection head of the standard YOLOv5 model; In this step, the shared feature extraction layer consists of two cascaded 3×3 convolutional layers with the same number of input and output channels, used to extract shared deep features before three independent branches; The four task branches are as follows: The regression branch outputs the coordinate offset of the target bounding box (center x, center y, width w, height h) through a 1×1 convolutional layer, with na×4 output channels, where na is the preset number of anchor points for each detection layer (the default is 3). The target degree branch outputs the target existence probability through a 1×1 convolutional layer, with na×1 output channels; The classification branch outputs the probability of the target belonging to each category through a 1×1 convolutional layer, with the number of output channels being na×nc, where nc is the total number of categories; The mask coefficient branch splits the mask coefficients through the output instance of a 1×1 convolutional layer, with the number of output channels being na×nm, where nm is the dimension of the mask coefficients (the default value is 32). The decoupled detection head also includes a prototype mask generation submodule, which performs multiple convolutions and upsampling operations on the shallow feature map output by the backbone network to generate a prototype mask map corresponding to the size of the input image. It should be noted that during the training of the improved model, the prototype mask map is linearly combined with the mask coefficients output by the mask coefficient branch to generate the final instance segmentation mask.
[0028] The improvement mentioned above is that the decoupled detection head assigns classification, localization, and mask prediction tasks to independent network branches, avoiding the problem of different tasks competing for the same set of features in the standard YOLOv5 coupled detection head. This allows each task branch to focus on learning the feature representation it needs, thereby improving the overall detection accuracy.
[0029] S300: Train the improved model, initialize the parameters of the improved model, train using the training set, and update the model parameters; This step specifically includes: S310: YOLOv5m-seg pre-trained weights are used to initialize the parameters of the backbone network and the neck network, and the new parameters of the decoupled detection head are randomly initialized; S320: The improved YOLOv5 neural network model is trained end-to-end using the training set. It integrates bounding box regression loss, target degree loss, classification loss and segmentation mask loss, and updates the model parameters through backpropagation algorithm and stochastic gradient descent optimizer.
[0030] S400: Target detection and segmentation using an improved model; This step specifically includes: S410: Acquire the image to be detected; S420: Input the image to be detected into the improved model, extract features through the backbone network, and output the enhanced feature map after being enhanced by the convolutional block attention module CBAM. S430: The enhanced feature map is fused by the Spatial Pyramid Pooling Module (SPPF-A) to obtain the pooled feature map; S440: The pooling feature map is obtained by fusing features from the neck network of the improved model. S450: The decoupled detection head performs target prediction on the fused feature map, and outputs the target detection box, class confidence and instance segmentation mask based on the prediction results.
[0031] The software modules in the technical solution of this invention are all implemented based on the PyTorch deep learning framework, with a running environment of Python 3.10 and CUDA 11.8, and a hardware platform of NVIDIA GeForce RTX 3070 GPU. The source code of all improved modules is compatible with the standard interface of the YOLOv5 project and can be directly embedded into the existing YOLOv5 training and inference process.
[0032] II. Implementation examples based on the above technical solution are as follows: Example 1: This embodiment uses visual inspection of logs in forestry timber processing as an application scenario, and uses the TimberVision dataset to verify the method of the present invention.
[0033] 1. Forestry Scenarios and Datasets The TimberVision dataset is a professional dataset for forestry automation vision tasks, containing 1203 training images, 259 validation images, and 260 test images. All images were captured from real timber processing line environments, covering various lighting conditions, shooting angles, and timber species, demonstrating high scene complexity and robustness. The image size has been uniformly adjusted to 640×640 pixels.
[0034] The dataset labels four target classes: cut (the saw marks on the cross-section of the log), bark edge (the area of bark not completely removed from the log surface), side of the board (the texture of the exposed side of the wood after processing), and trunk (the complete outer surface of the log). Each target class is provided with both bounding box annotations and instance segmentation mask annotations, which can be used to train a deep learning model that simultaneously outputs detection boxes and segmentation masks.
[0035] 2. Basic configuration of the improved model in this embodiment: The improved YOLOv5 network model uses YOLOv5m as its infrastructure, with the following specific configuration: Input image size: 640×640×3; Backbone network depth multiplier: 0.67 (corresponding to m model); Backbone network width multiple: 0.75 (corresponding to m model); Anchor points: There are a total of 9 anchor points, distributed across 3 detection layers, with 3 anchor points per layer; CBAM module channel compression ratio: 16; SPPF-A pooling core size: 5×5; CARAFE upsampling kernel size: 5×5, number of intermediate channels: 64; Decoupling detection head mask coefficient dimension: 32.
[0036] 3. Improve the training parameter configuration of the model. Pre-trained weights: YOLOv5m-seg; Optimizer: SGD (Stochastic Gradient Descent); Initial learning rate: 0.01; Momentum: 0.937; Weight decay: 0.0005; Batch size: 4; Number of training rounds: 100; Learning rate decay: cosine annealing strategy; Data augmentation: mosaic enhancement, random scaling, random flipping, color dithering, etc.
[0037] 4. Experimental Results: like Figure 5 As shown in the charts, experimental results on the TimberVision dataset demonstrate that the improved model of this invention achieves a significant improvement compared to the standard YOLOv5m model. like Figure 6 As shown in the charts, compared with the standard YOLOv5 model and individual modules of the standard YOLOv5+, the improved model of this invention shows that the CBAM attention module, SPPF-A module, CARAFE upsampling module, and decoupled detection head each contribute to the accuracy improvement. Moreover, the synergistic effect of the four improvements is better than the sum of individual improvements. The improvement in detection accuracy of the model is mainly reflected in the following aspects: ① Improved recall rate for detecting small targets; ② Improved positioning accuracy for occluded targets; ③ Improved edge quality of segmentation mask.
[0038] The above embodiments are merely illustrative of the principles and effects of the present invention and are not intended to limit the invention. Any person skilled in the art can modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by those skilled in the art without departing from the spirit and technical concept disclosed in the present invention should still be covered by the claims of the present invention.
Claims
1. A visual recognition method for forest logs based on an improved YOLOv5, characterized in that: Includes the following steps: S100: Obtain the training image dataset and preprocess it, dividing the preprocessed image dataset into training set, validation set and test set; S200: Constructing an improved model: S210: Construct a backbone network for feature extraction. Embed a convolutional block attention module (CBAM) at the end of the backbone network of the YOLOv5 model. The CBAM performs weighted enhancement on the feature map through a series of channel attention sub-modules and spatial attention sub-modules. S220: Construct a spatial pyramid pooling module SPPF-A at the output of the backbone network for feature pooling, replacing the pyramid pooling module SPPF in the standard YOLOv5 model. S230: Construct a neck network for feature fusion, using the content-aware upsampling module CARAFE to replace the nearest neighbor interpolation upsampling operation in the standard YOLOv5 model; S240: Construct a decoupled detection head for target prediction, which includes a shared feature extraction layer and four independent task branches, replacing the coupled detection head of the standard YOLOv5 model; S300: Train the improved model, initialize the parameters of the improved model, train using the training set, and update the model parameters; S400: Utilizing an improved model for object detection and segmentation.
2. The visual recognition method according to claim 1, characterized in that: In step S210, the channel attention submodule and the spatial attention submodule sequentially execute the following sub-steps: S211: The channel attention submodule performs global average pooling and global max pooling on the input feature map respectively, and inputs the two channel descriptors obtained into a shared multilayer perceptron; S212: The two channel attention feature maps output by the multilayer perceptron are added element by element, and then channel attention weights are generated by Sigmoid activation; S213: Multiply the channel attention weights element-wise with the input feature map to obtain the feature map after channel attention weighting; S214: Calculate the average and maximum values of the feature map after channel attention weighting in the channel dimension to obtain two two-dimensional spatial feature descriptors; S215: Two two-dimensional spatial feature descriptors are concatenated to obtain the concatenated feature map; S216: Spatial attention weights are generated by performing convolution and sigmoid activation on the concatenated feature map. S217: Multiply the spatial attention weights element-wise with the feature map after channel attention weighting to obtain the final enhanced feature map.
3. The visual recognition method according to claim 2, characterized in that: In step S220, the Spatial Pyramid Pooling Module SPPF-A includes a 1×1 convolutional dimensionality reduction layer, four cascaded 5×5 max pooling layers, and a 1×1 convolutional fusion layer. The Spatial Pyramid Pooling Module SPPF-A performs the following operations: S221: After the enhanced feature map is input, it undergoes channel dimensionality reduction through a 1×1 convolutional dimensionality reduction layer; S222: Pooling operations are performed sequentially through four cascaded 5×5 max pooling layers to obtain the original feature, the first pooling feature, the second pooling feature, the third pooling feature, and the fourth pooling feature, respectively. S223: The first pooling feature and the third pooling feature are concatenated along the channel dimension, and the concatenated feature map is channel fused through the 1×1 convolutional fusion layer to output the pooling feature map.
4. The visual recognition method according to claim 3, characterized in that: In step S230, the content-aware upsampling module CARAFE includes a kernel prediction submodule and a content-aware reconstruction submodule, wherein: The kernel prediction submodule activates the input pooled feature map through an activation function and predicts the original upsampling kernel through a convolutional layer. Then, it generates the corresponding upsampling kernel by pixel recombination and finally normalizes the upsampling kernel by the Softmax function. The content-aware recombination submodule extracts feature blocks from the neighborhood of each location in the input pooled feature map, and then performs a weighted summation of the upsampling kernel and the corresponding feature blocks to generate new feature values.
5. The visual recognition method according to claim 4, characterized in that: In step S240, the shared feature extraction layer consists of two cascaded 3×3 convolutional layers, and the four task branches are as follows: The regression branch is used to output the coordinate offset of the target bounding box; The target degree branch is used to output the probability of the target's existence. Classification branches are used to output the probability that the target belongs to each category; The mask coefficient branch is used to output instance segmentation mask coefficients; The decoupled detection head also includes a prototype mask generation submodule, which is used to generate a prototype mask map from the shallow feature map output by the backbone network.
6. The visual recognition method according to claim 5, characterized in that: Step S300 specifically includes: S310: YOLOv5m-seg pre-trained weights are used to initialize the parameters of the backbone network and the neck network, and the new parameters of the decoupled detection head are randomly initialized; S320: Perform end-to-end training on the improved YOLOv5 neural network model using the training set, and update the model parameters through the backpropagation algorithm and stochastic gradient descent optimizer.
7. The visual recognition method according to claim 6, characterized in that: Step S400 specifically includes: S410: Acquire the image to be detected; S420: Input the image to be detected into the improved model, extract features through the backbone network, and output the enhanced feature map after being enhanced by the convolutional block attention module CBAM. S430: The enhanced feature map is fused by the Spatial Pyramid Pooling Module (SPPF-A) to obtain the pooled feature map; S440: The pooling feature map is obtained by fusing features from the neck network of the improved model. S450: The decoupled detection head performs target prediction on the fused feature map, and outputs the target detection box, class confidence and instance segmentation mask based on the prediction results.
