iCAS: A In-Context Anomaly Segmentation Framework for Industrial Visual Inspection

Hanqiu Deng, Bin-Bin Gao, Xi Jiang, Yong Liu, Chengjie Wang, Feng Zheng, Xingyu LiOpenReview 2026 · Submission to ICLR 2026 · Rejected

TL;DR

iCAS is a new framework that brings the power of in-context learning to industrial visual inspection, allowing models to segment defects based on just a few examples. By combining a specialized mask transformer with a "General-to-Specific" training strategy, it significantly outperforms general-purpose models like SAM while being smaller and nearly twice as fast.

What Problem Does This Paper Address?

In the world of industrial manufacturing, finding defects (anomalies) is a high-stakes game of "spot the difference." While large-scale foundation models like the Segment Anything Model (SAM) have revolutionized general image segmentation, they often stumble in industrial settings.

The challenge is three-fold:

  1. Subtlety: Industrial anomalies are often tiny, low-contrast, and fine-grained—very different from the distinct "cats and dogs" found in general datasets.
  2. Data Scarcity: Labeled examples of rare defects are hard to come by.
  3. Generalization: A model trained to find scratches on metal might fail to find cracks in a cookie.

Current methods often rely on text prompts (e.g., "a scratch"), but text is too imprecise for the pixel-perfect boundaries required in quality control. The authors propose iCAS (In-Context Anomaly Segmentation) to allow models to learn "what is wrong" dynamically from a few visual examples (prompts) without needing full retraining for every new product.

Methods

The iCAS framework is built on an in-context mask transformer architecture. Its novelty lies in three key areas:

  • Greedy Query Selection (GQS): Instead of using random or fixed queries, iCAS uses an active learning strategy (formulated as a k-center problem) to select the most representative and independent features from an image. This ensures the model focuses on unique visual regions, making it much more sensitive to outliers (anomalies).
  • Mask-level Feature Matching (MFM): Rather than just comparing pixels, the model compares features at the mask level. This allows for finer discrimination between normal and abnormal regions by aggregating semantic information within proposed boundaries.
  • General-to-Specific Pre-training: The authors argue that general knowledge isn't enough. They first train the model on massive generic datasets (like COCO and ADE20K) to learn how to segment anything. Then, they perform a second "anomaly-aware" pre-training phase on specific anomaly datasets (RealIAD, MANTA) to refine the model’s ability to perceive subtle defect boundaries.

Datasets

The researchers utilized a mix of massive general datasets and specialized anomaly benchmarks:

  • Pre-training: Generic datasets (COCO, ADE20K, Objects365) and a large-scale anomaly pre-training set containing 85,564 images across over 300 anomaly categories (RealIAD and MANTA).
  • Evaluation: The gold standards for industrial inspection: MVTecAD (15 categories) and VisA (12 categories).
  • Cross-Domain: To test generalization, they also evaluated on medical datasets including Retinal OCT, Brain MRI, and Liver CT.

Key Insights and Ideas

  • Visual Prompts > Text Prompts: The paper demonstrates that visual context (showing the model a picture of a defect) provides much higher precision for boundaries than trying to describe a defect with words.
  • The "Anomaly Gap": General-purpose models fail not because they can't segment, but because their internal representations are optimized for broad semantic categories rather than the subtle deviations characteristic of defects.
  • Efficiency Matters: By using a frozen DINOv2 encoder and a lightweight decoder, iCAS achieves better results with roughly half the parameters of SAM.

Key Results

iCAS sets a new state-of-the-art (SOTA) across multiple benchmarks:

  • Semantic Segmentation: On MVTecAD, iCAS achieved 51.1% mIoU, a massive leap over the previous SOTA, SINE (19.2%). On the more difficult VisA dataset, it reached 37.3% mIoU (vs. SINE's 8.9%).
  • Interactive Performance: When a user clicks on a defect to "prompt" the model, iCAS outperforms SAM significantly (63.7% vs 39.1% mIoU on MVTecAD).
  • Speed and Scale: iCAS is highly efficient. It has 322M parameters (compared to SAM’s 641M and Matcher’s 945M) and processes images in 0.46s, making it 1.74x faster than SAM and nearly 26x faster than Matcher.
  • Few-Shot Detection: In few-shot anomaly detection (2, 4, and 8-shot), iCAS achieved AUROC scores between 97.6% and 98.2%, outperforming specialized models like WinCLIP and PatchCore.

Limitations and Future Work

Despite its strengths, the authors identify a few areas for improvement:

  • Multi-instance Failure: In cases where an image has multiple identical defects, the model sometimes segments only one and misses the others.
  • Ambiguity in Generalization: The model still struggles to generalize between very different appearances of the same defect category (e.g., a "color" anomaly that is black vs. one that is red).
  • Granularity Control: Future work will focus on making the granularity of the segmentation more controllable, allowing users to better define what constitutes a "defect" in ambiguous cases.

Summary updated

BibTeX
@misc{deng2026icas,
  author = {Hanqiu Deng and Bin-Bin Gao and Xi Jiang and Yong Liu and Chengjie Wang and Feng Zheng and Xingyu Li},
  title = {{iCAS: A In-Context Anomaly Segmentation Framework for Industrial Visual Inspection}},
  year = {2026},
  url = {https://openreview.net/forum?id=p6sJSEuoRE},
  howpublished = {OpenReview},
  note = {Submitted to ICLR 2026},
}
Figure