Marigold, as an important traditional Chinese medicine with the functions of clearing heat and detoxification, protecting the liver, beautifying the face as well as promoting the health of the eyes, etc. Its demand is increasing day by day, and mechanized harvesting has become an inevitable trend in the industrialization of marigold harvesting. Therefore, this study tries to collect a new dataset in the south of Xinjiang, China, which is important for the production of marigold focusing on improving the YOLOv7 model by lightweighting, and proposing a set of detection models suitable for marigold. By deleting the redundant object detection layer of the YOLOv7 model, replacing the ordinary convolution of the backbone network with the DSConv convolution, replacing the SPPCSPC module with Simplified SPPF, and finally pruning and fine-tuning the model, it seeks to solve the trouble of the difficulty in deploying the mobile devices of the marigold picking robot and the inability to realize the high real-time detection. The experimental result shows that the accuracy and average accuracy mAP0.5 of the improved YOLOv7 model in marigold detection reach 93.9% and 97.7%, which are both improved compared with the original YOLOv7 model; the GFLOPs is only 2.3, which is 2.2% of the original model; and the parameter amount is 15.04M, which is 41.2% of the original model; The FPS is 166.7, which is 26.7% higher than the original model. It shows excellent accuracy and speed in detecting marigolds, providing strong technical support for marigold harvesting.