Skip to content

Learning from Adversity: Semantic-Aware Mask Refinement through Adversarial Perturbation

Conference: ECCV 2026
Paper: ECCV Official Link
Code: https://phoenix-eccv26.github.io
Area: Segmentation
Keywords: mask refinement, adversarial perturbation, contrastive learning, instance segmentation, fine-grained segmentation

TL;DR

Addressing the lack of semantic structure in traditional morphological noise for mask refinement, Phoenix introduces embedding-space adversarial perturbation to generate realistic, controllable noise patterns and pairs it with Tri-directional Contrastive Mask Refinement Learning (CMRL), achieving state-of-the-art performance across weakly-supervised, instance, and fine-grained segmentation tasks.

Background & Motivation

Image segmentation serves as a cornerstone for pixel-level visual understanding in critical domains such as autonomous driving, medical imaging, and robotics. However, even state-of-the-art foundation segmentation models exhibit persistent failure modes when handling intricate contours, thin structures, or boundaries between visually similar categories. Retraining or end-to-end fine-tuning large vision backbones incurs prohibitive computational and annotation expenses. Mask refinement has emerged as a versatile, model-agnostic post-processing paradigm that boosts segmentation fidelity without modifying upstream networks. Furthermore, it plays a vital role in semi-supervised and weakly-supervised learning regimes by turning noisy pseudo-labels into dependable supervision signals.

The primary bottleneck in building effective mask refiners lies in synthesizing representative training pairs of noisy and clean masks. Existing methods such as SegFix and SegRefiner predominantly rely on morphological operations like erosion, dilation, and random edge jittering. Such synthetic perturbations are spatially randomized and context-blind, completely failing to mimic the structured, semantic failure modes of deep neural networks caused by feature confusion or predictive uncertainty. On the other hand, training-free refiners that freeze large pre-trained foundation models like SAM rely strictly on heuristic prompt engineering without optimizing representations specifically for the mask-correction task.

Drawing philosophical inspiration from the notion that systems grow strongest by facing meaningful challenges, this work posits that a mask refiner must confront realistic, structured obstacles to learn robust error-correction capabilities. Core idea: repurpose adversarial perturbation from a destructive testing tool into a constructive data-generation mechanism by performing embedding-space attacks on a frozen lightweight decoder to synthesize realistic semantic noise, and couple it with Tri-directional Contrastive Mask Refinement Learning (CMRL) to model feature transformations across ground-truth, noisy input, and refined prediction states.

Method

Overall Architecture

The overall pipeline of Phoenix comprises three primary phases: image embedding extraction, Adversarial Mask Perturbation (AMP), and Contrastive Mask Refinement Learning (CMRL). Phoenix builds upon the Segment Anything Model (SAM) architecture, freezing the large ViT-H image encoder (637M parameters) to reuse image embeddings across training steps and fine-tuning only the lightweight mask decoder (4M parameters).

During training, the frozen encoder extracts image embeddings once per image. The Adversarial Mask Perturbation module then injects learnable perturbation embeddings into the decoder input to construct semantically structured, uncertainty-driven noisy masks. Next, the generated noisy mask and its derived prompt embeddings are fed into the decoder to produce refined mask predictions. Finally, features across ground truth, noisy input, and refined predictions are projected into an embedding space where a tri-directional contrastive loss and conventional segmentation objectives jointly optimize the decoder parameters.

%%{init: {'flowchart': {'rankSpacing': 24, 'nodeSpacing': 28, 'padding': 6, 'wrappingWidth': 400}}}%%
flowchart TD
    A["Input Image I & Target Mask M_t"] --> B["Image Encoder (Frozen ViT-H)<br/>Extract and cache image embeds E_img"]
    B --> C["Adversarial Mask Perturbation AMP<br/>Controllable embedding attack yields noisy mask M_n"]
    C --> D["Lightweight Decoder (Fine-tuned 4M)<br/>Refine mask with visual prompts into M_r"]
    D --> E["Contrastive Mask Refinement Learning CMRL<br/>Tri-directional feature contrast across 6 regions"]
    E --> F["High-Quality Refined Mask Output"]

