SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2309.14888 · ICCV · 2023

Nearest Neighbor Guidance for Out-of-Distribution Detection

Jaewoo Park, Andrew Beng, Jin Teoh, Yoon Gyo

arXiv · PDF · Open in the Atlas

Code that ran

6 of 8 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (2 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 4 have no contract verdict; 2 failures of our instrument; 2 no recorded run), measured 2026-11-24; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2309.14888.json · badge: /api/ran/2309.14888.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
jingkang50/openood marked official in Papers with Code
Papers with Code archive
5 ran · 0 no recorded run
roomo7time/nnguide marked official in Papers with Code
Papers with Code archive
1 ran · 2 no recorded run
FunctionStatusWhere it lives
BasePostprocessor Ran
ran on a synthesized input · constructed an object; no result was computed
jingkang50/openood/openood/postprocessors/nnguide_postprocessor.py
code served (permissive licence) · get_code("c308d7f79dfb5ace")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, BasePostprocessor: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
from torch.utils.data import DataLoader

torch.manual_seed(0)

# Create a minimal config
config = {
    "num_classes": 4,
    "threshold": 0.5
}

# Create a minimal neural network that outputs logits
class SimpleNet(nn.Module):
    def __init__(self, num_classes=4):
        super().__init__()
        self.linear = nn.Linear(5, num_classes)
    
    def forward(self, x):
        return self.linear(x)

net = SimpleNet(num_classes=4)

# Create minimal batch data with 'data' and 'label' keys
batch_data = {
    'data': torch.randn(2, 5),
    'label': torch.tensor([0, 1])
}

# Create a minimal DataLoader-like object (list of batches)
id_loader_dict = {
    'train': [batch_data.copy() for _ in range(2)]
}

ood_loader_dict = {
    'test': [batch_data.copy() for _ in range(2)]
}

