SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2304.11855 · CVPR · 2023

Glocal Energy-based Learning for Few-Shot Open-Set Recognition

Peng Wang, Lei Zhang, Haoyu Wang, Guansong Pang, Yanning Zhang, Wei Wei

arXiv · PDF · Open in the Atlas

Code that ran

3 of 5 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (1 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 3 have no contract verdict; 0 failures of our instrument; 2 no recorded run), measured 2026-11-23; 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/2304.11855.json · badge: /api/ran/2304.11855.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
00why00/glocal marked official in Papers with Code
Papers with Code archive
3 ran · 2 no recorded run
FunctionStatusWhere it lives
EnergyLoss Ran
ran on a synthesized input
00why00/glocal/model/models/glocal_energy.py
code served (permissive licence) · get_code("ee73acfcbc9f8d1d")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned tuple. The image it ran in was 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 torch.nn.functional as F

# Mock AutomaticWeightedLoss for testing
class AutomaticWeightedLoss(nn.Module):
    def __init__(self, args, num_losses):
        super(AutomaticWeightedLoss, self).__init__()
        self.num_losses = num_losses
        self.weights = nn.Parameter(torch.ones(num_losses))
    
    def forward(self, loss1, loss2):
        return loss1 * torch.sigmoid(self.weights[0]) + loss2 * torch.sigmoid(self.weights[1])

# Patch the import
import sys
from types import ModuleType
model_module = ModuleType('model')
loss_module = ModuleType('loss')
loss_module.automatic_weighted_loss = ModuleType('automatic_weighted_loss')
loss_module.automatic_weighted_loss.AutomaticWeightedLoss = AutomaticWeightedLoss
model_module.loss = loss_module
sys.modules['model'] = model_module
sys.modules['model.loss'] = loss_module
sys.modules['model.loss.automatic_weighted_loss'] = loss_module.automatic_weighted_loss

class EnergyLoss(nn.Module):

    def __init__(self, args):
        super(EnergyLoss, self).__init__()
        self.args = args
        if args.ahead_combine:
            from model.loss.automatic_weighted_loss import AutomaticWeightedLoss
            self.awl = AutomaticWeightedLoss(args, 2)
        if args.learnable_margin:
            assert args.ahead_combine
            self.m_in = torch.nn.Parameter(-torch.ones(1, requires_grad=True))
            self.m_out = torch.nn.Parameter(torch.ones(1, requires_grad=True))

    def forward(self, f_klogits, f_ulogits, e_klogits, e_ulogits):
        args = self.args
        energy_loss_scale = 0.1
        if args.ahead_combine:
            k_energy_score = -torch.logsumexp(f_klogits, dim=1)
            u_energy_score = -torch.logsumexp(f_ulogits, dim=1)
            k_logits_score = -torch.logsumexp(e_klogits, dim=1)
            u_logits_score = -torch.logsumexp(e_ulogits, dim=1)
            k_energy_score = self.awl(k_energy_score, k_logits_score)
            u_energy_score = self.awl(u_energy_score, u_logits_score)
            if args.learnable_margin:
                l_energy = (torch.pow(F.relu(k_energy_score - self.m_in), 2).mean() + torch.pow(F.relu(self.m_out - u_energy_score), 2).mean()) * energy_loss_scale + torch.pow(F.relu(self.m_in - self.m_out), 2)
            else:
                l_energy = (torch.pow(F.relu(k_energy_score - args.m_in), 2).mean() + torch.pow(F.relu(args.m_out - u_energy_score), 2).mean()) * energy_loss_scale
        else:
            if args.energy_method == 'sum':
                k_energy_score = -torch.logsumexp(f_klogits, dim=1)
                u_energy_score = -torch.logsumexp(f_ulogits, dim=1)
            else:
                k_energy_score = -torch.log(torch.max(torch.exp(f_klogits), dim=1)[0])
                u_energy_score = -torch.log(torch.max(torch.exp(f_ulogits), dim=1)[0])
            l_energy = (torch.pow(F.relu(k_energy_score - args.m_in), 2).mean() + torch.pow(F.relu(args.m_out - u_energy_score), 2).mean()) * energy_loss_scale
        energy_score = torch.cat([k_energy_score, u_energy_score], dim=0)
        return (l_energy, energy_score)


class Args:
    def __init__(self, ahead_combine=True, learnable_margin=True, m_in=-1.0, m_out=1.0, energy_method='sum'):
        self.ahead_combine = ahead_combine
        self.learnable_margin = learnable_margin
        self.m_in = m_in
        self.m_out = m_out
        self.energy_method = energy_method


INIT_ARGS = {
    'args': Args(ahead_combine=True, learnable_margin=True, m_in=-1.0, m_out=1.0, energy_method='sum')
}

ARGS = {
    'f_klogits': torch.randn(2, 4),
    'f_ulogits': torch.randn(2, 4),
    'e_klogits': torch.randn(2, 4),
    'e_ulogits': torch.randn(2, 4)
}

