Open-Set Recognition by Inverting a One-Step Class-Conditional Generator

Image classifiers trained on a fixed list of categories have no way to say "none of the above." Their final layer spreads all of its confidence across the known classes, so a picture of something never seen in training is confidently assigned to whichever known class it most resembles. One family of fixes asks a different question: can a generative model of each known class reproduce this input? If no known class can produce it, reject it. Current versions of this idea answer the question with a single encoder pass. An encoder network guesses a compact code for the input, and the method measures how badly the decoder reconstructs it. Work on learned image compression shows that such single-pass guesses are systematically suboptimal on atypical inputs. So a large reconstruction error may only mean the encoder guessed poorly, not that no good code exists. The direct remedy is to search for the best code by gradient descent at test time. That search has usually been too slow for recognition, because each step backpropagates through a heavy decoder or through a many-step diffusion sampler.

We propose making that search cheap and principled. The plan is to train a one-step generator in a compact semantic feature space, one that maps random noise plus a class label to a feature vector in a single network evaluation. At test time, for the few classes a standard classifier proposes, we run a short gradient search over the noise input. The aim is to find the cheapest code (in bits under the generator's prior) that reproduces the input's features. The per-class optimum of this rate-plus-distortion cost does two jobs at once: its argmin is the predicted class, and its minimum value is the rejection score. The claim is narrow and testable. Closing the encoder's inference gap should mainly rescue hard known samples that single-pass methods wrongly reject, while the rate penalty stops the search from also "explaining" unknowns. A one-step generator should keep the whole procedure within a few milliseconds per image.

Core Claim

The mechanism has three parts, each taken from a different direction. Test-time latent optimization comes from neural compression. Improving Inference for Neural Image Compression splits the suboptimality of encoder-based inference into amortization, discretization and marginalization gaps. Refining the encoder's code by gradient descent recovers 15% bitrate on Kodak and 20% on Tecnick with frozen networks. Content Adaptive Optimization for Neural Image Compression and Variable Rate Image Compression with Content Adaptive Optimization likewise show that per-image search over codes beats the encoder's guess. These papers supply the method and motivate the hypothesis. If the encoder's error is large on atypical inputs in compression, it is likely large on atypical known-class images in recognition.

The cost being minimized also comes from compression, and it is what separates this proposal from a plain "optimize until reconstruction is good" scheme. Let $f(x)$ be the frozen multi-layer pooled feature vector of image $x$, and let $G(\epsilon, c)$ be a one-step class-conditional generator mapping a standard Gaussian code $\epsilon$ and class $c$ to feature space. For each candidate class $c$, the score is

$$s_c(x) = \min_{\epsilon} \; \frac{\lVert f(x) - G(\epsilon, c)\rVert^2}{2\sigma^2} + \lambda \frac{\lVert \epsilon \rVert^2}{2},$$

where $\sigma$ is a fixed feature-noise scale, the second term is the negative log-density of the code under the Gaussian prior (its "rate" in nats, up to a constant), and $\lambda$ trades the two. The prediction is $\arg\min_c s_c(x)$, and the input is rejected when $\min_c s_c(x)$ exceeds a threshold set on known-class validation data. The rate term addresses the "reconstruction dilemma" noted by Diffusion-based Layer-wise Semantic Reconstruction for Unsupervised Out-of-Distribution Detection, in which flexible models reconstruct unknowns too well. An unknown can sometimes be matched in features, but only by pushing $\epsilon$ into low-prior regions, and that cost is paid in the score.

The latency constraint comes from one-step generative modeling. Mean Flows for One-step Generative Modeling learns an average velocity field instead of the usual instantaneous one, which lets it generate in a single evaluation without distillation (1-NFE FID 3.43 on ImageNet 256×256). We use the same training rule in a roughly 720-dimensional feature space, the dimensionality DLSR found sufficient. Each gradient step on $\epsilon$ is then one forward and one backward pass through a small network rather than through a full sampling trajectory. The same average-velocity field can be applied in reverse, from data at time 0 to noise at time 1, which gives a free one-step initial guess for $\epsilon$. The generator therefore acts as its own encoder, and the gradient steps close whatever gap that guess leaves. How MeanFlow's reverse map behaves on out-of-distribution inputs has not been studied, and measuring it is part of the work.

Research Program

The first stage builds the pieces. A frozen backbone (an EfficientNet-style network as in DLSR, plus a ViT for the fine-grained setting) provides features. A linear classifier on those features proposes the top-$m$ classes, with $m$ around 5. A single class-conditional MeanFlow MLP is trained on known-class features only. Sharing one conditional network across classes avoids the per-class autoencoders that make Class-Specific Semantic Reconstruction for Open Set Recognition scale linearly with the number of classes. At test time the $m$ class-conditional searches run as one batch of 5–20 Adam steps each, from the reverse-map initialization.

The second stage is diagnostic and carries most of the scientific content. We will measure the score drop from step 0 to step $k$ separately for typical known samples, atypical known samples, near unknowns and far unknowns. Atypical knowns are those misranked by the encoder-only score; near and far unknowns are the CUB "hard" and "easy" splits and CIFAR-100 versus SVHN against CIFAR-10. The hypothesis holds only if the drop is largest for atypical knowns and remains small for unknowns once $\lambda > 0$. We will also test the idea, absent from existing open-set work, that optimization dynamics carry signal. Following the suggestion that static scores ignore how hard it is to reach the known manifold, we will record gradient norms and convergence speed as extra features and see whether they add anything beyond the final $s_c$.

The third stage maps the accuracy–latency frontier. We sweep the step count $k$, the shortlist size $m$ and $\lambda$, and report images per second on fixed hardware next to every accuracy number.

Baselines

The naive reference point is maximum softmax probability thresholding on the same backbone and linear head. Every other method is reported against it. Towards Open Set Deep Networks shows why it is weak: OpenMax, which fits extreme-value tail models to distances from per-class mean activations, gave a 12.3% absolute F-measure gain over softmax on ImageNet 2012 plus unseen 2010 classes and fooling images. OpenMax itself is the classic calibrated competitor, run on our features with its tail size tuned on known-class validation data only.

The strongest reconstruction-based competitor is CSSR, which places class-specific autoencoders on deep feature maps and scores belongingness by L1 reconstruction error and Gram statistics. It reports an 8.3% macro-F1 gain on CIFAR-10, 97.9% AUROC on SVHN and more than 10% TNR@TPR95 gain on ImageNet-1000. It is the strongest competitor here because it uses the same "can the class model reproduce this?" test, only with a single encoder pass. Beating it on its own CIFAR-10 split and ImageNet protocol, using the same backbone features, is the main bar. Classification-Reconstruction Learning for Open-Set Recognition (CROSR, joint classification and hierarchical reconstruction, macro-F1 0.793 on MNIST with Omniglot outliers versus 0.680 for OpenMax, at 3–5 ms per image) sets both the small-benchmark bar and the latency budget we aim to stay within.

On the generative side, DLSR runs diffusion reconstruction on fixed pooled features and reports 99.7% AUROC on CIFAR-10 at 999 images per second. It is the throughput reference and the closest architectural relative, but it solves unsupervised binary detection, not known-class classification. We will rerun it on the open-set splits with our backbone and report both closed-set accuracy and AUROC. Out-of-Distribution Detection with a Single Unconditional Diffusion Model (DiffPath, which scores the curvature of a probability-flow path in 10 network evaluations, 0.931 average AUROC with a CelebA base model) is the passive-trajectory reference. For fine-grained recognition the reference is Latent Space Energy-based Model for Fine-grained Open Set Recognition, at 88.49% AUROC on easy CUB unknowns with 93.55% closed-set accuracy, a result obtained with slow MCMC sampling.

The ablations that isolate the key ingredient use the identical trained generator. Setting $k=0$ gives the encoder-only score from the reverse map, a direct analogue of CSSR. Setting $\lambda=0$ tests whether the rate term is what prevents unknowns from being explained. A multi-step flow-matching generator searched with the same wall-clock budget tests whether the one-step model matters. All methods get the same features, the same known-class training data and an equal hyperparameter search budget tuned on known-class validation data only, with no unknown samples used for tuning. Beating the field means matching or exceeding CSSR's reported CIFAR-10 macro-F1 and ImageNet TNR@TPR95 while staying within about 10 ms per image. The $k=0$ ablation must also lose by a margin larger than seed variance.

Why not just…?

Why not just threshold softmax or logits more carefully? Thresholding is the free option, and a well-tuned version could be competitive on far unknowns. The evidence in OpenMax's 12.3% gain, and the Stream-51 finding (Stream-51: Streaming Classification and Novelty Detection from Videos) that closed-set skill does not yield novelty detection, says it fails where the closed-world constraint bites. We expect the gap to be widest on CUB hard unknowns and on CIFAR-10 versus CIFAR-100. If temperature-scaled logits match our method there, the proposal has no case. The softmax baseline is run on the identical head precisely so that this can be checked.

Why not just use single-pass reconstruction, as CSSR or DLSR do? This is the real threat. Test-time search makes the generator more expressive, and it could lower scores for unknowns as much as for knowns, which would cancel any benefit. The $k=0$ and $\lambda=0$ ablations settle it directly. The idea survives only if search shrinks scores mainly on atypical knowns and the rate term keeps unknowns expensive. If the score drop is uniform across groups, we will report that test-time inference does not help open-set recognition. That negative result would itself bear on the compression-inspired argument.

Why not just train a better encoder, or precompute a steering direction? Amortized Latent Steering: Low-Cost Alternative to Test-Time Optimization replaces per-query search with a precomputed vector nudge and gets 2–5× speedups for language-model reasoning. That vector is fit to known failure modes, however, and unknown classes have no such profile. A stronger encoder can shrink the amortization gap on training-like data. The compression results suggest it cannot remove the gap on atypical inputs, which is exactly where open-set errors concentrate. To test this, we will train the reverse map with twice the capacity and compare its $k=0$ score against our $k$-step score at equal latency.

Why not just search through a full diffusion model, as in diffusion inversion? Precise Diffusion Inversion: Towards Novel Samples and Few-Step Models shows that per-step latent optimization inverts even novel samples faithfully, but it takes about 5.33 s per image, roughly three orders of magnitude over a recognition budget. The multi-step ablation measures how much accuracy that cost buys in feature space.

Why not just use nearest-neighbour or Gaussian distance in feature space? It is a simple and often strong rival. No reported result was found on Lacuna for it on these splits, so we will run it on identical features. If it matches our method, the generator adds nothing.

Proposed Experiments

Experiments cover MNIST with Omniglot outliers (macro-F1, against CROSR's 0.793), the CIFAR-10 known/unknown split and SVHN protocol used by CSSR (macro-F1 and AUROC), CIFAR-10 against CIFAR-100 and SVHN as unknowns (AUROC, against DLSR), CUB-200-2011 with easy and hard unknowns (AUROC and closed-set accuracy, against 88.49% and 93.55%), and ImageNet-1k with TNR@TPR95 following CSSR plus the ImageNet 2010 unseen-class protocol from OpenMax. Every table reports images per second on one GPU alongside DLSR's 999 and CROSR's 3–5 ms.

Three results decide the proposal. The first is a gain over the $k=0$ ablation that is concentrated on hard knowns and near unknowns. The second is a collapse of that gain when $\lambda=0$, which would confirm that the rate term is what keeps unknowns out. The third is that the one-step generator matches the multi-step generator's accuracy at a fraction of its latency. If the first fails, latent search does not help recognition. If the second fails, the compression-style cost is not doing the work we claim. If the third fails, one-step generation is the wrong place to spend effort.