ARGS = {
    'config': config
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, tqdm — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type BasePostprocessor — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a BasePostprocessor output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
NNGuidePostprocessor Ran
ran on a synthesized input · constructed an object; no result was computed
jingkang50/openood/openood/postprocessors/nnguide_postprocessor.py
code served (permissive licence) · get_code("1e5c62cec24c56e4")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, NNGuidePostprocessor: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
import numpy as np
from unittest.mock import MagicMock

torch.manual_seed(0)

# Create a minimal config object
class Config:
    def __init__(self):
        self.postprocessor = MagicMock()
        self.postprocessor.postprocessor_args = MagicMock()
        self.postprocessor.postprocessor_args.K = 5
        self.postprocessor.postprocessor_args.alpha = 0.8
        self.postprocessor.postprocessor_sweep = {}

# Create a minimal neural network that supports return_feature
class SimpleNet(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear1 = nn.Linear(4, 8)
        self.linear2 = nn.Linear(8, 3)  # 3 classes
    
    def forward(self, x, return_feature=False):
        feat = torch.relu(self.linear1(x))
        logit = self.linear2(feat)
        if return_feature:
            return logit, feat
        return logit

# Create simple data loaders
class SimpleDataLoader:
    def __init__(self, num_samples=4, batch_size=2):
        self.batch_size = batch_size
        self.num_samples = num_samples
        self.dataset = MagicMock()
        self.dataset.__len__ = MagicMock(return_value=num_samples)
    
    def __iter__(self):
        for i in range(0, self.num_samples, self.batch_size):
            data = torch.randn(min(self.batch_size, self.num_samples - i), 4)
            label = torch.randint(0, 3, (min(self.batch_size, self.num_samples - i),))
            yield {
                'data': data,
                'label': label
            }
    
    def __len__(self):
        return (self.num_samples + self.batch_size - 1) // self.batch_size

# Create loaders
id_loader_dict = {
    'train': SimpleDataLoader(num_samples=6, batch_size=2),
    'val': SimpleDataLoader(num_samples=4, batch_size=2)
}

ood_loader_dict = {
    'test': SimpleDataLoader(num_samples=4, batch_size=2)
}

net = SimpleNet()

config = Config()

ARGS = {
    'config': config,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
faiss, numpy, scipy, torch, tqdm — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type NNGuidePostprocessor — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a NNGuidePostprocessor output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_rank Ran
ran on a synthesized input
jingkang50/openood/openood/postprocessors/nnguide_postprocessor.py
code served (permissive licence) · get_code("4f1cf6e198d885d2")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned int, ndim 0, dtype family int, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.distributed as dist

torch.manual_seed(0)

# The function get_rank() takes no parameters
# It only checks dist availability and initialization status
# No arguments are needed to call it

ARGS = {}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type int, ndim 0, dtype family int, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
is_main_process Ran
ran on a synthesized input
jingkang50/openood/openood/postprocessors/nnguide_postprocessor.py
code served (permissive licence) · get_code("3305c78c72a2232b")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned bool, ndim 0, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# The function is_main_process() takes no parameters
# It internally calls get_rank() which checks distributed training status
# Since we're not setting up actual distributed training, get_rank() will return 0
# and is_main_process() will return True

ARGS = {}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type bool, ndim 0, dtype family float — no output shape is stated: observe_signature.py could not observe it (no_inputs)
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
knn_score Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
jingkang50/openood/openood/postprocessors/nnguide_postprocessor.py
code served (permissive licence) · get_code("e3a7b669b8599e08")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned ndarray, ndim 1, dtype family float, shape (3,) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np
import torch

torch.manual_seed(0)

# Create small feature tensors
# bankfeas: features for the database/bank
# queryfeas: features for the queries
# Both should be 2D arrays where last dimension is the feature dimension

# Using distinct sizes: batch=2, feature_dim=4 for bank, batch=3 for queries
bankfeas = np.random.randn(2, 4).astype(np.float32)
queryfeas = np.random.randn(3, 4).astype(np.float32)

# k: number of nearest neighbors to retrieve
k = 100

# min: whether to use min or mean of the k distances
min_flag = False

ARGS = {
    "bankfeas": bankfeas,
    "queryfeas": queryfeas,
    "k": k,
    "min": min_flag,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
faiss, numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ndarray, ndim 1, dtype family float, shape (3,) — shape (3,) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
knn_score Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
roomo7time/nnguide/ood_detectors/nnguide.py
code served (permissive licence) · get_code("a8d49b0c1c2c5802")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned ndarray, ndim 1, dtype family float, shape (2,) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import numpy as np
import faiss

# Create small feature matrices for training and testing
np.random.seed(0)

# feas_train: training features for building the index
# Shape (5, 4) - 5 samples, 4 dimensions
feas_train = np.random.randn(5, 4).astype(np.float32)

# feas: query features
# Shape (2, 4) - 2 samples, 4 dimensions
feas = np.random.randn(2, 4).astype(np.float32)

# k: number of neighbors to retrieve
k = 3

# min: whether to use min or mean of distances
min_flag = False

ARGS = {
    "feas_train": feas_train,
    "feas": feas,
    "k": k,
    "min": min_flag,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
faiss, numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ndarray, ndim 1, dtype family float, shape (2,) — shape (2,) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
NNGuideOODDetector Not yet run
unverified (harvested, no recorded run)
roomo7time/nnguide/ood_detectors/nnguide.py
code served (permissive licence) · get_code("95b2f6eda760158c")
How it ran

no invocation recorded.

OODDetector Not yet run
unverified (harvested, no recorded run)
roomo7time/nnguide/ood_detectors/nnguide.py
code served (permissive licence) · get_code("bb0a165703b4bc07")
How it ran

no invocation recorded.

Also present in other papers' code

Of 8 samples lifted from this paper's linked repositories, 8 carry a function identity and 0 do not. Of the 8 distinct functions with an identity, 3 are also present in other papers whose code we hold (3 with at least one paper dated earlier, 0 the same month, 3 later) and 5 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
get_rank
brick of this paper's assembly: helper
7 other papers
2 dated earlier, 5 later · 6 only as an assembly brick
1706.02690 (2017-06)
Enhancing The Reliability of Out-of-distribution Image Detection in Neural Networks
2203.10807 (2022-03)
ViM: Out-Of-Distribution with Virtual-logit Matching
2310.09449 (2023-10)
Pairwise Similarity Learning is SimPLE
and 4 more not named here
is_main_process
brick of this paper's assembly: helper
7 other papers
2 dated earlier, 5 later · 6 only as an assembly brick
1706.02690 (2017-06)
Enhancing The Reliability of Out-of-distribution Image Detection in Neural Networks
2203.10807 (2022-03)
ViM: Out-Of-Distribution with Virtual-logit Matching
2406.09867 (2024-06)
Rethinking the Evaluation of Out-of-Distribution Detection: A Sorites Paradox
and 4 more not named here
BasePostprocessor
brick of this paper's assembly: helper
5 other papers
1 dated earlier, 4 later · 4 only as an assembly brick
2203.10807 (2022-03)
ViM: Out-Of-Distribution with Virtual-logit Matching
2406.09867 (2024-06)
Rethinking the Evaluation of Out-of-Distribution Detection: A Sorites Paradox
2406.15104 (2024-06)
Deciphering the Definition of Adversarial Robustness for post-hoc OOD Detectors
and 2 more not named here

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-24.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Detecting out-of-distribution (OOD) samples are crucial for machine learning models deployed in open-world environments. Classifier-based scores are a standard approach for OOD detection due to their fine-grained detection capability. However, these scores often suffer from overconfidence issues, misclassifying OOD samples distant from the in-distribution region. To address this challenge, we propose a method called Nearest Neighbor Guidance (NNGuide) that guides the classifier-based score to respect the boundary geometry of the data manifold. NNGuide reduces the overconfidence of OOD samples while preserving the fine-grained capability of the classifier-based score. We conduct extensive experiments on ImageNet OOD detection benchmarks under diverse settings, including a scenario where the ID data undergoes natural distribution shift. Our results demonstrate that NNGuide provides a significant performance improvement on the base detection scores, achieving state-of-the-art results on both AUROC, FPR95, and AUPR metrics.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2309.14888")
get_code_for_paper("2309.14888")
have("2309.14888")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2309.14888.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2309.14888.svg)](https://syntology.ai/paper/2309.14888)

Connect an agent — have() is free.