Rule Coherence as a Localization Signal: Logic-Aware Rescoring for Constrained Detectors

Object detectors used in driving are now often required to obey written rules about their labels. One example: a box cannot be both "pedestrian" and "car", and a "turning" action needs a compatible lane location. The standard fix is to let the network predict labels for each box, then pass them through a logic solver that flips the fewest, least-confident labels until every rule holds. This guarantees compliance, but it leaves a separate problem untouched. The confidence score that later ranks and filters boxes still comes from the raw classifier. Detection research has shown repeatedly that this score does not track how well the box is placed. After the solver has edited a box's labels, nothing tells the system how likely the edited detection is to be correct and well localized.

We propose to treat how badly a box's predicted labels break the rules as evidence about the box itself. A box that sits halfway between a cyclist and a parked car, or crops half a vehicle, tends to produce a mixed set of labels that cannot all be true together. The probability, under the network's own label distribution, that the rules are satisfied can be computed exactly and cheaply once the rules are compiled into a tractable circuit. A circuit here means a data structure that answers probability queries over logical formulas in time linear in its size. We feed that probability, together with a predicted localization quality, into a small monotone calibrator. Its output is the score used for suppression and thresholding, and it replaces the classifier confidence after the logic repair. The bet is that rule coherence carries localization information that neither the class score nor a predicted overlap captures. That would let one static detector reach better accuracy and calibration under full compliance, with no dynamically generated weights.

Core Claim

For a candidate box with class confidence $c$, predicted localization quality $q$ (an estimate of overlap with ground truth), label distribution $p(y)$ over the 41 ROAD-R labels, and rule set $K$, we compute two quantities with a compiled circuit. The first is the rule-satisfaction mass $P(K)=\sum_{y \models K} p(y)$. The second is the conditional probability of the solver's repaired labeling $y^\ast$, which is $P(y^\ast \mid K)=p(y^\ast)/P(K)$. We then fit a monotone calibrator to predict whether the repaired detection is a true positive at the evaluation overlap threshold:

$$s = g\big(c,\; q,\; P(K),\; P(y^\ast \mid K)\big),$$

Here $g$ is a function constrained to be non-decreasing in each argument, fitted on held-out data with the localization-aware target used by On Calibration of Object Detectors. The claim has three parts. First, $P(K)$ is correlated with localization error beyond what $c$ and $q$ explain. Second, ranking repaired boxes by $s$ improves frame-level mean average precision (f-mAP) and localization-aware calibration error at 100% rule compliance. Third, this comes at negligible cost: one circuit pass per pre-suppression candidate, batched on the GPU.

Where This Sits

Three lines of work motivate the gap. ROAD-R (ROAD-R) introduced a 243-rule driving benchmark. Its Weighted Partial MaxSAT solver repairs predictions in under a millisecond and guarantees compliance, but it acts only on label assignments and never touches box scores or coordinates. MOD-ECL (T-norm Selection) turns the rules into differentiable training losses through a bandit over 12 fuzzy-logic operators. It reports YOLOv8 f-mAP rising from 57.55 to 61.00 on ROAD-R, with per-box violations below 1% but not zero. Its class scores remain uncoupled from localization. In both papers the logic is a filter on labels. We instead use the logic as a measurement that feeds back into ranking.

The calibration literature supplies the method we build on. Generalized Focal Loss merges class score and predicted overlap into one quality score. Mask Scoring R-CNN and Fitness NMS multiply or rank by predicted overlap. On Calibration of Object Detectors shows that post-hoc isotonic regression fitted to overlap beats train-time calibration across 14 detectors, and it defines the localization-aware calibration errors (LaECE$_0$, LaACE$_0$) and the localization-recall-precision (LRP) error we will report. MoCaE shows that calibrating to overlap is what makes fusion of detectors work. None of these has access to relational label structure. Our calibrator is their isotonic approach with logical features added. The same paper also constrains us: it reports that post-hoc calibrators degrade under domain shift, so we test transfer across datasets explicitly.

