SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2502.06756 · ICLR · 2025

SAMRefiner: Taming Segment Anything Model for Universal Mask Refinement

Wenqi Shao, Ping Luo, Zheng Yang, Xiaofei He, Jun Zhao, Kaipeng Zhang, Yuqi Lin, Hengjia Li

arXiv · PDF · Open in the Atlas

Code that ran

7 of 12 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; 0 honoured the contract we drafted, 0 violated it and 3 have no contract verdict; 4 failures of our instrument; 5 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/2502.06756.json · badge: /api/ran/2502.06756.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
linyq2117/samrefiner canonical (classifier label)
classifier basis not recorded on the link
7 ran · 5 no recorded run
FunctionStatusWhere it lives
gaussian_2d Ran
ran on a synthesized input
linyq2117/samrefiner/SAMRefiner_plus/utils.py
code served (permissive licence) · get_code("a75b4ea06278636b")
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 2, dtype family float, shape (5, 7) 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

ARGS = {
    "shape": (5, 7),
    "gamma_x": 1.5,
    "gamma_y": 2.0,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ndarray, ndim 2, dtype family float, shape (5, 7) — shape (5, 7) 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
get_iou Ran
ran on a synthesized input
linyq2117/samrefiner/SAMRefiner_plus/iou_adaption_davis585.py
code served (permissive licence) · get_code("b8469730f63cb657")
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 float64, 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 numpy as np

# Create small binary masks for testing
# gt_mask: ground truth mask with values in {-1 (ignore), 0 (background), 1 (object)}
# pred_mask: predicted mask with boolean values

np.random.seed(0)

# Create a small ground truth mask (4x3)
gt_mask = np.array([
    [1, 0, -1],
    [1, 1, 0],
    [0, 1, 1],
    [-1, 0, 1]
], dtype=np.int32)

# Create a small predicted mask (4x3) with boolean values
pred_mask = np.array([
    [True, False, True],
    [True, False, False],
    [False, True, True],
    [True, False, True]
], dtype=bool)

ARGS = {
    "gt_mask": gt_mask,
    "pred_mask": pred_mask,
    "ignore_label": -1
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type float64, ndim 0, dtype family float — no output shape is stated: observe_signature.py recorded float ndim 0, which disagrees with the fixture run
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
get_rel_pos Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
linyq2117/samrefiner/SAMRefiner_plus/segment-anything/segment_anything/modeling/image_encoder.py
code served (permissive licence) · get_code("733d7f0bedcb74c2")
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 3, dtype family float, shape (3, 4, 4) 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 a small relative position embedding tensor
# Shape: (L, C) where L is the sequence length and C is the channel dimension
# Using a small size that will be resized by the function
rel_pos = torch.randn(5, 4)  # 5 positions, 4 channels

# Define query and key sizes
q_size = 3
k_size = 4

ARGS = {
    "q_size": q_size,
    "k_size": k_size,
    "rel_pos": rel_pos,
}
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 3, dtype family float, shape (3, 4, 4) — shape (3, 4, 4) 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
mask_to_boundary Ran
ran; our contract draft was wrong, not the code
linyq2117/samrefiner/SAMRefiner_plus/iou_adaption_davis585.py
code served (permissive licence) · get_code("b79a90dcf06de145")
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 2, dtype family int, shape (16, 12) 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 cv2

# Create a small binary mask for testing
# Using a 16x12 image for distinct dimensions
mask = np.zeros((16, 12), dtype=np.uint8)
# Add some white region to the mask
mask[4:12, 3:9] = 255

# Define the arguments dictionary
ARGS = {
    "mask": mask,
    "dilation_ratio": 0.02
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
cv2, numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ndarray, ndim 2, dtype family int, shape (16, 12) — shape (16, 12) 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
prepare_image Ran
ran on a synthesized input
linyq2117/samrefiner/SAMRefiner_plus/utils.py
code served (permissive licence) · get_code("73f5acb20532d93f")
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 Tensor, ndim 3, dtype family int, shape (3, 4, 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 torch
import numpy as np

torch.manual_seed(0)

# Create a minimal transform class with apply_image method
class MinimalTransform:
    def apply_image(self, image):
        # Returns an image in HxWxC format as numpy array
        return image

# Create a sample image as numpy array in HxW format (will be converted to HxWxC)
# Using shape (4, 3, 3) to represent 4 height, 3 width, 3 channels
image = np.random.randint(0, 256, size=(4, 3, 3), dtype=np.uint8)

# Create transform instance
transform = MinimalTransform()

# CPU device
device = 'cpu'

ARGS = {
    'image': image,
    'transform': transform,
    'device': device
}
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 Tensor, ndim 3, dtype family int, shape (3, 4, 3) — shape (3, 4, 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
window_partition Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
linyq2117/samrefiner/SAMRefiner_plus/segment-anything/segment_anything/modeling/image_encoder.py
pointer only (licence: MIT); the stored copy get_code serves, from LeapLabTHU/EchoWorld, is pointer only (licence: NONE) · get_code("105fa08885dc36cc")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from LeapLabTHU/EchoWorld, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

window_unpartition Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
linyq2117/samrefiner/SAMRefiner_plus/segment-anything/segment_anything/modeling/image_encoder.py
pointer only (licence: MIT); the stored copy get_code serves, from yatengLG/ISAT_with_segment_anything, is pointer only (licence: NOASSERTION) · get_code("27be441cc8213e52")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from yatengLG/ISAT_with_segment_anything, and GitHub could not classify the licence of that repository (NOASSERTION). The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

build_sam_vit_b Not yet run
unverified (harvested, no recorded run)
linyq2117/samrefiner/SAMRefiner_plus/segment-anything/segment_anything/build_sam.py
code served (permissive licence) · get_code("37d02776691c6ccc")
How it ran

no invocation recorded.

build_sam_vit_h Not yet run
unverified (harvested, no recorded run)
linyq2117/samrefiner/SAMRefiner_plus/segment-anything/segment_anything/build_sam.py
code served (permissive licence) · get_code("408c835829e1dadc")
How it ran

no invocation recorded.

build_sam_vit_l Not yet run
unverified (harvested, no recorded run)
linyq2117/samrefiner/SAMRefiner_plus/segment-anything/segment_anything/build_sam.py
code served (permissive licence) · get_code("e42540863d3b7880")
How it ran

no invocation recorded.

get_iu Not yet run
unverified (harvested, no recorded run)
linyq2117/samrefiner/SAMRefiner_plus/iou_adaption_davis585.py
code served (permissive licence) · get_code("f5f76587ff3a7654")
How it ran

no invocation recorded.

get_mask_embed Not yet run
unverified (harvested, no recorded run)
linyq2117/samrefiner/SAMRefiner_plus/utils.py
code served (permissive licence) · get_code("a0228049b4df86da")
How it ran

no invocation recorded.

Also present in other papers' code

Of 12 samples lifted from this paper's linked repositories, 12 carry a function identity and 0 do not. Of the 12 distinct functions with an identity, 8 are also present in other papers whose code we hold (7 with at least one paper dated earlier, 0 the same month, 7 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
get_rel_pos 47 other papers
42 dated earlier, 5 later · 5 only as an assembly brick
2304.02643 (2023-04)
Segment Anything
2304.06790 (2023-04)
Inpaint Anything: Segment Anything Meets Image Inpainting
2304.12306 (2023-04)
Segment Anything in Medical Images
and 44 more not named here
window_partition 47 other papers
43 dated earlier, 4 later · 1 only as an assembly brick
2304.02643 (2023-04)
Segment Anything
2304.06790 (2023-04)
Inpaint Anything: Segment Anything Meets Image Inpainting
2304.12306 (2023-04)
Segment Anything in Medical Images
and 44 more not named here
window_unpartition 46 other papers
42 dated earlier, 4 later · 1 only as an assembly brick
2304.02643 (2023-04)
Segment Anything
2304.06790 (2023-04)
Inpaint Anything: Segment Anything Meets Image Inpainting
2304.12306 (2023-04)
Segment Anything in Medical Images
and 43 more not named here
build_sam_vit_h 37 other papers
33 dated earlier, 4 later · 2 only as an assembly brick
2304.06790 (2023-04)
Inpaint Anything: Segment Anything Meets Image Inpainting
2304.12306 (2023-04)
Segment Anything in Medical Images
2305.01586 (2023-05)
An Alternative to WSSS? An Empirical Study of the Segment Anything Model (SAM) on Weakly-Supervised Semantic Segmentation Problems
and 34 more not named here
build_sam_vit_b 34 other papers
32 dated earlier, 2 later
2304.06790 (2023-04)
Inpaint Anything: Segment Anything Meets Image Inpainting
2304.12306 (2023-04)
Segment Anything in Medical Images
2305.01586 (2023-05)
An Alternative to WSSS? An Empirical Study of the Segment Anything Model (SAM) on Weakly-Supervised Semantic Segmentation Problems
and 31 more not named here
build_sam_vit_l 34 other papers
32 dated earlier, 2 later
2304.06790 (2023-04)
Inpaint Anything: Segment Anything Meets Image Inpainting
2304.12306 (2023-04)
Segment Anything in Medical Images
2305.01586 (2023-05)
An Alternative to WSSS? An Empirical Study of the Segment Anything Model (SAM) on Weakly-Supervised Semantic Segmentation Problems
and 31 more not named here
mask_to_boundary 2 other papers
2 later
2503.14029 (2025-03)
Rethinking End-to-End 2D to 3D Scene Segmentation in Gaussian Splatting
2503.19777 (2025-03)
LPOSS: Label Propagation Over Patches and Pixels for Open-vocabulary Semantic Segmentation
get_iu 1 other paper
1 dated earlier
2005.02551 (2020-05)
CascadePSP: Toward Class-Agnostic and Very High-Resolution Segmentation via Global and Local Refinement

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

In this paper, we explore a principal way to enhance the quality of widely preexisting coarse masks, enabling them to serve as reliable training data for segmentation models to reduce the annotation cost. In contrast to prior refinement techniques that are tailored to specific models or tasks in a close-world manner, we propose SAMRefiner, a universal and efficient approach by adapting SAM to the mask refinement task. The core technique of our model is the noise-tolerant prompting scheme. Specifically, we introduce a multi-prompt excavation strategy to mine diverse input prompts for SAM (i.e, distance-guided points, context-aware elastic bounding boxes, and Gaussian-style masks) from initial coarse masks. These prompts can collaborate with each other to mitigate the effect of defects in coarse masks. In particular, considering the difficulty of SAM to handle the multi-object case in semantic segmentation, we introduce a split-then-merge (STM) pipeline. Additionally, we extend our method to SAMRefiner++ by introducing an additional IoU adaption step to further boost the performance of the generic SAMRefiner on the target dataset. This step is self-boosted and requires no additional annotation. The proposed framework is versatile and can flexibly cooperate with existing segmentation methods. We evaluate our mask framework on a wide range of benchmarks under different settings, demonstrating better accuracy and efficiency. SAMRefiner holds significant potential to expedite the evolution of refinement tools. Our code is available at SAMRefiner.

For agents

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

get_harvested_code_for_paper("2502.06756")
get_code_for_paper("2502.06756")
have("2502.06756")

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

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

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

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

Connect an agent — have() is free.