Repair-Guided Synthesis of Logical Anomalies in Feature Space

Some factory defects are not scratches or dents but broken rules. A breakfast box holds two tangerines instead of one. A screw bag is missing a washer. A cable is plugged into the wrong slot. In these images every local patch looks perfectly normal, so detectors that learn "normal" by pushing image features slightly off their usual values never see a training example of this failure. This proposal treats each image's detected parts as a small, noisy database of facts. It borrows two tools from database theory for handling inconsistent data: the repair, a largest subset of facts that satisfies all the rules, and the minimal conflict, a smallest subset of facts that already breaks a rule. These tools are used to learn the scene's rules from defect-free images, to manufacture realistic rule-breaking examples directly in feature space, and to score test images by how much must be discarded to make them consistent.

The opportunity exists because two mature lines of work have never met. Feature-space anomaly synthesis is fast and accurate for surface defects. Corrupting backbone features with Gaussian noise and training a small discriminator reaches 99.6% image-level AUROC (area under the ROC curve) on MVTec AD at 77 FPS (SimpleNet). But it cannot express "wrong count" or "impossible combination." Inconsistency-tolerant query answering, meanwhile, has spent decades on exactly this question: how to reason soundly over facts that violate constraints without letting one contradiction ruin everything. It has stayed entirely symbolic. In two sentences: mine part-level rules from normal images while tolerating segmentation errors, then train a detector on feature-space edits that break exactly one rule by the smallest possible margin. The repair formalism supplies the rule miner, the hard-negative generator, and a localized explanation of every flagged image.

Core Claim

The claim is that logical anomaly synthesis should target the boundary between consistent and inconsistent part configurations, and that repair semantics is the right tool for locating that boundary when the facts come from imperfect perception. Concretely, each image $I$ is turned into a fact base $F(I)$ of part assertions. Each fact is a part type, a coarse position or slot, and a confidence. They come from an unsupervised part decomposition like the one in SALAD. Rules $C$ come from a small constraint language: count bounds per part type, functional dependencies such as "a slot determines its part type," inclusion dependencies such as "if a connector is present, a cable is present," and pairwise denial constraints. Given weights $w(f)$ that grow with perception confidence, the weighted cardinality-repair cost of an image is

$$ \rho(I) = \min_{R \subseteq F(I),\; R \models C} \; \sum_{f \in F(I) \setminus R} w(f), $$

the cheapest set of facts whose removal makes the image consistent with the rules. Missing-part rules are handled symmetrically by allowing weighted insertion of facts, which keeps the measure a repair distance and not just a deletion count. This is a perception-weighted version of the preferred and cardinality-based repairs studied in Complexity of Inconsistency-Tolerant Query Answering in Datalog+/- under Cardinality-Based Repairs and Querying Inconsistent Description Logic Knowledge Bases under Preferred Repair Semantics.

