Aiming at the problems of low detection accuracy caused by complex shape and large scale change of cotton impurities,an intelligent classification detection method based on improved YOLOv5 was proposed.The adaptive anchor frame algorithm adapted to the data set was used to re-cluster the anchor frame to improve the detection effect of small target impurities.In the feature fusion part,MCA attention mechanism module was introduced to focus the impurity target information of the effective feature layer,reduce the interference of irrelevant areas,and locate the cotton impurity target more accurately.The GIoU loss function was used to calculate the loss of cotton impurity prediction box and real box,and the best cotton impurity detection box was filtered out,which makes the algorithm more suitable for the current detection task.Experimental results show that the average accuracy of the proposed algorithm model(mAP@0.5)reaches 92.5%.Compared with YOLOv3,YOLOv5,YOLOv8 and YOLOv6,the mAP index of the proposed algorithm was improved by 15.4%,2.2%,13.5%and 26.4%,respectively.It provides reference for intelligent classification and detection of cotton impurities,and the accuracy of model detection is improved.