Log counting method based on yolov9-unet in complex environment

By combining Transformer and UNet to form a Trans-UNet module for image restoration and object detection, the problem of insufficient log counting accuracy in complex environments is solved, and the end-to-end tasks of high-quality image restoration and log counting are achieved, thereby improving counting accuracy.

CN119599963BActive Publication Date: 2025-10-10CHONGQING UNIV OF POSTS & TELECOMM +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411633754.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-15
Publication Date
2025-10-10
Estimated Expiration
2044-11-15

AI Technical Summary

Technical Problem

Existing deep learning methods lack accuracy in log counting in complex environments, especially in outdoor environments such as docks and forests. Due to aging cameras, changes in lighting, and noise, image quality deteriorates, affecting counting accuracy.

Method used

The Transformer and UNet are combined to form the Trans-UNet module for image restoration, which is then combined with Yolov9 to form the Yolov9-UNet model. Through alternating training to optimize image quality and perform object detection, end-to-end log counting is achieved.

Benefits of technology

The log image quality and counting accuracy are significantly improved in complex environments, especially maintaining high robustness in different lighting, noise and raindrop environments, and the counting accuracy is increased to more than 90%.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119599963B_ABST
    Figure CN119599963B_ABST
Patent Text Reader

Abstract

The present application relates to a kind of complex environment based on Yolov9-UNet's log counting method, belong to image processing technical field.The method includes: embedding Transformer into UNet, form Trans-UNet module;Trans-UNet module is combined with Yolov9, form Yolov9-UNet model;Training data is collected to train Yolov9-UNet model, reference GAN network's training process, Trans-UNet module and Yolov9 are trained respectively;Image containing log end face is collected and is normalized, the image of normalized processing is input into trained Yolov9-UNet model, obtains log detection frame, and the number of log is obtained by counting detection frame.The present application can realize the effective recovery of image in different scenes, realize log counting in complex environment.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of image processing, and relates to restoration of log images in complex environments and a method for counting logs based on the restored images. Background Art

[0002] With the continued growth of global demand for timber resources, accurate log counting has become a critical issue in forest management and the timber industry. Traditional manual counting methods are not only inefficient but also susceptible to human error, resulting in inaccurate results. Due to the rise of deep learning and its widespread application in computer vision tasks, the use of image processing and deep learning techniques to automatically count logs has become a hot topic of research.

[0003] Currently, log counting methods are mainly divided into two categories: traditional counting methods and deep learning counting methods.

[0004] (1) Traditional counting methods mainly rely on image processing and traditional machine learning techniques to count logs. These methods are generally divided into three categories: edge detection-based counting methods, morphological analysis-based counting methods, and feature extraction-based counting methods. The basic principles and shortcomings of these methods are briefly described as follows:

[0005] 1) Edge detection-based counting methods primarily use edge detection algorithms, such as the Canny operator, to identify log boundaries. High-pass filters are then used to remove background noise, enhance log outlines, and extract clear edge information. Finally, a Hough transform is used to detect lines and determine the length and number of logs. This method performs well with simple backgrounds, but accuracy is significantly affected in complex backgrounds and with overlapping logs.

[0006] Morphological analysis is based on the geometric shape of logs. Morphological operations (such as dilation, erosion, opening, and closing) are typically used to effectively separate overlapping logs and identify their shape features. Machine learning regression models are then used for counting. This method is computationally efficient and suitable for processing large amounts of logs. However, variations in lighting and wood size can lead to reduced recognition rates, thus affecting counting accuracy.

[0007] 3) Feature extraction methods focus on quantifying the color, texture, and shape characteristics of logs. By extracting local features (such as HOG features and LBP features) and combining them with machine learning algorithms (such as SVM or KNN), log classification and counting can be achieved. This method has the advantage of being robust across various environments, but model training requires a large number of labeled samples.

[0008] (2) Deep learning technology mainly focuses on the characteristics of wood by constructing convolutional neural networks (CNNs). Currently, the most widely used deep learning counting method is to use the Yolo series of models to perform multi-target detection on logs, and then calculate the number of logs based on the number of detections. Compared with pure image processing methods, deep learning models can improve counting accuracy in complex scenarios and reduce reliance on manual parameter adjustment.

