Cross-SGA: Semantic Guided Adapter
- Cross-SGA is a dedicated adapter that injects dual-branch cross-attention into a pre-trained UNet, enabling controlled anomaly synthesis.
- It fuses standard language-driven guidance with anomaly-specific semantic embeddings via a gated mechanism to enhance synthetic realism.
- Empirical results demonstrate that incorporating Cross-SGA with CSM and ASEA significantly boosts performance metrics such as IS and AUROC.
Cross-SGA (Semantic Guided Adapter) is a dedicated adapter architecture designed for anomaly synthesis within the AnomalyControl framework. It enables fine-grained controllable generation of realistic abnormalities by integrating cross-modal semantic features that arise from both textual and visual prompts. SGA extends each cross-attention block in a pre-trained UNet (notably Stable Diffusion) by introducing a dual-branch attention mechanism, allowing simultaneous and gated fusion of standard language-driven guidance and anomaly-specific cross-modal information coordinated upstream by a Cross-modal Semantic Modeling (CSM) module and the Anomaly-Semantic Enhanced Attention (ASEA) mechanism (He et al., 2024).
1. Architectural Overview of SGA
SGA is implemented as a lightweight adapter module injected into all 16 cross-attention blocks of a Stable Diffusion UNet. At each block, the input to SGA consists of the standard text prompt embedding and a cross-modal semantic embedding computed by CSM. Queries are projected as usual, with (flattened spatial locations), and (token dim). SGA introduces a second set of key/value projections () from , distinct from the text branch's . This enables dual cross-attention in each block: one over and another over . The outputs are fused by a learnable gate parameter 0, fixed to 1 during inference.
2. Attention Mechanisms and Core Equations
The dual-branch cross-attention operates as follows. For both textual and cross-modal (semantic) branches, attention maps are computed:
2
Corresponding outputs:
3
These are fused in a gated manner:
4
where 5 is a scalar, set to 6. In matrix form, with SGA introducing trainable parameters only in the new branch:
7
3. Interaction with Cross-Modal Feature Extraction and ASEA
Upstream, the CSM module extracts 8 by leveraging ASEA (Anomaly-Semantic Enhanced Attention). ASEA steers the attention of a large pre-trained vision-LLM (VLM) toward ground-truth anomaly regions, optimizing a guidance vector 9 so that the attention map 0 aligns with the binary anomaly mask 1. The alignment penalty is
2
and 3 is refined for 4 steps using learning rate 5. After optimization, the cross-modal embedding is computed:
6
serving as key/value source for SGA's semantic branch.
4. Optimization Objectives and Training Workflow
SGA's and ASEA's training is compartmentalized as follows.
- ASEA loss for 7:
8
- Diffusion reconstruction loss for SGA parameters 9:
0
At each iteration: (1) ASEA updates 1 for 2 steps with respect to 3, (2) 4 is frozen, a noisy latent 5 is sampled, 6 is computed, then SGA weights are updated via 7.
5. Hyperparameters and Data-Flow Specifications
- Stable Diffusion latent space: 8, 9, 0.
- VLM outputs 1 cross-modal tokens: 2, token dimension 3.
- Key/Value projections in SGA branch: 4.
- Training: SGA learning rate 5, AdamW optimizer, weight decay 6.
- ASEA: 7 guidance steps, guidance learning rate 8.
- Classifier-free guidance: each branch (text/cross-modal) independently dropped with 9.
- Gating parameter 0 fixed at 1 during both training and inference.
6. Empirical Impact of SGA and Ablation Findings
Performance metrics as measured on MVTec-AD, with relevant IS (Inception Score), IC-LPIPS, and AUROC (AUC-P, AUC-I):
| Configuration | IS | IC-LPIPS | AUC-P | AUC-I |
|---|---|---|---|---|
| SD Backbone (no SGA) | 1.50 | 0.18 | 90.3% | 93.0% |
| +SGA (visual adapter only) | 1.66 | 0.23 | 92.7% | 95.4% |
| +CSM (cross-modal) + SGA | 1.69 | 0.25 | 93.1% | 95.8% |
| Full (CSM+ASEA+SGA), 2 | 1.84 | 0.35 | 99.5% | 99.3% |
These results indicate SGA alone contributes a 0.16 increase in IS and a 2.4 percentage point increase in AUC-I. When combined with cross-modal feature extraction and attention guidance, the complete AnomalyControl stack achieves substantial gains in the realism and controllability of synthesized anomalies, with near-perfect anomaly/pixel-level detection AUROC scores (He et al., 2024). This suggests SGA is instrumental in closing the realism gap for synthetic abnormalities, especially when paired with attention-optimized cross-modal priors.
7. Significance and Outlook
Cross-SGA constitutes a dedicated and modular solution for infusing semantic and anomaly-specific guidance into conditional diffusion models. Its gated dual-attention and reliance on externally steered cross-modal embeddings distinguish it from conventional text-driven adapters, conferring enhanced ability to encode fine-grained abnormal traits for downstream inspection and detection tasks. Subsequent research may extend the Cross-SGA mechanism to other generative pipelines or further refine the interaction between semantic adapters and upstream attention guidance processes.