Key Designs

1. Adversarial Mask Perturbation (AMP): Controllable, uncertainty-driven semantic noise synthesis

Unlike conventional adversarial attacks designed to degrade model accuracy at the pixel level, AMP operates constructively in the embedding space of SAM's lightweight decoder to synthesize realistic segmentation mistakes. Given target mask \(M_t\), learnable perturbation embeddings \(E_p \in \mathbb{R}^{P \times C}\) are injected into the frozen decoder alongside visual prompt embeddings \(E_v\). Single-step or multi-step FGSM updates perturb \(E_p\) along the gradient direction of an adversarial loss: \(E_p \leftarrow E_p + \alpha \cdot \text{sign}(\nabla_{E_p} \mathcal{L}_{adv})\). Grounded in Bayesian deep learning principles, the magnitude of the embedding gradient is intrinsically tied to local predictive uncertainty: $\(\|\nabla_{E_p} f_{dec}(E_{img}, [E_p; E_v]; \theta_{dec})\|_2 \propto -\log p(y | E_{img}, [E_p; E_v]; \theta_{dec})\)$ Perturbations therefore naturally concentrate in ambiguous boundary zones and difficult semantic transitions where real models stumble. By defining guidance masks \(M_g\), AMP controls the error mode: expansion (\(M_g=1\), false positives), contraction (\(M_g=0\), false negatives), or inversion (\(M_g=1-M_t\), balanced). An adaptive threshold-guided loop iteratively steps until the IoU between noisy and target masks lands in \([\tau, \tau+\epsilon]\), achieving realistic noise patterns with minimal compute.

2. Intra-Class Feature Consistency: Enforcing feature cohesion within semantic classes

Standard pixel-wise losses treat spatial locations independently, failing to preserve global semantic coherence across damaged regions. CMRL introduces a structured tri-directional state space by categorizing pixels into six mutually exclusive sets based on target (\(M_t\)), noisy (\(M_n\)), and refined (\(M_r\)) masks: true regions (\(\mathcal{T}_{fg}, \mathcal{T}_{bg}\)), successfully refined regions (\(\mathcal{S}_{fg}, \mathcal{S}_{bg}\)), and unrefined failure regions (\(\mathcal{F}_{fg}, \mathcal{F}_{bg}\)). Over feature vectors projected by a 3-layer MLP, intra-class consistency pulls foreground failure features in \(\mathcal{F}_{fg}\) toward correct foreground representations (\(\mathcal{T}_{fg} \cup \mathcal{S}_{fg}\)) while implicitly repelling background features, eliminating fractured predictions on thin object parts under partial occlusion or complex lighting.

3. Inter-Class Feature Contrast: Sharpening high-confusion boundary transitions

Misclassifications frequently concentrate along object boundaries where representations blur across foreground and background. The inter-class contrastive objective establishes explicit bidirectional repulsion between foreground failure points and all background regions, as well as background failure points and all foreground regions: $\(\mathcal{L}_{inter}^{fg \to bg} = \mathbb{E}_{i \in \mathcal{F}_{fg}} \left[ -\log \frac{\sum_{j \in \mathcal{T}_{fg} \cup \mathcal{S}_{fg}} \exp(\text{sim}(p_i, p_j) / \tau_{temp})}{\sum_{j \in \mathcal{T}_{fg} \cup \mathcal{S}_{fg}} \exp(\text{sim}(p_i, p_j) / \tau_{temp}) + \sum_{k \in \mathcal{T}_{bg} \cup \mathcal{S}_{bg}} \exp(\text{sim}(p_i, p_k) / \tau_{temp})} \right]\)$ By maximizing the denominator distance between foreground errors and background features, this formulation reshapes the local geometric feature landscape, constructing razor-sharp decision boundaries that prevent over-smoothing.

4. Self-Improvement Regularization: Bootstrapping recovery from successful refinements

