The manual sorting method employed in the mango production line is both inefficient and costly. Furthermore, the traditional machine sorting method is unable to accurately detect mango ripeness. To enhance the efficiency of mango ripeness detection and fulfill the requisite production demands, this paper puts forth a mango ripeness detection method founded upon the YOLOv8s model. Mango image datasets describing different ripeness levels were acquired using a bespoke image acquisition device. The neck structure of the YOLOv8s model was optimized by incorporating the Squeeze-and-Excitation attention mechanism after the C2F module. This approach enhances the model's focus on pivotal channels, mitigates the impact of superfluous channels, and elevates the precision of detection. The substitution of the original convolutional structure with the Alterable Kernel Convolution represents a further enhancement to the model's detection efficiency. The experimental results demonstrate that the enhanced YOLOv8s model markedly enhances the precision, recall, and average precision of detection, particularly the mAP50 and mAP50-95, which exhibit an improvement of 4.9% and 4.8%, respectively. The mean inference time during the production line run was 13.475 ms, with an average detection success rate of 88.75%. The aforementioned results demonstrate that the enhanced model is capable of fulfilling the practical requirements of an automated mango grading system, thereby offering dependable technical assistance in this regard.