[0009] Although deep learning-based log counting methods have significantly improved accuracy compared to traditional algorithms, particularly for high-quality images, the accuracy of log counting using current deep learning methods in complex real-world environments still needs to be improved. For example, in outdoor environments such as docks and forestry farms, images of logs captured by older cameras often contain significant noise. Furthermore, lighting intensity, rain, and fog can also affect the quality of captured log images, thereby impacting log counting accuracy. Currently, existing deep learning technologies and methods are not adequately addressing these challenges. Summary of the Invention

[0010] In view of this, the purpose of the present invention is to provide a log counting method based on Yolov9-UNet in complex environments. By combining UNet and Transformer to form a Trans-UNet module, the original log image is restored to improve its image quality. Then, Yolov9 is used to perform target detection on the restored image, so as to achieve the purpose of improving the log counting accuracy of low-quality real images.

[0011] In order to achieve the above object, the present invention provides the following technical solutions:

[0012] A log counting method based on Yolov9-UNet in a complex environment, the method includes:

[0013] S1. Embed Transformer into UNet to form a Trans-UNet module; combine the Trans-UNet module with Yolov9 to form a Yolov9-UNet model;

[0014] S2. Collect training data to train the Yolov9-UNet model. During the training process, first train the Trans-UNet module while freezing the Yolov9 parameters. After the Trans-UNet module is trained, freeze the Trans-UNet module parameters and use the Trans-UNet output images to train Yolov9.

[0015] S3. Collect an image containing the end face of the log and perform normalization processing. Input the normalized image into the trained Yolov9-UNet model to obtain the log detection frame, and count the detection frame to obtain the number of logs.

[0016] Furthermore, in step S1, a Transformer is embedded into the UNet to form a Trans-UNet module; wherein, a Transformer is connected between the convolution blocks of the UNet encoder and decoder, specifically, the corresponding convolution blocks in the UNet U-shaped structure are connected by a Transformer; at the same time, a Transformer is embedded between the convolution blocks in the UNet encoder, and a Transformer is embedded between the convolution blocks in the UNet decoder.

[0017] Furthermore, in step S2, the training process of the Yolov9-UNet model includes: first collecting image training data and normalizing the size of the image training data through opencv; then freezing the parameters of Yolov9, inputting the normalized image training data into the Trans-UNet module for training, and optimizing the parameters of the Trans-UNet module through the loss function; then inputting the image data optimized by the Trans-UNet module into Yolov9, freezing the parameters of the Trans-UNet module, training Yolov9, and adjusting the parameters of Yolov9 through the loss function.

[0018] Among them, during the training process of the Yolov9-UNet model, it is necessary to alternately train the Trans-UNet module and Yolov9, and optimize the parameters through their respective loss functions during the training process, so that the loss values ​​of the Trans-UNet module and Yolov9 are minimized, thereby completing the training.

[0019] Furthermore, in step S3, the process of counting logs using the Yolov9-UNet model includes: collecting images containing the end faces of logs, normalizing the images using OpenCV, and inputting the normalized images into the trained Yolov9-UNet model; first optimizing the images using the Trans-UNet module to improve image quality; then performing target detection on the optimized images using Yolov9 to obtain detection frames of the logs in the image, and obtaining the number of logs after counting the detection frames.

[0020] The beneficial effects of the present invention are as follows: Based on the excellent feature extraction capabilities of Transformer and the excellent image generation capabilities of UNet, the present invention combines the two to form a Trans-UNet module. The module uses the important feature information in the complex environment image learned during the downsampling stage to guide the generation of high-quality log images. This module can effectively restore images with different lighting conditions, noisy images, and rain-blurred images. In addition, the present invention uses the concept of alternating learning to cross-train Trans-UNet and Yolov9, achieving an end-to-end task that combines image restoration and object detection, allowing Yolov9-UNet to effectively perform log counting in complex environments.

