Detection method of heterotropic fiber based on improved YOLOv5

. Aiming at the problems of inaccuracy and poor real-time detection of heterosexual fiber in cotton cleaning process, a target detection model of heterosexual fiber based on YOLOv5 network was proposed to realize fast and accurate identification and location of heterosexual fiber in cotton. YOLOv5 was selected as the basic target detection model, and depth separable convolution was introduced to reduce the number of parameters of the detection model and improve the detection speed. Combined with SE module of channel attention mechanism, it can reduce irrelevant information interference and enhance feature expression ability. Comparative ablation tests were performed on YOLOv5 model before and after modification. The experimental results show that the improved YOLOv5 model has a mAP of 91.6% and a frame rate of 83 frames /s. The improved YOLOv5 model can not only improve the detection accuracy but also improve the detection speed, which can better meet the requirements of accuracy and real-time detection of cotton foreign fiber.


Introduction
Heterogenous fiber is one of the main factors affecting cotton quality. With the rapid development of domestic textile industry, cotton cleaning industry has been vigorously developed, cotton cleaning has become an important factor affecting the development of textile industry. In the industrial environment, it is difficult to quickly and accurately detect the opposite sex fibers similar to cotton, which will affect the quality and production efficiency of cotton textiles. The rapid and accurate detection of foreign fiber mixed in raw cotton is the focus of cotton spinning industry and the key problem to be solved. In recent years, the research on foreign fiber detection of cotton has made some progress. Fortier C A[1] and Cintron M S [2] both realized the detection of foreign fibers in cotton by Fourier transform infrared spectroscopy. Du Yuhong [3] et al. adopted the method of clustering statistical RGB image information to realize foreign fiber identification and positioning. Zhang Hang, Qiao Xi [4] et al. proposed a hyperspectral image segmentation method of plastic film to achieve foreign fiber detection and recognition by combining spectral analysis and image processing technology. The research on the detection of heterosexual fiber is mainly based on the color, shape, texture and other characteristics of the segmentation, but the white heterosexual fiber similar to cotton is difficult to carry out image segmentation, so it is difficult to be used in the industrial detection of heterosexual fiber. At present, researchers have applied deep learning target recognition technology to agriculture, which can better achieve target detection of substances. Du Yuhong [5]  To solve the problem of the identification of foreign matter detecting under industrial environment, to promote deep learning in the textile industry the application of target detection, in this paper, polypropylene fiber silk, cloth, feather, hemp rope, plastic film, chemical fiber, seven kinds of common straight hair fiber as the research object, based on the single phase detection algorithm YOLOv5 as the infrastructure of the detection algorithm, Combined with SE module of channel attention mechanism and depth devoluble convolution, DSCE-Yolov5 method of heterotropy detection was established to achieve rapid and accurate recognition and classification of all kinds of heterotropy, and to provide theoretical basis for the later heterotropy elimination.

Improved YOLOv5 foreign fiber detection model
YOLOv5 is the latest algorithm in YOLO series, which has made great improvement in model size and detection speed. But YOLOv5 the original model is in the public training data sets, for the building of the opposite sex in our study the polypropylene fiber data set silk, chemical fiber and transparent plastic film and white cotton under certain lighting conditions the characteristics of color close, hard to detect, need to improvement and optimization of the model, in order to more quickly identify and detect its objectives. Since the detection of heterotropic fibers is used in the actual industry, the detection model needs smaller volume and faster detection speed. In this paper, standard convolution in YOLOv5 feature extraction network is replaced by deeply separable convolution, and a Pooling Block Attention Module (DSCE) is proposed combining the SE Module of Attention mechanism. This module is added to YOLOv5 network to solve the problem of no attention preference in detection. DSCE module uses the method of first compression and then expansion to enhance the learning of key points sampled from shallow features.
The improved YOLOv5 network structure as shown in figure 1, not only the depth of separable convolution can be used to reduce the pressure calculation of attention mechanism module, and convolution can be calculated more deep shallow characteristic graph extraction for important information characteristic figure, further to extract the foreign key information, improve the whole detection algorithm for foreign effect.

Experiment and result analysis
3.1 Introduction of experimental environment and data set The hardware platform used for this model training and test is the training environment based on Intel I5-9300HCPU, the graphics card is Nvidia GTX1660Ti and 8GB memory. The software platform is Win10+ Pytorch1.8.0 +Python3.7.10+ CUDA10.0+ VS2017+ OpencV2.0. The experimental materials are mainly heterosexual fibers removed from cotton in the actual production of 10 cotton spinning enterprises such as Gucheng Silver Spinning Company in Hubei Province. The raw materials for the experiment were PP yarn, cloth, feather, hemp rope, plastic film, chemical fiber and hair. This paper studied the detection and identification of these 7 kinds of heterosexual fibers. The image examples of 7 kinds of cotton foreign fibers are shown in Figure 2. In order to improve sample diversity, the light intensity was changed during image collection, and the type, quantity, size and position of heterosexual fibers in each image were randomly selected and placed. A total of 1000 images were collected, and then the data set was enlarged to 5000 images through translation, rotation and cropping.

Data set markup
When labeling the data, Labelimg tool was used for boxselected labeling, which was divided into 7 types of heterotropic fibers. The labeling example was shown in FIG. 3, and 3750 Figure 3. Example markup of an image