On scalability, Semantic Probabilistic Layers and Pseudo-Semantic Loss supply the machinery. Exact circuit evaluation is linear in circuit size, and compilation is worst-case exponential. Where that blows up, local Hamming-1 neighborhoods around the predicted labeling give a tractable approximation. Our 41-variable propositional rule set is small, but we must evaluate it on thousands of candidates per frame before suppression. Whether exact compilation stays cheap at that throughput, and whether the local approximation preserves the signal, is the scalability question we actually face.

Dynamic weight generation enters as the competitor we expect to make unnecessary. Compliance2LoRA uses a small network to generate low-rank adapter weights for a frozen model, conditioned on which policies are active. Pareto HyperNetworks generate weights conditioned on a preference between objectives. Either could be adapted to a detection head to trade accuracy against compliance at runtime. Both pay a per-context generation pass and an extra training cost, and the output projection scales with the number of target parameters (Continual Model-Based RL with Hypernetworks). Our position is that in this regime, conditioning the cheap circuit and calibrator on the active rules recovers most of what conditioning the weights would. We test that claim directly rather than assume it.

Research Program

The first stage is a measurement study that can kill the idea early. On ROAD-R and ROAD-Waymo-R we run a YOLOv8 detector from the MOD-ECL codebase, in both its unconstrained form and its Product t-norm form. We record, for every pre-suppression candidate matched to ground truth, the true overlap, $c$, $q$, and the exactly computed $P(K)$. Here $q$ comes from an added quality branch trained with Quality Focal Loss. The test is whether $P(K)$ explains variance in true overlap and in true-positive status after conditioning on $c$ and $q$. We measure this by the gain in held-out log-likelihood of a logistic model when $P(K)$ is added, broken down by agent class and occlusion. The analysis is run separately on the logic-trained detector. Training with rule losses might push $P(K)$ toward 1 everywhere and erase the signal, and we need to know whether that happens.

The second stage builds the rescoring pipeline. The 243 (and 251) rules are compiled once into a sentential decision diagram, a type of tractable circuit. Its forward pass is implemented as batched tensor operations, so $P(K)$, the most probable valid labeling $y^\ast$, and $P(y^\ast \mid K)$ come out for all candidates in one pass. The repaired labeling is checked against MaxHS output for agreement. The calibrator $g$ is fitted on a held-out split as an additive monotone model, which is the natural extension of isotonic regression to a few inputs. Its output then drives Soft-NMS and score voting, following MoCaE. We profile circuit size, compile time, and per-frame latency. We also implement the pseudo-semantic Hamming-1 approximation of $P(K)$ as a fallback, and we measure how much signal it loses relative to the exact value. This gives a concrete reading on whether local approximations suffice for rule sets too large to compile.

The third stage is an optional training-time coupling. Here the per-box rule loss is weighted by the target overlap, so that background and badly placed boxes are not forced into label coherence. That forcing would destroy the very signal the calibrator reads. This variant is only worth reporting if it improves on the post-hoc pipeline.

Baselines

The naive reference is the unconstrained YOLOv8 detector ranked by raw class confidence, with MaxHS repair applied afterward so compliance is 100%. This is the cheapest compliant system anyone would deploy. It is what we must beat on f-mAP, LaECE$_0$ and LRP error at equal compliance.

The strongest existing method is MOD-ECL with the Product t-norm followed by MaxHS repair. MOD-ECL reports f-mAP of 61.00 on ROAD-R with YOLOv8, and the repair closes its remaining sub-1% violations. ROAD-R's own CLCO result (f-mAP 31.81 at 100% compliance) uses a different video backbone and is not directly comparable. We rerun MOD-ECL from its released code on our splits with the same backbone, input resolution and training epochs. We add the MaxHS stage and our rescoring on top of the same checkpoint, so any gain comes from the score alone. Beating it means a statistically reliable f-mAP gain over three seeds plus a lower LaECE$_0$, with compliance held at 100%. No reported calibration result on ROAD-R was found on Lacuna, so all calibration numbers there will be our own.