[0021] Other advantages, objects, and features of the present invention will be described in part in the following description and, in part, will be apparent to those skilled in the art upon examination of the following description or may be learned from practice of the present invention. The objects and other advantages of the present invention may be realized and obtained through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] In order to make the purpose, technical solutions and advantages of the present invention more clear, the present invention will be described in detail below with reference to the accompanying drawings, in which:

[0023] Figure 1 This is a flow chart of a log counting method according to an embodiment of the present invention;

[0024] Figure 2 This is a schematic diagram of the structure of the Yolov9-UNet module;

[0025] Figure 3 This is a structural diagram of the Trans-UNet module;

[0026] Figure 4 This is the image restoration effect of the Trans-UNet module;

[0027] Figure 5 The following is a comparison chart of log testing results using various methods under different environments. DETAILED DESCRIPTION

[0028] The following describes the embodiments of the present invention by means of specific examples, and those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present invention, and the following embodiments and features in the embodiments can be combined with each other without conflict.

[0029] This paper addresses the problem of low-quality log images captured by cameras in complex outdoor environments such as docks and forestry farms, which affects the accuracy of log counting. This paper proposes a log counting method based on a combination of Yolov9, UNet, and Transformer. This method first combines UNet with Transformer to form a Trans-UNet module to restore the original log images to improve their image quality. Yolov9 is then used to perform object detection on the restored images, ultimately achieving the goal of improving log counting accuracy in low-quality real-world images.

[0030] See also Figures 1 to 3 An embodiment of the present invention provides a log counting method based on Yolov9-UNet in a complex environment. The method is specifically as follows:

[0031] 1. First, the Transformer and UNet are combined to form a Trans-UNet module. This module is used to restore images of log piles collected in complex environments to improve image quality and facilitate subsequent log detection, identification, and counting.

[0032] UNet's downsampling primarily extracts image features, and upsampling then restores the extracted features. However, if the image contains significant noise, downsampling alone will cause the model to interpret the noise as crucial information, leading to the loss of this important information. Therefore, adding the Transformer allows the downsampling process to consider both global and local information, preserving the image's essential information. Based on the improved downsampling structure described above and the UNet architecture, the upsampling process is implemented in the same manner. Furthermore, UNet's original skip connections ensure that the restored image contains information from the original image. However, due to the significant noise content of the original image, direct skip connections could introduce noise during the upsampling process. By introducing the Transformer, however, it is possible to extract key image features and, to a limited extent, avoid the introduction of noise. Therefore, the introduction of the Transformer allows the improved UNet to effectively extract important image features while removing noise and other redundant information, resulting in a higher-quality restored image.

[0033] Based on the above principles, in this embodiment, the Transformer is embedded into the UNet network to form Figure 3 The Trans-UNet module shown in the figure embeds Transformers in both the encoder and decoder of the UNet network, and also between each feature extraction layer (convolutional block) of the encoder and decoder. The Transformer simultaneously considers both global and local information, resulting in better image denoising results compared to simply using convolutional blocks for denoising.

[0034] 2. After the Trans-UNet module is built, it is combined with Yolov9 to obtain the following Figure 2 The Yolov9-UNet model shown is used to detect and count logs.

[0035] 3. Prepare training data for training the constructed Trans-UNet module. During the training process, you need to freeze the parameters of Yolov9 and train the Trans-UNet module separately.

[0036] In this embodiment, since the labeled log dataset is relatively small, a public steel bar detection dataset is used for training, and the log dataset is used for verification after the training is completed.

[0037] During the training phase of the Trans-UNet module, the original rebar image is first input and its size is normalized using OpenCV. After freezing the Yolov9 parameters, the normalized images are batch-fed into the Trans-UNet module for training, and the Trans-UNet parameters are optimized according to their corresponding loss function, where the loss function is shown in the following formula:

[0038]

[0039] 4. Use the log end image restored by the Trans-UNet module to train Yolov9.