Beyond static correctness, mask refinement is intrinsically a dynamic process of correcting flawed inputs into accurate segmentations. Phoenix implements a self-improvement regularization term that directly uses successfully corrected regions within the same image (\(\mathcal{S}_{fg} \cup \mathcal{S}_{bg}\)) as dynamic anchors to guide remaining failure regions (\(\mathcal{F}_{fg} \cup \mathcal{F}_{bg}\)): $\(\mathcal{L}_{self} = -\mathbb{E}_{i \in \mathcal{F}_{fg} \cup \mathcal{F}_{bg}} \left[ \log \frac{\sum_{j \in \mathcal{S}_{fg} \cup \mathcal{S}_{bg}} \exp(\text{sim}(p_i, p_j) / \tau_{temp})}{\sum_{k \in \Omega} \exp(\text{sim}(p_i, p_k) / \tau_{temp})} \right]\)$ This dynamic bootstrapping mechanism transfers correction knowledge gained on straightforward structural segments directly to adjacent or difficult residual error regions within the identical visual context.

Loss & Training

The overall training objective combines traditional segmentation losses with the CMRL contrastive formulation: $\(\mathcal{L}_{total} = \mathcal{L}_{Dice} + \mathcal{L}_{Focal} + \mathcal{L}_{CMRL}\)$ where the contrastive objective is balanced by: \(\mathcal{L}_{CMRL} = \lambda_{intra} \mathcal{L}_{intra} + \lambda_{inter} \mathcal{L}_{inter} + \lambda_{self} \mathcal{L}_{self}\), with defaults \(\lambda_{intra} = 0.4, \lambda_{inter} = 0.4, \lambda_{self} = 0.2\). Optimization uses AdamW with an initial learning rate of \(1 \times 10^{-4}\) and cosine decay over 10K iterations with batch size 16 across 8 V100 GPUs, finishing training in under 10 hours.

Key Experimental Results

Main Results

Phoenix delivers substantial improvements when refining coarse masks from weakly-supervised, semi-supervised, off-the-shelf instance segmentation, and high-precision fine-grained segmentation models.

Benchmark / Setting Metric Coarse Input Prev. SOTA (SAMRefiner) Phoenix (Ours) Gain
Weakly Semi-Supervised PointWSSIS (1% F + 99% P) \(AP_{mask}\) 12.6 21.8 28.7 +16.1 (+6.9 vs SOTA)
Weakly Semi-Supervised PointWSSIS (1% F + 99% P) \(AP_{boundary}\) 6.3 16.4 23.6 +17.3 (+7.2 vs SOTA)
Semi-Supervised NB (1% F + 99% U) \(AP_{mask}\) 5.1 8.1 9.8 +4.7 (+1.7 vs SOTA)
Instance Segmentation Mask R-CNN (RN50) \(AP_{mask}\) 39.8 45.3 46.9 +7.1 (+1.6 vs SOTA)
Instance Segmentation Mask2Former \(AP_{mask}\) 46.8 49.0 50.6 +3.8 (+1.6 vs SOTA)
Fine-Grained DIS-UNet (Average) IoU / Boundary F 54.7 / 68.4 64.3 / 72.4 (HQ-SAM) 75.7 / 84.4 +21.0 / +16.0
Fine-Grained DIS-ISNet (Average) IoU / Boundary F 66.1 / 79.6 67.1 / 74.1 (HQ-SAM) 76.6 / 85.9 +10.5 / +6.3

Ablation Study

Ablations on PointWSSIS 1% (\(AP_1\)), Mask R-CNN RN50 (\(AP_2\)), and DIS fine-grained benchmarks (\(IoU_1, IoU_2\)) isolate component contributions and hyper-parameter behavior.

