[Paper Review] End-to-end training of a two-stage neural network for defect detection
This paper proposes an end-to-end training scheme for a two-stage neural network in surface defect detection, enabling simultaneous optimization of segmentation and classification via gradient-flow adjustment and dynamic loss balancing. The method achieves state-of-the-art performance, including 100% detection rates on DAGM and KolektorSDD datasets, through innovations like frequency-of-use sampling and distance-transform-weighted loss for positive pixels.
Segmentation-based, two-stage neural network has shown excellent results in the surface defect detection, enabling the network to learn from a relatively small number of samples. In this work, we introduce end-to-end training of the two-stage network together with several extensions to the training process, which reduce the amount of training time and improve the results on the surface defect detection tasks. To enable end-to-end training we carefully balance the contributions of both the segmentation and the classification loss throughout the learning. We adjust the gradient flow from the classification into the segmentation network in order to prevent the unstable features from corrupting the learning. As an additional extension to the learning, we propose frequency-of-use sampling scheme of negative samples to address the issue of over- and under-sampling of images during the training, while we employ the distance transform algorithm on the region-based segmentation masks as weights for positive pixels, giving greater importance to areas with higher probability of presence of defect without requiring a detailed annotation. We demonstrate the performance of the end-to-end training scheme and the proposed extensions on three defect detection datasets - DAGM, KolektorSDD and Severstal Steel defect dataset - where we show state-of-the-art results. On the DAGM and the KolektorSDD we demonstrate 100\% detection rate, therefore completely solving the datasets. Additional ablation study performed on all three datasets quantitatively demonstrates the contribution to the overall result improvements for each of the proposed extensions.
Motivation & Objective
- To address the slow and cumbersome two-stage training process in defect detection networks that requires sequential training of segmentation and classification heads.
- To enable end-to-end learning in a two-stage architecture without compromising performance, reducing training time and improving convergence.
- To reduce dependency on precise pixel-level annotations by extending the loss function to handle region-based, coarser annotations with uncertainty modeling.
- To improve model generalization on imbalanced datasets by introducing frequency-of-use sampling for negative (non-defective) samples.
- To enhance feature learning for defect regions by applying distance transform as sample weights for positive pixels, increasing focus on high-probability defect areas.
Proposed method
- Introduce end-to-end training by jointly optimizing segmentation and classification heads in a single forward and backward pass, eliminating the need for sequential training.
- Dynamically balance the segmentation and classification loss components during backpropagation to stabilize training and prevent instability from classification gradients.
- Adjust gradient flow from the classification head to the segmentation head to avoid corrupting learned features during joint optimization.
- Extend the loss function to account for uncertainty in region-based annotations, allowing use of less precise but easier-to-annotate bounding boxes or regions.
- Apply a frequency-of-use sampling strategy that prioritizes underused negative (non-defective) samples to address class imbalance during training.
- Use the distance transform on segmentation masks as class-agnostic weights for positive pixels, giving higher importance to pixels near defect boundaries and improving localization accuracy.
Experimental results
Research questions
- RQ1Can end-to-end training of a two-stage defect detection network achieve superior performance compared to traditional two-stage training with separate optimization phases?
- RQ2How can gradient flow between segmentation and classification heads be adjusted to maintain stable feature learning during joint optimization?
- RQ3To what extent can coarser, region-based annotations be used effectively in training without sacrificing detection accuracy?
- RQ4Does frequency-of-use sampling of negative samples improve model performance on imbalanced defect detection datasets?
- RQ5Can distance-transform-based weighting of positive pixels enhance detection performance without requiring precise pixel-level annotations?
Key findings
- The proposed end-to-end training scheme achieves 100% detection rate on the DAGM dataset, completely solving it and outperforming all prior methods.
- On the KolektorSDD dataset, the method achieves a 100% detection rate, also completely solving the dataset, and reduces training iterations by half compared to the prior two-stage approach.
- The combination of frequency-of-use sampling and distance-transform weighting increases the AP on the Severstal Steel defect dataset from 98.24% to 98.70%.
- Ablation studies confirm that each proposed component—dynamic loss balancing, gradient-flow adjustment, frequency-of-use sampling, and distance-transform weighting—individually contributes to performance gains, with the best results achieved when all are used together.
- The method demonstrates robustness to coarse annotations, enabling effective training with region-based labels instead of precise pixel-level masks, which are costly to obtain.
- The ablation study shows that removing any single component leads to a measurable drop in performance, confirming the necessity and mutual benefit of all proposed extensions.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.