SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2211.03003 · ICLR · 2022

Learning to Annotate Part Segmentation with Gradient Matching

Xiangyang Ji, Yu Yang, Hakan Bilen, Xiaotian Cheng

arXiv · PDF · Open in the Atlas

Code that ran

5 of 5 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 1 honoured the contract we drafted, 0 violated it and 1 has no contract verdict; 3 failures of our instrument; 0 no recorded run), measured 2026-11-22; 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/2211.03003.json · badge: /api/ran/2211.03003.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
yangyu12/lagm canonical (classifier label)
classifier basis: classifier_2025
5 ran · 0 no recorded run
FunctionStatusWhere it lives
GradientMatcher Ran
ran on a synthesized input
yangyu12/lagm/training/loss.py
code served (permissive licence) · get_code("fc7aca119a00d268")
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 Tensor, ndim 0, dtype family float, 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.nn.functional as F

def distance_wb(x, y, metric, reduction='sum'):
    shape = x.shape
    if len(shape) == 4:
        x = x.reshape(shape[0], shape[1] * shape[2] * shape[3])
        y = y.reshape(shape[0], shape[1] * shape[2] * shape[3])
    elif len(shape) == 3:
        x = x.reshape(shape[0], shape[1] * shape[2])
        y = y.reshape(shape[0], shape[1] * shape[2])
    elif len(shape) == 2:
        tmp = 'do nothing'
    elif len(shape) == 1:
        x = x.reshape(1, shape[0])
        y = y.reshape(1, shape[0])
        return 0
    if metric == 'cosine':
        distance = torch.sum(1.0 - F.cosine_similarity(x, y, dim=1, eps=1e-06))
    elif metric == 'l2':
        distance = torch.sum((x - y) ** 2, dim=1).sqrt().sum()
    elif metric == 'dotprod':
        distance = -torch.sum(x * y)
    else:
        raise NotImplementedError
    if reduction == 'mean':
        num_groups = x.shape[0]
        distance = distance / num_groups
    return distance

def gradient_matching(param_grad_syn, param_grad_lbl, metric='cosine', reduction='sum'):
    dis = 0
    assert len(param_grad_syn) == len(param_grad_lbl), f'{len(param_grad_syn)}, {len(param_grad_lbl)}'
    for x, y in zip(param_grad_syn, param_grad_lbl):
        dis = dis + distance_wb(x, y, metric, reduction=reduction)
    if reduction == 'mean':
        num_params = len(param_grad_syn)
        dis = dis / num_params
    return dis

class GradientMatcher:

    def __init__(self, metric='cosine', reduction='mean'):
        self.metric = metric
        self.reduction = reduction

    def match(self, grad_syn, grad_real):
        return gradient_matching(grad_syn, grad_real, metric=self.metric, reduction=self.reduction)


INIT_ARGS = {
    'metric': 'cosine',
    'reduction': 'mean'
}

ARGS = {
    'grad_syn': [
        torch.randn(2, 4),
        torch.randn(3, 5),
        torch.randn(2, 3, 4)
    ],
    'grad_real': [
        torch.randn(2, 4),
        torch.randn(3, 5),
        torch.randn(2, 3, 4)
    ]
}

METHOD = 'match'

matcher = GradientMatcher(**INIT_ARGS)
result = matcher.match(ARGS['grad_syn'], ARGS['grad_real'])
print(f"Result: {result}")
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 Tensor, ndim 0, dtype family float, 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
distance_wb Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
yangyu12/lagm/training/loss.py
code served (permissive licence) · get_code("40305d496ad82775")
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) and returned Tensor, ndim 0, dtype family float, 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.nn.functional as F

torch.manual_seed(0)

# Create small tensors for testing
# Test with 2D shape (batch_size, features)
x = torch.randn(2, 4)
y = torch.randn(2, 4)

# Test with different metrics
metric = 'cosine'
reduction = 'sum'

ARGS = {
    'x': x,
    'y': y,
    'metric': metric,
    'reduction': reduction
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 0, dtype family float, 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
gradient_matching Ran
ran, honoured the contract we drafted
yangyu12/lagm/training/loss.py
code served (permissive licence) · get_code("fa28b5e7a248a1f8")
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) and returned Tensor, ndim 0, dtype family float, 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.nn as nn

torch.manual_seed(0)

# Create synthetic parameter gradients (list of tensors with different shapes)
param_grad_syn = [
    torch.randn(2, 4),           # 2D tensor
    torch.randn(2, 3, 4),        # 3D tensor
    torch.randn(2, 2, 3, 4),     # 4D tensor
]

# Create label parameter gradients (same shapes as synthetic)
param_grad_lbl = [
    torch.randn(2, 4),           # 2D tensor
    torch.randn(2, 3, 4),        # 3D tensor
    torch.randn(2, 2, 3, 4),     # 4D tensor
]

ARGS = {
    'param_grad_syn': param_grad_syn,
    'param_grad_lbl': param_grad_lbl,
    'metric': 'cosine',
    'reduction': 'sum',
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 0, dtype family float, 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
set_logging Ran
ran; our contract draft was wrong, not the code
yangyu12/lagm/downstream_seg.py
code served (permissive licence) · get_code("63df326991f2f738")
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) and returned RootLogger. 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 logging
import tempfile
import os

# Create a temporary file path for logging
temp_dir = tempfile.mkdtemp()
log_path = os.path.join(temp_dir, "test.log")

ARGS = {
    "log_path": log_path
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type RootLogger — a RootLogger output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a RootLogger 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
setup_snapshot_image_label_grid Ran
ran; our contract draft was wrong, not the code
yangyu12/lagm/annotate_seg.py
code served (permissive licence) · get_code("288e4b24566ba9c1")
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) 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 numpy as np

class MockTrainingSet:
    def __init__(self):
        # image_shape is accessed as [1] for height and [2] for width
        # Set distinct dimensions: (batch, height, width, channels)
        self.image_shape = (1, 64, 128, 3)
        self.data = []
        # Create 10 samples
        for i in range(10):
            image = torch.randn(3, 64, 128)
            label = torch.tensor([i % 2], dtype=torch.long)
            self.data.append((image, label))
    
    def __len__(self):
        return len(self.data)
    
    def __getitem__(self, idx):
        return self.data[idx]

torch.manual_seed(0)
training_set = MockTrainingSet()

ARGS = {
    "training_set": training_set,
    "random_seed": 0,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, 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: none by the harness; any seed is in the setup block

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, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 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.

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

Repositories linked to this paper

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

Abstract

The success of state-of-the-art deep neural networks heavily relies on the presence of large-scale labelled datasets, which are extremely expensive and time-consuming to annotate. This paper focuses on tackling semi-supervised part segmentation tasks by generating high-quality images with a pre-trained GAN and labelling the generated images with an automatic annotator. In particular, we formulate the annotator learning as a learning-to-learn problem. Given a pre-trained GAN, the annotator learns to label object parts in a set of randomly generated images such that a part segmentation model trained on these synthetic images with their predicted labels obtains low segmentation error on a small validation set of manually labelled images. We further reduce this nested-loop optimization problem to a simple gradient matching problem and efficiently solve it with an iterative algorithm. We show that our method can learn annotators from a broad range of labelled images including real images, generated images, and even analytically rendered images. Our method is evaluated with semi-supervised part segmentation tasks and significantly outperforms other semi-supervised competitors when the amount of labelled examples is extremely limited.

For agents

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

get_harvested_code_for_paper("2211.03003")
get_code_for_paper("2211.03003")
have("2211.03003")

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

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

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

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

Connect an agent — have() is free.