The setting of the anchor
In the prediction network of YOLOv3, each prediction feature layer has three pre-set prior frames. During the training process, appropriate prior frames are selected according to the size of the target size in the training picture for frame regression output prediction frame. Kmeans clustering method is added to YOLOv5 network. All pre-calibrated training data of real frames are clustered to appropriate prior frames, and then data training is performed according to the clustered prior frames, so that the results of prediction frames are closer to labeled real frames. In this paper, an adaptive prior frame method is proposed. A part of data is trained by pre-set prior frame. During the training process, the difference of prediction results is calculated by constantly comparing the prediction box of training results with the marked real box, and the size of prior frame is adjusted according to the difference result to make prediction. The prediction frame size is close to the real frame size by iterative update, and the small target can be recognized more accurately.

Evaluation index
In this paper, the performance of heterociliary measurement method was evaluated by the following indicators [8]: (1)The accuracy and recall rates are calculated as follows： Where, TP represents the number of correctly divided into positive samples, FP represents the number of incorrectly divided into positive samples, and FN represents the number of incorrectly divided into negative samples.
(2)Average accuracy and average accuracy are calculated as follows： Where, N represents the number of all target categories.
(3)Detection speed： The detection speed refers to the number of images (frames) that the target detection network can detect per second. It is expressed as FPS (frames per second).

Ablation experiments on a foreign fiber dataset
The change of foreign fiber detection performance caused by the change of network structure was gradually verified through the detection ablation experiment of foreign fiber. Four network models including YOLOv5s, YOLOv5s combined with depth-detachable convolution, SE-YOLOv5s and DSCE-YOLOv5S were trained in the four experiments respectively. The name can be used to correspond to the structural changes mentioned above. The experimental process and experimental test results are shown in Figure 4 and Table 1, where the curve rises successively from below: YOLOv5s combined with depth-detachable convolution, YOLOv5s, DSCE-YOLOv5s and SE-YOLOv5s.

Figure4
Experimental data of each model on the heterogenous fiber data set  Figure 4 and Table 1 are the experimental results of foreign fiber detection ablation experiment. It can be found that compared with the original YOLOv5s model, the detection accuracy is reduced by 0.93% and the detection speed is increased by 37.3% by using the depthseparable convolution to replace the ordinary convolution in the trunk network by reducing the number of parameters. Compared with the original YOLOv5s model, use the SE module can improve the detection accuracy by 9.1% and reduce the detection speed by 13.4% by reducing the loss of each channel. Compared with the original YOLOv5s, the accuracy of the foreign fiber detection model is improved by 6% and the detection speed is improved by 23.9% using the depth-separable convolution and SE module. It indicates that the combination of the depth separable convolution proposed in this paper instead of ordinary convolution and the SE module of attention mechanism can improve the detection accuracy of foreign fiber detection model and improve the detection speed.

Analysis of foreign fiber detection results
The partial foreign fiber detection results before and after the improvement of YOLOv5s network are shown in Figure 5, where (a) is the original input image, (b) is the detection effect picture of YOLOv5s, and (c) is the effect picture of the improved algorithm in this paper. Due to problems such as illumination brightness and small target, it is difficult to directly detect the polypropylene filament, transparent plastic film and small feather with similar color to cotton in Figure 5 (a) in the original picture. It can be seen from Figure 5 (a) and (b) that the original YOLOv5s mis-detected polypropylene fiber and missed detection of feathers, and the improved DCE-YOLOv5s can accurately detect foreign fibers when polypropylene fiber and transparent plastic film are similar to cotton, as shown in Figure 5 (c). However, it is difficult to completely detect the whole plastic film with transparent part. Feathers are still detected even when some foreign fiber features are lost due to the small size of feathers. This is because each detection scale of DCE-YOLOv5s integrates the feature information of other scales. By redistributing the weight of feature channel, the characteristic information of foreign fiber can be effectively enhanced, the interference of foreign fiber surrounding can be suppressed, and the detection of foreign fiber can be enhanced. Therefore, compared with the original YOLOv5s, DSCE-YOLOv5s can more accurately detect the opposite fiber in the image, and the improved network can reduce the loss of image information to obtain more information, improve the integrity of effective information, and effectively improve the problem of missed detection and overdetection.

Conclusion
In order to solve the problem of foreign fiber recognition in the industrial environment, this paper proposed an improved YOLOv5s algorithm to identify the foreign fiber in cotton, and the main conclusions are as follows: (1) An improved YOLOv5s network model for heterofiber detection is proposed, which is suitable for industrial environment. The data processing method of image data enhancement is adopted, and the accuracy is up to 91.6%, and the frame rate is up to 83F /s. (2) According to the characteristics of the heterotropic fiber data set, the size of the target frame of YOLOv5 model was adjusted and updated, and an improved feature extraction network based on the depth separable convolution and attention mechanism SE module was introduced to propose a heterotropic fiber recognition method based on the improved YOLOv5s model.
(3) Experiments on the test set show that the detection model in this paper can accurately detect the different fibers with similar color to cotton. Compared with YOLOv5s model, the recognition accuracy of this model is 6 percentage points higher, and the detection speed is 2.4 percentage points higher. Compared with the existing models with the same or similar objects, the DCE-YOLOv5s model in this paper has higher recognition accuracy and faster recognition speed.