[0040] After the Trans-UNet module data is verified, the log end face image is collected and input into Trans-UNet to obtain the restored image. Use together Train Yolov9 and fine-tune its parameters based on Yolov9's object detection loss.

[0041] It should be noted that during the Yolov9 training process, the Trans-UNet parameters also need to be frozen.

[0042] After Yolov9 training is completed, it is tested using test data.

[0043] 5. Collect images containing log ends in the work scene and input them into the Yolov9-UNet model for log counting.

[0044] The user collects images containing log end faces in the work scene and uses OpenCV to normalize the image size. The normalized image is fed into the Yolov9-UNet model to obtain target detection results. The target detection frames are counted to determine the number of logs.

[0045] Among them, the image quality improvement effect of the Yolov9-UNet model is as follows: Figure 4 As shown, from Figure 4 It can be seen that for log images with different light intensities, noise, and raindrops, the Trans-UNet model proposed in this invention can effectively restore the original images. That is, the Trans-UNet model can greatly improve the image quality of log images in complex scenes.

[0046] In another embodiment of the present invention, the Yolov9-UNet model is used to compare the detection effects with several mainstream Yolo models. Figure 5 As can be seen from Table 1, for high-quality images, both the yolo series and Yolov9-UNet can achieve high-precision detection and counting, but in complex environments (such as illumination enhancement and reduction, noise and raindrops), the detection and counting accuracy of the yolo series will decrease. The Yolov9-UNet proposed in the present invention has better robustness for different complex environments, and the detection and counting accuracy of logs is higher (more than 90%). It can be seen that the Yolov9-UNet proposed in the present invention is more suitable for log detection and counting tasks in real complex environments.

[0047] Table 1

[0048]

[0049]

[0050] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not limiting. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present invention can be modified or replaced by equivalents without departing from the purpose and scope of the technical solutions, which should all be included in the scope of the claims of the present invention.

Claims

1. A log counting method based on Yolov9-UNet in complex environments, characterized by: Embed the Transformer into the UNet to form a Trans-UNet module, where the Transformer is connected between the convolution blocks of the UNet encoder and decoder, and between the convolution blocks in the UNet encoder and decoder, respectively. Combine the Transformer into Yolov9 to form a Yolov9-UNet model. Collecting training data to train the Yolov9-UNet model; during the training process, first training the Trans-UNet module while freezing the Yolov9 parameters; after the Trans-UNet module is trained, using the images output by the Trans-UNet while freezing the Trans-UNet module parameters; An image containing the end face of a log is collected and normalized, and the normalized image is input into the trained Yolov9-UNet model to obtain a log detection frame, and the detection frame is counted to obtain the number of logs.

2. The log counting method according to claim 1, characterized in that: The training process of the Yolov9-UNet model includes: first collecting image training data and normalizing the size of the image training data through OpenCV; then freezing the parameters of Yolov9, inputting the normalized image training data into the Trans-UNet module for training, and optimizing the parameters of the Trans-UNet module through the loss function; then inputting the image data optimized by the Trans-UNet module into Yolov9, freezing the parameters of the Trans-UNet module, training Yolov9, and adjusting the parameters of Yolov9 through the loss function.

3. The log counting method according to claim 1 or 2, characterized in that: During the training process of the Yolov9-UNet model, it is necessary to alternately train the Trans-UNet module and the Yolov9 module, and optimize the parameters through their respective loss functions during the training process, so that the loss values ​​of the Trans-UNet module and Yolov9 are minimized and the training is completed.

4. The log counting method according to claim 1, characterized in that: The process of counting logs using the Yolov9-UNet model includes: collecting an image containing the end face of the log, normalizing the image using OpenCV, and inputting the normalized image into the trained Yolov9-UNet model; first optimizing the image using the Trans-UNet module to improve the image quality; then performing target detection on the optimized image using Yolov9 to obtain a detection frame of the logs in the image, and obtaining the number of logs after counting the detection frame.

Citation Information

Patent Citations

  • Reinforcing steel bar model training method and device based on convolutional neural network

    CN113344877A

  • System and method for detecting nodules in living tissue

    CN113647987A