CN-121982687-A - Lightweight garbage detection method and system based on improved YOLOv s model
Abstract
The invention discloses a lightweight garbage detection method and system based on an improved YOLOv S model, the detection method comprises the following steps of S1, utilizing a monocular camera to obtain road RGB image data, S2, cutting the acquired image data, cutting the upper half part of a road image, retaining key information related to a ground area below the image, S3, calling an improved YOLOv S network model, inputting the preprocessed image into the network model, then starting a detection code to perform image reasoning detection, and drawing a detection result on the image to obtain result image data containing garbage bounding box coordinates, garbage categories and detection confidence information. The method can efficiently and cost-effectively detect and identify the garbage in complex environments such as urban roads, green belts, community scenes and the like in real time, and particularly has excellent detection performance on small-size target garbage.
Inventors
- WU ENGUANG
- CHEN ZEYU
- WANG HONGHUI
Assignees
- 城市之光(深圳)无人驾驶有限公司
Dates
- Publication Date
- 20260505
- Application Date
- 20251219
Claims (10)
- 1. The lightweight garbage detection method based on the improved YOLOv s model is characterized by comprising the following steps of: step S1, only a monocular camera is adopted, the monocular camera is installed on a vehicle to shoot, and road RGB image data are obtained by the monocular camera; S2, cutting the acquired road RGB image data, cutting the upper half part of the road RGB image, and reserving key information related to a ground area below the image; And step S3, calling an improved YOLOv S network model, inputting the image preprocessed in the step S2 into the network model, starting a detection code to perform image reasoning detection, and drawing a detection result on the image to obtain result image data containing garbage boundary frame coordinates, garbage categories and detection confidence information.
- 2. The lightweight garbage detection method based on the improved YOLOv S model as claimed in claim 1, wherein in the step S1, the monocular camera is installed at an on-vehicle installation position with a height of 1.4-1.6m from the ground and a pitch angle of 25-35 degrees so as to focus a camera view on the ground area, and the non-ground false detection area is automatically filtered through space geometric constraint optimization based on the height and pitch angle installation parameters of the camera, wherein the automatic filtering process based on the space geometric constraint optimization is as follows: step S11, establishing a conversion relation between a camera coordinate system and a world coordinate system; Step S12, calculating the distance of the acquired road RGB image data in a world coordinate system according to the vertical pixel coordinates of the camera detection frame; step S13, setting the maximum height of garbage to be generally smaller than 0.5m based on priori knowledge, so as to set a space effective area; and S14, filtering the detection frames beyond the ground projection range, and reserving the detection frames within the ground projection range.
- 3. The method for lightweight garbage detection based on the modified YOLOv S model as claimed in claim 1, wherein in step S2, the resolution of the original image acquired by the camera is 1920×1080, the image is cut, only half of the image area is reserved, and the resolution of the specific image is 1920×576, so as to focus on the ground area where garbage is likely to appear.
- 4. The method for detecting lightweight garbage based on the improved YOLOv S model as claimed in claim 1, wherein in step S2, the original image and the label are cut by adopting a function of cutting the COCO format dataset, and a new cut dataset is generated and stored, and the specific processing procedure is as follows: S21, loading and batch processing a plurality of COCO format annotation files, and creating a new COCO dictionary for storing the cropped annotation information, including image ID and image size; s22, calculating a cutting area of each image, cutting and storing each image by taking a fixed horizontal centering and vertical cutting height from the top to the bottom as a cutting reference, and storing the cut image to a designated position; And S23, updating the size information of the cut image, updating the coordinates of the boundary frame of the original labels of all the images through a get_crop_box function according to the cutting offset, enabling the coordinates to be aligned with the cut image, and finally generating the cut image and the corresponding COCO label file.
- 5. The lightweight garbage detection method based on the improved YOLOv S model as claimed in claim 1, wherein in step S3, the image inference detection process is as follows: Step S31, loading an improved YOLOv S network model, wherein the input parameters comprise an image path, an image size, a confidence threshold, an IOU threshold, whether half precision and equipment are used or not, and then carrying out garbage identification detection on the images obtained in the step S2 in batches to obtain a garbage identification prediction result contained in each image; step S32, reading each image by using OpenCV, and extracting data of each garbage detection from the prediction result in step S31, wherein the data comprise garbage boundary box coordinates (x, y, w, h), confidence and category ID; Step S33, according to the width and the height of each garbage, a labeling frame of each garbage is correspondingly and directly drawn on the current image, a class ID is used for obtaining the class name of each garbage, and the label information of the class name and the confidence information of the garbage is marked on the labeling frame by combining the confidence score; And step S34, outputting a result image containing coordinates of the garbage bounding box, garbage categories and detection confidence information by the final model, and storing the result image to a specified position.
- 6. The lightweight garbage detection method based on the improved YOLOv S model according to claim 5, wherein in step S31, different confidence thresholds are set for different garbage categories, the garbage categories are plastic/metal, the confidence threshold is 0.75, the garbage categories are glass/paper, the confidence threshold is 0.70, the garbage categories are perishable garbage, the confidence threshold is 0.65, the garbage categories are other garbage, the confidence threshold is 0.68, the garbage categories are cigarette ends, the confidence threshold is 0.7, the garbage categories are bottle caps, and the confidence threshold is 0.7.
- 7. The lightweight garbage detection method based on the modified YOLOv S model as claimed in claim 1, wherein in step S32, each class ID corresponds to a garbage class name, and the garbage class name includes plastic, paper, glass, metal, perishable garbage, cigarette ends, bottle caps, and other eight classes.
- 8. The lightweight garbage detection method based on the modified YOLOv S model as claimed in claim 1, wherein in step S3, the modified YOLOv S network model is constructed and trained as follows: S301, carrying out architecture improvement based on an original YOLOv S network, wherein the architecture improvement comprises the following two core modules, namely reconstructing a high-resolution detection head, adjusting the sampling multiplying power of a feature map level used for final prediction in the original detection network from 16 times of downsampling to 8 times of downsampling, introducing a channel attention feature fusion module CAM at a key level of the original feature fusion network, inputting adaptive data, configuring training parameters, wherein the training parameters comprise a AdamW optimizer, setting an initial learning rate to be 3e-4, adopting a cosine annealing learning rate scheduling strategy, increasing a focusing loss weight aiming at a small target by a loss function on the basis of original positioning and classification loss, setting Batch Size (Batch Size) to be 32, and setting total training round Epoch to be 100; S302, starting model training, generating a new weight file after training is finished, and storing the result in a designated directory.
- 9. The lightweight garbage detection method based on the improved YOLOv S model as claimed in claim 1, further comprising step S4 of uploading the result image data obtained in step S3 to a cloud, wherein the processing procedure includes the following steps: Step 41, preparing uploading data and server information, namely defining a local image file path to be uploaded and designating an uploading interface URL of a cloud server; Step S42, a local image file is opened, a POST request containing the file is sent to a server, network connection is established, and data are transmitted; and step 43, receiving an HTTP response returned by the server, and outputting success prompt information if the status code is successful, wherein the success prompt information indicates that the picture is successfully uploaded to the cloud.
- 10. A lightweight garbage detection system based on an improved YOLOv s model is characterized by comprising a monocular camera and a controller, wherein, The monocular camera is used for acquiring RGB original images of the front lane; The controller comprises an image preprocessing module, a target detection module and a post-processing optimization module, wherein the image preprocessing module is used for performing ground area perception clipping on an original image, clipping the image with the original resolution of 1920×1080 into 1920×576 and only keeping the lower half area of the image, the target detection module is used for performing garbage target detection on the clipped image based on an improved YOLOv s model and outputting boundary frame coordinates, confidence and garbage category probability, and the post-processing optimization module is used for performing geometric constraint optimization based on camera installation parameters, filtering non-ground area false detection targets and performing dynamic confidence threshold adjustment on different garbage categories.
Description
Lightweight garbage detection method and system based on improved YOLOv s model Technical Field The invention relates to the technical field of garbage detection in intelligent sanitation systems, in particular to a lightweight garbage detection method and system based on an improved YOLOv s model, which can be applied to scenes such as automatic driving sanitation vehicles and intelligent garbage cans. Background Traditional garbage detection methods mainly rely on high-precision sensors (such as multispectral cameras and laser radars) or adopt a two-stage detection strategy. The scheme based on the multispectral camera generally utilizes infrared or visible light images to directly identify garbage targets through a deep learning model, and the two-stage method detects a 2D bounding box of garbage first and then further judges garbage types and space positions through a classification network or geometric analysis. However, these methods have the following limitations in practical applications: 1. The dependence on high-cost sensors is that the multispectral cameras and the laser radars can provide abundant environmental information, but the equipment cost is high, and the multispectral cameras and the laser radars are easily influenced by weather conditions (such as rain, snow and haze), so that the data quality is reduced. Moreover, the large-scale deployment costs of such sensors limit their popularity in urban sanitation systems. 2. The two-stage method needs to run the target detection model first, and then refines the result through classification or 3D reasoning network, so that the calculation delay is higher (generally >200 ms/frame), and the real-time response requirement of <50ms is difficult to realize. Meanwhile, the multi-stage series connection may accumulate errors, reducing the detection accuracy. 3. The system complexity is high, the multi-sensor fusion scheme is used for solving the problems of data synchronization, calibration and cross-mode alignment, and the engineering maintenance difficulty is increased. While deep learning-based models are sensitive to training data distribution, and have limited generalization ability in different scenarios (e.g., city streets, highways, parks). 4. The detection performance of the small target is poor, and for small-size garbage (the image ratio is less than 5%) such as cigarette ends and bottle caps, the omission rate of the existing method is generally more than 30%, and the existing method is easy to be interfered by complex background (such as fallen leaves are misjudged as garbage). Disclosure of Invention In order to overcome the defects of the prior art, one of the purposes of the invention is to provide a lightweight garbage detection method based on an improved YOLOv s model. It is a second object of the invention to provide a lightweight garbage detection system based on the improved YOLOv s model. The invention discloses a lightweight garbage detection method based on an improved YOLOv s model, which is realized by adopting the following technical scheme: step S1, only a monocular camera is adopted, the monocular camera is installed on a vehicle to shoot, and road RGB image data are obtained by the monocular camera; S2, cutting the acquired road RGB image data, cutting the upper half part of the road RGB image, and reserving key information related to a ground area below the image; And step S3, calling the improved YOLOv S, inputting the image preprocessed in the step S2 into a network model, starting a detection code to perform image reasoning detection, and drawing a detection result on the image to obtain result image data containing garbage boundary frame coordinates, garbage categories and detection confidence information. Further, in step S1, the monocular camera is mounted at an on-vehicle mounting position with a height of 1.4-1.6m from the ground and a pitch angle of 25-35 ° so that the field of view of the camera is focused on the ground area, and the non-ground false detection area is automatically filtered through space geometric constraint optimization based on the height and pitch angle mounting parameters of the camera, wherein the automatic filtering process based on the space geometric constraint optimization is as follows: step S11, establishing a conversion relation between a camera coordinate system and a world coordinate system; Step S12, calculating the distance of the acquired road RGB image data in a world coordinate system according to the vertical pixel coordinates of the camera detection frame; step S13, setting the maximum height of garbage to be generally smaller than 0.5m based on priori knowledge, so as to set a space effective area; and S14, filtering the detection frames beyond the ground projection range, and reserving the detection frames within the ground projection range. Further, in step S2, the resolution of the original image acquired by the camera is 1920×1080, the image is cut out, and only hal