Configuration Perturbation Contrastive Loss \(AP_1\) (Weakly-sup) \(AP_2\) (High-qual) \(IoU_1\) (Fine-grained) \(IoU_2\) (Fine-grained) Note
Baseline Morphological None (\(\times\)) 22.3 45.2 65.3 69.9 Standard morphological noise + pixel loss
CMRL Only Morphological Enabled (\(\checkmark\)) 23.8 45.5 67.8 71.0 Morphological noise with tri-directional contrast
AMP Only Adversarial None (\(\times\)) 26.9 46.1 71.5 74.2 Adversarial noise with standard pixel loss
Phoenix (Full) Adversarial Enabled (\(\checkmark\)) 28.7 46.9 75.7 77.1 Full model with synergistic gains
Criterion: MSE Adversarial Enabled (\(\checkmark\)) 28.7 46.8 - - MSE adversarial objective alternative
Real Errors: UNet Real model noise Enabled (\(\checkmark\)) - - 67.6 71.6 Static model noise limits diversity
Real Errors: ISNet Real model noise Enabled (\(\checkmark\)) - - 65.6 70.2 Lacks magnitude controllability

Key Findings

  • Synergy between AMP and CMRL: AMP is the primary driver of performance gains (+4.6% on \(AP_1\), +6.2% on \(IoU_1\)), confirming that facing realistic errors is crucial for learning refinement. When combined with CMRL, the joint improvement (+10.4% on \(IoU_1\)) surpasses the sum of individual gains (+8.7%), because CMRL thrives when contrasting semantically coherent, realistic error distributions.
  • Superiority over Real Model Errors: Training directly on error masks harvested from real networks (UNet/ISNet) yields inferior accuracy (\(IoU_1\) 67.6/65.6) compared to AMP (75.7). AMP not only reflects realistic error semantics but also supplies superior diversity and controllable intensity through dynamic sampling \(\tau \sim U(0.3, 0.9)\).
  • Zero Inference Overhead: The adversarial perturbation operates solely on the lightweight decoder during data loading (requiring only 6 ms per update on a V100 GPU). At test time, Phoenix runs as a single forward pass without iterative adversarial search.

Highlights & Insights

  • Repurposing Adversarial Attacks for Constructive Data Generation: Rather than utilizing adversarial perturbations as destructive robustness probes, Phoenix retools them into a generative mechanism in embedding space, creating training noise that mirrors human and neural network ambiguity.
  • Tri-directional Spatial Contrast and Self-Improvement: By partitioning mask states into six functional regions, CMRL pioneers a bootstrapping paradigm where successful online corrections dynamically serve as positive anchors for remaining unrefined failures within the same visual scene.
  • Versatile Plug-and-Play Performance: Phoenix generalizes effortlessly from zero-shot pseudo-label upgrading in label-sparse regimes to boosting cutting-edge instance segmentors like Mask2Former and ViTDet.

Limitations & Future Work

  • Author-Admitted Limitations: When upstream segmentors suffer catastrophic false negatives (e.g., missing an entire object instance), mask refinement cannot infer or hallucinate an object from a completely blank mask.
  • Future Directions: Exploring multimodal prompt-guided adversarial perturbations (e.g., text-conditioned embedding attacks) to simulate cross-modal misalignments, and extending the self-improvement formulation to fully unsupervised test-time adaptation.
  • vs SegRefiner / SegFix: Early methods rely on morphological dilation and erosion that lack semantic relevance; Phoenix generates context-aware adversarial perturbations in embedding space, yielding substantial performance margins.
  • vs SAMRefiner: SAMRefiner freezes the entire SAM model and relies on heuristic prompt heuristics without task-specific tuning; Phoenix fine-tunes the lightweight decoder and uses CMRL to reshape boundary feature geometries, excelling at intricate, thin topological structures.

Rating

  • Novelty: โญโญโญโญโญ [Creative adaptation of embedding-space adversarial perturbation into constructive noise generation paired with tri-directional contrastive learning]
  • Experimental Thoroughness: โญโญโญโญโญ [Exhaustive evaluations across weak-supervision, instance segmentation, and fine-grained DIS benchmarks with rigorous ablations]
  • Writing Quality: โญโญโญโญโญ [Clear philosophical framing, rigorous mathematical definitions, and coherent narrative flow]
  • Value: โญโญโญโญโญ [A plug-and-play refiner offering significant practical value for data-efficient learning and precision segmentation]