The repair framing does three jobs. First, it makes rule mining robust. A candidate rule is kept if nearly all normal training images admit a low-cost repair under it, so a rule is not thrown away because the segmenter split one pushpin in two. Second, it defines hard negatives. A synthetic anomaly is a feature-space edit (deleting, duplicating, or transplanting a part's feature tokens) whose result contains a minimal conflict of size one or two and whose repair cost sits just above the normal range. Third, it gives localization and explanation for free. The facts outside the intersection of all minimum-cost repairs are the disputed parts, in the spirit of IAR semantics (Complexity of Inconsistency-Tolerant Query Answering in Datalog+/-) and of the explanation work in Explanations for Negative Query Answers under Inconsistency-Tolerant Semantics.

Worst-case complexity is not a concern here. The co-NP-hardness of repair-based answering is in data complexity over large databases. Our fact bases have tens of facts, so minimum-cost repairs are solved exactly with a small integer program in milliseconds.

Position Relative to Prior Work

The closest work is a family of logical-anomaly synthesizers that mutate scenes at random. SALAD erases or swaps segments in predicted composition maps. LogicAL removes, replaces, and merges edge fragments and renders them back to pixels with a GAN. ComGEN deletes prompt tokens during diffusion. These papers motivate this proposal: they show that synthetic logical defects help. They also leave its gap open, because none checks whether a mutation actually violates a scene rule. Many random swaps produce configurations that are still normal, and these become label noise. Many others are gross violations that teach nothing about the boundary. Two of the three pay for full image rendering.

Our edits happen on part-level feature tokens, as in SimpleNet-style training, so no pixels are generated. They are accepted only if a repair solver certifies a minimal violation. Boundary-seeking synthesis already exists for continuous features. Progressive Boundary Guided Anomaly Synthesis pushes noise radially to the edge of the normal cluster, and CRAS scales noise by distance to the cluster center. We carry the same idea into the discrete relational space, where those methods cannot reach.

Two detectors handle logical anomalies without synthesis and constrain the design. PSAD stores part-count histograms in a memory bank and reaches 98.1% logical AUROC, but it needs few-shot part annotations. GLCF learns global relations through a transformer bottleneck. PSAD is the reason the "just count" alternative must be taken seriously below.

On the logic side, An Embedding-based Approach to Inconsistency-tolerant Reasoning supplies a method we reuse in spirit. It uses embedding similarity to decide which maximal consistent subset to trust. We instead use perception confidence and feature density to set fact weights, so that the repair blames the least reliable detection. Computing Repairs Under Functional and Inclusion Dependencies via Argumentation shows that repairs under exactly our dependency types are well characterized, which justifies restricting the rule language to them.

Finally, AR-Pro uses "repair" in the continuous sense: it builds counterfactual normal images by guided diffusion, taking about 40 hours on VisA. Our repair is a discrete counterfactual ("remove this second tangerine") that is computed instantly and used during training, not only after detection.

Research Program

The first component is the fact extractor. We reuse SALAD's label-free route: SAM-HQ segments, DINO clustering into part types, and a UNet predicting composition maps. Each connected component becomes a fact carrying its pooled backbone feature token, its slot (a quantized position relative to the object frame), and a confidence. The confidence is the clustering margin times the segment-quality score. Holding the extractor fixed lets us attribute gains to the synthesis and scoring, not to better segmentation.

The second component is tolerant rule mining. We enumerate candidate rules in the four constraint families from per-type statistics on normal images. Each candidate is kept if the 95th-percentile repair cost it induces on held-out normal images stays below a tolerance $\tau$. Rules are added greedily, in order of how much they would increase the cost of a random-edit image. This keeps only rules that normal data respects, up to perception noise, and that actually discriminate.

The third component is repair-guided synthesis. For each normal training image we propose edits to its token set: delete a part token, duplicate one, transplant a token from another normal image, or move a token to a different slot. We keep an edit only if the edited fact base has a minimal conflict of size at most two and a repair cost in a band just above the normal 95th percentile. The band is set by quantiles of the normal cost distribution rather than a hand-tuned noise scale, which addresses the scale sensitivity SimpleNet reports for its Gaussian $\sigma$.

The fourth component is the detector. A small set transformer over part tokens is trained to separate normal token sets from certified violations. It runs alongside a SimpleNet-style patch branch for structural defects. The final score is

$$ s(I) = \alpha\, \hat\rho(I) + \beta\, d_{\text{set}}(I) + \gamma\, d_{\text{patch}}(I). $$

Here $\hat\rho$ is the repair cost standardized on normal validation images, $d_{\text{set}}$ is the set-discriminator output, $d_{\text{patch}}$ is the patch-branch output, and $\alpha$, $\beta$, $\gamma$ are fit on normal validation data only, by matching score variances. For localization, pixels of disputed facts inherit the repair score and other pixels inherit the patch score.

Baselines

The naive reference point is SimpleNet run unchanged on MVTec LOCO: Gaussian feature noise and an MLP discriminator, with no part-level reasoning (SimpleNet). It shows how much of the logical-anomaly gap a pure geometric synthesizer leaves. We run it with the same backbone and image resolution as our patch branch and tune $\sigma$ over the same grid we use for our cost band. A large gap on logical AUROC and parity on structural AUROC is the expected result. Failing to beat it on logical anomalies would sink the proposal.

The strongest label-free competitor is SALAD, which reports 96.1% mean AUROC and 96.5% logical AUROC on MVTec LOCO (SALAD). It is the strongest competitor because it shares our fact extractor and differs mainly in synthesizing logical defects by random erase and swap. We rerun it from its released configuration so both systems see identical composition maps, backbones, and training epochs. We also quote its reported figures. Beating it means exceeding 96.5% logical AUROC with structural AUROC no lower than SALAD's, averaged over three seeds with non-overlapping standard errors.

The strongest method overall is PSAD at 98.1% logical AUROC and 91.6% structural AUROC (PSAD). It uses few-shot part annotations, so we compare in two regimes. In the label-free regime we report the gap to PSAD honestly. In a matched regime we give our extractor the same few-shot annotations. Matching or exceeding 98.1% under matched supervision counts as beating it. ComGEN (91.2% AUROC on LOCO) and LogicAL (69.7 pixel AU-sPRO) are the generative-synthesis references for detection and localization respectively.

Three ablations isolate the key ingredient. The first is "random edits in token space": the same feature-space edits without the certification filter. It separates the effect of moving to feature space from the effect of repair guidance. The second is "hard rules": mining without tolerance, so any violation on a normal image discards the rule, with unweighted counting. It isolates the inconsistency-tolerant part. The third is "repair cost only," which sets $\beta = 0$ and asks whether the trained set discriminator adds anything beyond the symbolic score. All ablations share data, extractor, and a fixed GPU-hour budget per category.

Why not just…?

Why not just keep SALAD's random erase-and-swap, since it already works? It is a real threat, because 96.5% leaves little headroom. Our argument is that random swaps of same-type parts often produce normal configurations, which are mislabeled negatives, while others are trivially easy. The token-space random-edit ablation tests this directly. We will also report the fraction of SALAD-style mutations that our solver certifies as consistent. If that fraction is small and certification gives no gain, the minimal-conflict idea fails and we will say so.

Why not just count parts and compare against a reference histogram, as PSAD's memory bank does? Counting is one of our four rule families, so on count-only categories we expect to tie. The difference is twofold. Histograms cannot express functional or inclusion dependencies, such as a correct cable count in the wrong slot. Hard counting is also brittle to segmentation errors, which is exactly what tolerant repairs address. The decisive test is the segmentation-noise sweep below. It injects controlled split, merge, and drop errors into the facts and compares degradation of histogram matching, hard rules, and weighted repairs.

Why not just use the repair cost as the detector and skip synthesis entirely? This may well work nearly as well on MVTec LOCO, whose rules are simple. The repair-cost-only ablation measures it. The case for synthesis is generalization to violations the miner did not capture and to interactions between appearance and relations. We test that by withholding one rule family during mining and checking whether the discriminator, trained on violations of the remaining families, still catches the held-out anomaly types better than $\hat\rho$ alone. If it does not, the right conclusion is that the repair scorer, not the synthesizer, is the contribution, and we will report it that way.

Why not just render logical defects as images, as ComGEN or LogicAL do? Rendering costs heavy generation per sample and adds pixel artifacts. Feature-space edits cost a forward pass. We will report training wall-clock and inference latency next to SALAD's 64.6 ms per image and SimpleNet's 77 FPS, and require that we stay within SALAD's inference budget.

Proposed Experiments

The main benchmark is MVTec LOCO AD across its five categories. We report image AUROC split by logical and structural anomalies, and pixel AU-sPRO for localization against LogicAL's 69.7. MVTec AD serves as a regression check that the structural branch keeps SimpleNet-level performance. The SimpleNet paper reports 99.6% I-AUROC, and we require no more than a small drop given our shared backbone. VisA is used for its multi-instance categories as a check that rule mining does not fire spuriously where there are few relational rules. The file contains no reported number on Lacuna for SALAD or CRAS on VisA, so those must be rerun.

Three checks decide the proposal. First, certified minimal-violation synthesis must beat uncertified token edits on logical AUROC under identical budgets. Second, under the segmentation-noise sweep, the weighted-repair scorer must degrade more slowly than hard rules and histogram matching. This is the claim that inconsistency tolerance earns its place. Third, on held-out rule families, the set discriminator must add detection beyond the repair cost. On a sample of flagged test images we will also check whether the disputed facts named by the repair match the annotated defect regions. That would give each logical alarm an explanation of the form "this part breaks rule $c$" at no extra cost.