Objective Defect has great influence on the accuracy of fabric quality evaluation. At present, the detection methods of fabric defect utilizing deep learning method, such as region convolutional neural networks (R-CNN) and YOLO, have insufficient detection accuracy for complex pattern fabric defects and are heavily dependent on the number of training samples. In order to solve the problem that the number of fabric defect samples with complex patterns has a large impact on the detection accuracy, a reconstruction method of fabric defect image is proposed for fabric defect detection. Method The core idea of the proposed method is to consider the defect as a damage to the fabric texture. Firstly, the conditional generative adversarial neural network(CGAN) is adopted to repair the defective area of the image. Then, the difference is calculated as pixels-by-pixels comparison between the reconstructed image and the defect image. Lastly, the detection of fabric defect is perform by the image division of difference result. Results In order to enhance reconstruction accuracy of the defect image by the generator, a self attention mechanism is used in the constitutional neural network, which can establish connections between distant pixels in the defect image. To solve the problem that the loss function of the generative adversarial neural network is weak in processing image details, the L1 loss function and the improved structural loss function are employed to construct the target loss function to improve the network's ability to process image details. Since the self attention mechanism is added to the generator, the neural network has the capability to coordinate the global features of the pattern fabric image and the local features around the defect area. The network is encouraged to reconstruct the defect according to the global features, so that the accuracy of image reconstruction is higher. Through the reconstruction experiment of oil defect images, the effectiveness of the method is proved (Fig. 1). The image reconstruction quality and image detail processing capability of the network are improved by introducing L1 loss function and improved structure loss function. L1 loss function can improve the image reconstruction quality of the network. The structural loss function can enhance the detail processing ability of the network. Two functions were simultaneously a dopted to strengthen the detection capability of defect edges and small defects (Fig. 3). ReNet-D method, SDDM-PS method and the proposed method are respectively used for the comparative experimental study of five kinds of fabric defects with different complex patterns. The results show that the ReNet-D method has a very poor performance in the detection of various defects of complex pattern fabrics, and can hardly detect the defects. The SDDM-PS method had a good detection effect on obvious defects such as oil stains and holes, but there were some cases of missed detection and false detection, and the detection effect was poor for defects such as rubbing damage and gaps with small differences from the background. It can be seen that the proposed method provides complete detection of oil, foreign matter, holes, rubbing damage and warp loss defects in the fabric (Fig. 6-Fig. 10). In terms of detection efficiency,our method takes 46.15 ms to detect an image, which is only a small increase in time consumption compared to 38.25 ms for ReNet-D and 43.82 ms for SDDM-PS. Conclusion A defect detection method based on defect image reconstruction is proposed. This method combines GAN network and self attention mechanism, and makes full use of the advantages of both to improve the reconstruction accuracy of defect images. At the same time, aiming at the problem of weak image detail processing in the generation of adversarial neural network loss function, L1 loss function and improved structure loss function are introduced to construct the target loss function, so as to improve the ability of CGAN network to process image details. The experimental results show that the ReNet-D method has poor detection accuracy for all kinds of defects, and even the original background of the image is used as a defect. SDDM-PS method has certain detection ability for oil, foreign matter and holes, but there are cases of missed detection and false detection, and it can hardly detect rubbing damage defects, and the detection integrity of warp loss defects is also very low. Although there is some error in the detection of rubbing damage and warp loss defects, the proposed method has a high degree of completeness and accuracy compared to the above two methods. © 2023 China Textile Engineering Society. All rights reserved.