Abstract
SAM-LAD is a zero-shot, plug-and-play framework that addresses the challenge of detecting "logical anomalies"—complex errors in object relationships and arrangements that traditional methods often miss. By combining the Segment Anything Model (SAM) with a novel object-matching pipeline, SAM-LAD treats scenes as collections of discrete objects rather than simple pixel grids. This approach eliminates the need for scene-specific retraining while significantly outperforming state-of-the-art models on challenging industrial benchmarks like MVTec LOCO AD.
Introduction: Structural vs. Logical Anomalies
Most visual anomaly detection (AD) methods are optimized for structural anomalies, which include local defects like scratches, dents, or holes. However, these methods frequently fail when encountering logical anomalies. In these cases, individual components appear perfect, but their arrangement, quantity, or relationship is incorrect—for example, a breakfast box missing a fruit or a bag containing the wrong number of screws.
Existing logical AD methods typically suffer from heavy data dependency, requiring extensive training on "normal" samples for every new product. Furthermore, they often lack the context needed to understand semantic relationships between objects, especially when those objects are placed randomly rather than in fixed positions.
Methodology
SAM-LAD utilizes a four-stage pipeline designed to avoid training on specific anomaly datasets entirely, enabling a truly zero-shot application.
1. Feature Extraction & Retrieval
The system employs a pre-trained DINOv2 backbone to extract high-level feature maps. For a given query image, it performs a nearest-neighbor search within a bank of normal images to identify the most similar reference samples, mimicking the human strategy of comparing a test sample against a mental "normal" template.
2. Object Segmentation via SAM
It leverages the Segment Anything Model (SAM) to generate masks for every object in the scene. To ensure the model focuses on relevant components rather than granular details (like individual grains of cereal), area-based filters are applied to isolate key objects of interest.
3. Object Matching Model (OMM)
This stage serves as the system's core reasoning engine. It uses a Dynamic Channel Graph Attention (DCGA) module to compress object features into descriptors that capture inter-object relationships. By treating objects as nodes in a graph, the model understands how an object relates to its neighbors. It then uses the Sinkhorn algorithm (Optimal Transport) to match objects in the query image to those in the reference images.
4. Anomaly Measurement Model (AMM)
Finally, the system calculates an anomaly score. If an object cannot be matched, it is flagged as a logical anomaly (extra or missing). If an object is matched but its internal features differ significantly—measured via Mahalanobis distance—it is flagged as a structural anomaly.
Key Results and Insights
SAM-LAD sets new performance benchmarks, particularly in the detection of logical inconsistencies:
- MVTec LOCO AD: Achieved an image-level AUROC of 90.7, a substantial improvement over the previous state-of-the-art model, GLCF (83.1).
- DigitAnatomy: On this purely logical synthetic dataset, SAM-LAD reached 92.3 AUROC, representing a massive leap over the previous best of 78.6.
- Structural Robustness: Despite its focus on logic, the model remains highly competitive on standard structural benchmarks like MVTec AD (98.4 AUROC), proving its versatility.
Limitations and Future Work
The primary limitation of the current framework is segmentation granularity. SAM can sometimes segment objects too finely or too coarsely depending on the scene complexity. For instance, in a box of identical items, the matching logic can become confused because the objects lack distinct features, making it difficult to identify if a specific compartment has an extra item.
Future iterations may integrate "Grounded SAM" or the "Recognize Anything Model" (RAM) to provide semantic labels. This would allow the model to reason about specific object types (e.g., "the screw" vs. "the washer") rather than generic object masks, further enhancing its logical reasoning capabilities.
Summary updated