Bolt-SAM: Attribute Segmentation for Defect Editing
- Bolt-SAM is a specialized segmentation model designed to generate precise attribute masks for bolt components like pins and nuts under challenging imaging conditions.
- It incorporates a CLAHE-FFT adapter and a Multipart-Aware Mask Decoder to enhance high-frequency features and accurately capture thin, multipart bolt structures.
- Evaluations show that Bolt-SAM outperforms existing methods with higher mIoU, Dice, and Pixel Accuracy, making it a key component in the SBDE defect editing pipeline.
Bolt Attribute Segmentation Model (Bolt-SAM) is a bolt-specific attribute segmentation model introduced as the segmentation backbone of the segmentation-driven bolt defect editing framework SBDE, whose purpose is to generate precise masks for bolt components such as pins and nuts so that those attributes can later be removed and reconstructed during defect synthesis (Xiao et al., 14 Aug 2025). Rather than targeting generic object segmentation, Bolt-SAM is designed for high-quality mask generation under the imaging conditions of transmission-line inspection, where bolts are small, often low-resolution, weakly contrasted against the background, and frequently affected by lighting changes, shadows, clutter, and noise. Within SBDE, its role is foundational: it defines the regions to be edited, and the downstream mask optimization, LaMa-based inpainting, scene recovery, and data augmentation stages depend on its masks being boundary-consistent and semantically correct (Xiao et al., 14 Aug 2025).
1. Problem setting and motivation
Bolt-SAM was proposed in the context of bolt defect detection for transmission lines, where defect images are scarce and data distributions are imbalanced (Xiao et al., 14 Aug 2025). The larger SBDE framework addresses this by converting normal bolts into defective ones through attribute editing, but that workflow requires a segmentation model capable of isolating bolt attributes with high precision. Bolt-SAM is therefore motivated by the need for accurate attribute masks rather than general-purpose instance masks.
The motivating difficulty is that existing segmentation tools, including SAM and RobustSAM, are reported to be hard to apply directly to bolt imagery because the relevant targets are visually challenging and structurally atypical (Xiao et al., 14 Aug 2025). Bolt attributes such as pins are not necessarily simple contiguous regions; a pin may appear as a thin, multipart, or disconnected structure. In this setting, even small segmentation errors have downstream consequences. If the segmented region is inaccurate, the inpainting stage may remove the wrong pixels, leave remnants of the original attribute, or include excess background, producing unnatural synthesized defects (Xiao et al., 14 Aug 2025).
This suggests that Bolt-SAM is best understood not as an isolated segmentation model, but as a prerequisite mechanism for controllable defect synthesis. The central technical requirement is mask quality in service of editing fidelity, rather than segmentation accuracy in the abstract.
2. Position within the SBDE pipeline
SBDE consists of three linked stages: attribute segmentation, mask-guided editing, and edited-scene recovery (Xiao et al., 14 Aug 2025). Bolt-SAM occupies the first stage and supplies the mask used by the later modules. A normal bolt image first enters Bolt-SAM, whose encoder-side enhancement and decoder-side multipart reasoning produce a fine-grained attribute mask. That mask is then passed to the mask optimization module (MOD), after which LaMa performs inpainting to remove the selected bolt attribute:
Bolt-SAM does not directly edit images; it produces the region definition that determines what is edited (Xiao et al., 14 Aug 2025). This separation is architecturally important. The segmentation stage identifies the target attribute, MOD enlarges and smooths the mask for more natural inpainting context, and LaMa reconstructs the edited image. The subsequent editing recovery augmentation (ERA) strategy then restores the edited defect bolt to the original inspection scene and expands the defect detection dataset (Xiao et al., 14 Aug 2025).
A plausible implication is that Bolt-SAM enables the “segmentation-driven” character of SBDE by making the editable region explicit and structurally grounded. Without that explicit mask definition, the later editing stages would lack the precision required for bolt-specific defect synthesis.
3. Architecture: RobustSAM adaptation through CFA and MAMD
Bolt-SAM is constructed by improving RobustSAM with two components: the CLAHE-FFT Adapter (CFA) in the image encoder and the Multipart-Aware Mask Decoder (MAMD) in the mask-decoding stage (Xiao et al., 14 Aug 2025). The design retains SAM’s original image encoder and prompt encoder in frozen form, while training the adapter, mask decoder, and fusion network. This yields a lightweight bolt-specific adaptation rather than a full end-to-end retraining of the underlying segmentation backbone.
The CFA module addresses weak edge visibility in inspection images. It first enhances image details using Contrast Limited Adaptive Histogram Equalization, producing an enhanced image . The enhanced image is transformed to the frequency domain:
A high-pass filter based on the mask is then applied to isolate high-frequency information:
where and are the image height and width, and controls the low-frequency cutoff. The filtered signal is transformed back:
This high-frequency component is combined with the patch embedding output to form the input feature 0 for the adapter. The adapter is an MLP-based projection defined as
1
Here, 2 is trainable for each adapter block, and 3 is a shared up-projection layer mapping the prompt vector to the transformer embedding dimension (Xiao et al., 14 Aug 2025). The resulting prompt 4 is appended to each transformer layer, steering the encoder toward edge-aware bolt-relevant features. In practical terms, the paper states that this is especially helpful for nuts and small pin parts.
MAMD addresses the structural complexity of bolt attributes, especially pins. Because bolt pins often appear in dispersed multipart form, a single-shot mask prediction is described as less reliable (Xiao et al., 14 Aug 2025). MAMD therefore adopts a multipart-aware, multi-task fine-tuning scheme. For pins, the attribute is split into three parts—pin0, pin1, and pin2—which are trained separately with point prompts and then fused into a complete pin mask. For nuts, a single branch is sufficient because nuts are structurally simpler than multipart pins (Xiao et al., 14 Aug 2025).
4. Multipart supervision, prompting strategy, and optimization objective
A central design choice in Bolt-SAM is the use of point prompts rather than box prompts for fine-grained bolt attribute localization (Xiao et al., 14 Aug 2025). The paper states that point prompts provide more precise localization in low-resolution bolt images, whereas box prompts tend to include too much irrelevant background. This is particularly consequential for disconnected or thin structures such as pins.
For each local region in MAMD, the optimization uses a composite loss:
5
where 6 is the predicted mask and 7 is the ground-truth mask for sub-region 8, and 9 are weighting coefficients (Xiao et al., 14 Aug 2025). The Focal Loss is used to address class imbalance and hard-to-segment boundary pixels, while Dice Loss promotes overlap quality and shape consistency. The complete attribute mask is obtained by merging local masks through a lightweight fusion network implemented with two convolution layers and batch normalization. The global mask is stated to be optimized with the same local loss formulation (Xiao et al., 14 Aug 2025).
Training uses point prompts in a specific way: three points are randomly sampled from the ground-truth mask during training (Xiao et al., 14 Aug 2025). Bolt-SAM fine-tunes only CFA and MAMD; the remaining components inherited from the RobustSAM baseline remain frozen. The reported implementation uses a learning rate of 0, batch size 2, and 50 epochs on two NVIDIA 4090 GPUs with PyTorch 2.4, CUDA 12.1, and Python 3.10 (Xiao et al., 14 Aug 2025).
This training configuration reinforces the model’s intended scope. Bolt-SAM is not presented as a universal segmentation system, but as a narrowly adapted segmentation engine optimized for bolt imagery, bolt attributes, and the needs of subsequent editing.
5. Datasets, evaluation protocol, and quantitative performance
The study constructs three datasets: BDD for scene-level defect detection, BDG for bolt image editing and generation comparison, and BAS for bolt attribute segmentation (Xiao et al., 14 Aug 2025). Bolt-SAM is trained and evaluated on BAS, which contains only normal bolts and manually annotated masks for nut and pin attributes; the pin is additionally split into pin0, pin1, and pin2 (Xiao et al., 14 Aug 2025).
The segmentation metrics are mean Intersection over Union (mIoU), Dice, and Pixel Accuracy (PA). Bolt-SAM is compared against SAM, SAM-Adapter, HQ-SAM, and RobustSAM, with both 1-point and 3-point prompt settings tested (Xiao et al., 14 Aug 2025).
With 3-point prompts, the main reported results are as follows:
| Attribute | mIoU | Dice | PA |
|---|---|---|---|
| Pin | 75.66% | 86.01% | 98.02% |
| Nut | 76.78% | 86.47% | 94.71% |
These results are reported to outperform RobustSAM with 3 points, described as the strongest baseline, by about 4.50 points mIoU, 3.21 points Dice, and 0.54 points PA for pin segmentation, and by 6.34, 4.57, and 1.95 points for nut segmentation (Xiao et al., 14 Aug 2025). The paper also reports that Bolt-SAM produces clearer boundaries and fewer missed regions than competing methods, including under complex background interference.
The ablation study isolates the contributions of the two added modules:
| Setting | Pin mIoU | Nut mIoU |
|---|---|---|
| B1 baseline | 71.16 | 70.44 |
| B2 + CFA | 74.83 | 76.78 |
| B3 + MAMD | 73.75 | — |
| B4 + CFA + MAMD | 75.66 | — |
The reported pattern is functionally specific: CFA alone improves nut segmentation noticeably, MAMD alone improves pin segmentation, and using both together gives the best overall performance (Xiao et al., 14 Aug 2025). This division of effect matches the intended roles of the modules: CFA enhances difficult edge information, while MAMD targets multipart structure.
6. Interaction with MOD-LaMa and contribution to defect augmentation
Once Bolt-SAM generates a mask, SBDE applies the MOD-LaMa pipeline (Xiao et al., 14 Aug 2025). MOD is not part of Bolt-SAM itself, but its necessity clarifies why Bolt-SAM’s masks matter. Because bolt images are low-resolution and segmentation masks can remain tight around the target, LaMa may lack sufficient surrounding context for natural inpainting. MOD therefore enlarges and smooths the segmentation region using morphological operations. The opening operation is defined as
1
where 2 is the structuring element. Erosion and dilation are given as
3
4
The final optimized mask is
5
The structural dependence is explicit: better segmentation yields better masks; better masks yield better morphological optimization; and better optimized masks yield more realistic LaMa inpainting (Xiao et al., 14 Aug 2025). This relation is reflected in the reported editing ablations. When Bolt-SAM and MOD-LaMa are combined, attribute editing accuracy and human preference are highest; the paper gives pin AEA of 6 and nut AEA of 7, together with the highest HPS scores (Xiao et al., 14 Aug 2025).
At the downstream detection level, the SBDE-augmented dataset improves YOLOv11 performance over both the original and copy-augmented baselines, increasing overall precision, recall, and mAP (Xiao et al., 14 Aug 2025). Although those detection gains belong to the full SBDE system rather than to Bolt-SAM in isolation, the paper positions Bolt-SAM as the enabling mechanism that makes defect synthesis controllable and structurally faithful.
7. Significance, scope, and interpretive context
Bolt-SAM is significant within SBDE because it adapts SAM-style segmentation to the specific geometry and imaging conditions of bolt inspection (Xiao et al., 14 Aug 2025). Its two defining interventions are complementary. CFA improves feature extraction through CLAHE and FFT-based high-frequency enhancement, while MAMD improves robustness to multipart and non-contiguous structures through point-prompted, part-wise supervision and mask fusion. The resulting masks are then refined by MOD and used by LaMa to synthesize defective bolts.
A common misconception would be to treat Bolt-SAM as a generic bolt detector or as an image editing model. The paper describes neither. Bolt-SAM is a segmentation engine specialized for bolt attributes, and its output is an attribute mask rather than a defect label or an edited image (Xiao et al., 14 Aug 2025). Its practical importance derives from its role in the larger editing pipeline.
Another potential misconception is that segmentation quality can be judged independently of the downstream task. The formulation in SBDE argues the opposite. In this setting, boundary precision, semantic correctness, and completeness of thin or disconnected parts directly condition the realism of defect synthesis (Xiao et al., 14 Aug 2025). This suggests that Bolt-SAM exemplifies task-coupled segmentation design: the segmentation objective is shaped by the requirements of subsequent inpainting and augmentation, not merely by generic region overlap metrics.
The code for the overall project is reported as publicly available at the repository linked by the authors (Xiao et al., 14 Aug 2025). Within the research trajectory defined by SBDE, Bolt-SAM serves as the segmentation component that makes segmentation-driven bolt defect editing technically viable.