facebookresearch / facebookresearch/segment-anything

amg.build_point_grid function

Open
#211 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
54.9k
Forks
6.4k
PR merge metrics
No merged PRs in 30d

Description

Thanks for your great work !
when I read and understand the source code,
copilot gives another implemention of function "build_point_grid", which looks more concise and direct, maybe you could have a try
```
def build_point_grid2(n_per_side: int) -> np.ndarray:
"""Generates a 2D grid of points evenly spaced in [0,1]x[0,1]."""
offset = 1 / (2 * n_per_side)
points = np.mgrid[0:n_per_side, 0:n_per_side].transpose(2, 1, 0).reshape(-1, 2) / n_per_side + offset
return points

def build_point_grid(n_per_side: int) -> np.ndarray:
"""Generates a 2D grid of points evenly spaced in [0,1]x[0,1]."""
offset = 1 / (2 * n_per_side)
points_one_side = np.linspace(offset, 1 - offset, n_per_side)
points_x = np.tile(points_one_side[None, :], (n_per_side, 1))
points_y = np.tile(points_one_side[:, None], (1, n_per_side))
points = np.stack([points_x, points_y], axis=-1).reshape(-1, 2)

assert np.all(points == build_point_grid2(n_per_side))
return points
```

Contributor guide

Open the contributing guide

Research direction

Start by locating the amg.build_point_grid entry point and compare its output with the proposed build_point_grid2 implementation. Done means the function remains behaviorally equivalent for its supported inputs and the relevant project checks pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
computer-vision
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.