if __name__ == '__main__':
    model = EnergyLoss(**INIT_ARGS)
    output = model(**ARGS)
    print("Loss:", output[0])
    print("Energy score shape:", output[1].shape)
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
model, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
MultiHeadAttention Ran
ran on a synthesized input · constructed an object; no result was computed
00why00/glocal/model/models/glocal_energy.py
code served (permissive licence) · get_code("a45b4e485260a65b")
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, MultiHeadAttention: the run constructed the object and did not call it, so no result was computed. The image it ran in was 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

torch.manual_seed(0)

# Create input tensors for q, k, v
# Batch size: 2, Sequence length: 3, Model dimension: 4
batch_size = 2
seq_len = 3
d_model = 4

q = torch.randn(batch_size, seq_len, d_model)
k = torch.randn(batch_size, seq_len, d_model)
v = torch.randn(batch_size, seq_len, d_model)

# Parameters for MultiHeadAttention
n_head = 2
d_k = 2
d_v = 2
dropout = 0.1

ARGS = {
    "n_head": n_head,
    "d_model": d_model,
    "d_k": d_k,
    "d_v": d_v,
    "dropout": dropout
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type MultiHeadAttention — 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 MultiHeadAttention 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
ScaledDotProductAttention Ran
ran on a synthesized input
00why00/glocal/model/models/glocal_energy.py
code served (permissive licence) · get_code("388586789afa7a3a")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned tuple. The image it ran in was 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 torch.nn.functional as F

class ScaledDotProductAttention(nn.Module):
    """ Scaled Dot-Product Attention """

    def __init__(self, temperature, attn_dropout=0.1):
        super().__init__()
        self.temperature = temperature
        self.dropout = nn.Dropout(attn_dropout)
        self.softmax = nn.Softmax(dim=2)

    def forward(self, q, k, v):
        attn = torch.bmm(q, k.transpose(1, 2))
        attn = attn / self.temperature
        log_attn = F.log_softmax(attn, 2)
        attn = self.softmax(attn)
        attn = self.dropout(attn)
        output = torch.bmm(attn, v)
        return (output, attn, log_attn)


INIT_ARGS = {
    'temperature': 8.0,
    'attn_dropout': 0.1,
}

ARGS = {
    'q': torch.randn(2, 3, 4),
    'k': torch.randn(2, 5, 4),
    'v': torch.randn(2, 5, 6),
}

if __name__ == '__main__':
    model = ScaledDotProductAttention(**INIT_ARGS)
    output, attn, log_attn = model(**ARGS)
    print("Output shape:", output.shape)
    print("Attention shape:", attn.shape)
    print("Log attention shape:", log_attn.shape)
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
Base Not yet run
unverified (harvested, no recorded run)
00why00/glocal/model/models/glocal_energy.py
code served (permissive licence) · get_code("b860f9451eeab647")
How it ran

no invocation recorded.

GEL Not yet run
unverified (harvested, no recorded run)
00why00/glocal/model/models/glocal_energy.py
code served (permissive licence) · get_code("578a3a4891ecd31a")
How it ran

no invocation recorded.

Also present in other papers' code

Of 5 samples lifted from this paper's linked repositories, 5 carry a function identity and 0 do not. Of the 5 distinct functions with an identity, 1 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 0 the same month, 1 later) and 4 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
ScaledDotProductAttention
brick of this paper's assembly: helper
3 other papers
2 dated earlier, 1 later
2207.06580 (2022-07)
Proposal-Free Temporal Action Detection via Global Segmentation Mask Learning
2207.07059 (2022-07)
Semi-Supervised Temporal Action Detection with Proposal-Free Masking
2605.13672 (2026-05)
SpurAudio: A Benchmark for Studying Shortcut Learning in Few-Shot Audio Classification

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-23.

Repositories linked to this paper

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

Abstract

Few-shot open-set recognition (FSOR) is a challenging task of great practical value. It aims to categorize a sample to one of the pre-defined, closed-set classes illustrated by few examples while being able to reject the sample from unknown classes. In this work, we approach the FSOR task by proposing a novel energy-based hybrid model. The model is composed of two branches, where a classification branch learns a metric to classify a sample to one of closedset classes and the energy branch explicitly estimates the open-set probability. To achieve holistic detection of openset samples, our model leverages both class-wise and pixelwise features to learn a glocal energy-based score, in which a global energy score is learned using the class-wise features, while a local energy score is learned using the pixelwise features. The model is enforced to assign large energy scores to samples that are deviated from the few-shot examples in either the class-wise features or the pixel-wise features, and to assign small energy scores otherwise. Experiments on three standard FSOR datasets show the superior performance of our model. 1

For agents

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

get_harvested_code_for_paper("2304.11855")
get_code_for_paper("2304.11855")
have("2304.11855")

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

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

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

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

Connect an agent — have() is free.