*Article* **Real-Time Grading of Defect Apples Using Semantic Segmentation Combination with a Pruned YOLO V4 Network**

**Xiaoting Liang 1,2,3, Xueying Jia 1,2,3, Wenqian Huang 1,3, Xin He 1,3, Lianjie Li 1,3, Shuxiang Fan 1,3, Jiangbo Li 1,3, Chunjiang Zhao 1,3 and Chi Zhang 1,3,\***


**Abstract:** At present, the apple grading system usually conveys apples by a belt or rollers. This usually leads to low hardness or expensive fruits being bruised, resulting in economic losses. In order to realize real-time detection and classification of high-quality apples, separate fruit trays were designed to convey apples and used to prevent apples from being bruised during image acquisition. A semantic segmentation method based on the BiSeNet V2 deep learning network was proposed to segment the defective parts of defective apples. BiSeNet V2 for apple defect detection obtained a slightly better result in MPA with a value of 99.66%, which was 0.14 and 0.19 percentage points higher than DAnet and Unet, respectively. A model pruning method was used to optimize the structure of the YOLO V4 network. The detection accuracy of defect regions in apple images was further improved by the pruned YOLO V4 network. Then, a surface mapping method between the defect area in apple images and the actual defect area was proposed to accurately calculate the defect area. Finally, apples on separate fruit trays were sorted according to the number and area of defects in the apple images. The experimental results showed that the average accuracy of apple classification was 92.42%, and the F1 score was 94.31. In commercial separate fruit tray grading and sorting machines, it has great application potential.

**Keywords:** defective apples; apple grading; deep learning; object detection; semantic segmentation