The calibration baseline is the strongest post-hoc recipe from On Calibration of Object Detectors and MoCaE. It is isotonic regression of the product $c \cdot q$ against overlap, fitted on the identical held-out split, then MaxHS repair, Soft-NMS and score voting. It uses exactly the same calibration data and fitting budget as our calibrator. The only difference is the absence of the two logic features, so this baseline is also the ablation that isolates the key ingredient. Two further ablations separate the two logic features: one gives the calibrator only $P(K)$, and one gives it only the unnormalized $p(y^\ast)$. The second asks whether the solver's own objective already contains the signal.

The dynamic-weight competitor is a hypernetwork that generates low-rank adapters for the detection head. It follows the Compliance2LoRA design and is conditioned either on a binary mask of active rule subsets or on a preference weight for the rule loss, as in Pareto HyperNetworks. It starts from the same backbone checkpoint and gets the same GPU-hour budget as MOD-ECL training. Our method beats it if, across held-out rule subsets and operating points, it matches the hypernetwork's accuracy-compliance curve within noise while adding less latency and training cost.

Why not just…?

Why not just calibrate the class score with isotonic regression and then run the solver? This is the most serious alternative, because the calibration literature shows simple post-hoc calibrators are hard to beat. It is exactly our main ablation. If adding $P(K)$ and $P(y^\ast \mid K)$ yields no gain over isotonic regression on $c \cdot q$, the core claim is false and we will report it as such. The one structural reason to expect a gain is that isotonic regression sees each box's score in isolation, while incoherence across the 41 labels is a property of the joint distribution that a scalar calibrator cannot see.

Why not just use the GFL-style quality score for ranking? Predicted overlap is learned from appearance. It can be confidently wrong on exactly the ambiguous boxes, such as straddling or partially visible agents, where label incoherence should appear. Every configuration of ours includes $q$, so the comparison asks whether rule coherence adds information on top of it. The per-class and occlusion breakdowns in the first stage show where that information lives.

Why not just tune the rule-loss weight or train MOD-ECL longer? MOD-ECL's gains come from better features, and our rescoring is applied on top of its checkpoint, so the two are complementary rather than competing. The risk is that rule-trained detectors make $P(K)$ uninformative by pushing it to 1. Stage one measures this directly on the MOD-ECL checkpoint. If the signal vanishes there, the method is limited to repairing unconstrained detectors, which is a weaker but still deployable result.

Why not just generate head weights with a hypernetwork conditioned on the active rules? It may genuinely win if changing the rules should change what the head attends to, not merely how its outputs are scored. Generation also adds a forward pass and training instability (Learning the Pareto Front with Hypernetworks), and Compliance2LoRA reaches only empirical compliance (0.976 safety rate), not a guarantee. The held-out-rule-subset experiment settles this. If the hypernetwork clearly dominates our curve, conditioning features is worth its overhead and we will say so.

Proposed Experiments and Decisive Checks

The primary benchmarks are ROAD-R and ROAD-Waymo-R, chosen because they are the only ones in our material that pair box detection with formal label rules. We report f-mAP, mean per-box violation before repair, LaECE$_0$, LaACE$_0$, LRP error at the model-chosen threshold, and per-frame latency of the circuit and calibrator stage. The first decisive check is the stage-one regression: if $P(K)$ gives no held-out likelihood gain over $c$ and $q$, we stop. The second is the main ablation against isotonic regression on $c \cdot q$ under the same split and the same repair. The third is cross-dataset transfer, fitting the calibrator on ROAD-R and evaluating on ROAD-Waymo-R restricted to shared rules. This probes the domain-shift weakness that the calibration literature reports for post-hoc methods. Logic features may plausibly transfer better than appearance-based ones, because the rules do not change between datasets.

The fourth check is rule-subset generalization against the hypernetwork. We drop random subsets of rules at test time, recondition the circuit, and compare accuracy-compliance curves and latency. The fifth is scalability: we compare exact against Hamming-1 estimates of $P(K)$ in both rank correlation and downstream f-mAP. We also report circuit size and throughput as the number of candidates grows. The goal is to show that rule-aware rescoring can run before suppression at frame rate, and where it would stop doing so for larger rule sets.