Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Pass meshgrid() indexing argument to avoid pytorch warning #5399

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion detectron2/modeling/anchor_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _create_grid_offsets(
target_device_tensor,
)

shift_y, shift_x = torch.meshgrid(shifts_y, shifts_x)
shift_y, shift_x = torch.meshgrid(shifts_y, shifts_x, indexing="ij")
shift_x = shift_x.reshape(-1)
shift_y = shift_y.reshape(-1)
return shift_x, shift_y
Expand Down
2 changes: 1 addition & 1 deletion detectron2/modeling/backbone/swin.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def __init__(
# get pair-wise relative position index for each token inside the window
coords_h = torch.arange(self.window_size[0])
coords_w = torch.arange(self.window_size[1])
coords = torch.stack(torch.meshgrid([coords_h, coords_w])) # 2, Wh, Ww
coords = torch.stack(torch.meshgrid([coords_h, coords_w], indexing="ij")) # 2, Wh, Ww
coords_flatten = torch.flatten(coords, 1) # 2, Wh*Ww
relative_coords = coords_flatten[:, :, None] - coords_flatten[:, None, :] # 2, Wh*Ww, Wh*Ww
relative_coords = relative_coords.permute(1, 2, 0).contiguous() # Wh*Ww, Wh*Ww, 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def _create_pixel_dist_matrix(grid_size: int) -> torch.Tensor:
# row = i // grid_size
# col = i % grid_size
pix_coords = (
torch.stack(torch.meshgrid(rows, cols), -1).reshape((grid_size * grid_size, 2)).float()
torch.stack(torch.meshgrid(rows, cols, indexing="ij"), -1).reshape((grid_size * grid_size, 2)).float()
)
return squared_euclidean_distance_matrix(pix_coords, pix_coords)

Expand Down Expand Up @@ -130,7 +130,7 @@ def forward(
)
# pixel distances [M, M]
pixel_dists = self.pixel_dists.to(pixel_embeddings.device)[
torch.meshgrid(pixel_indices_flattened, pixel_indices_flattened)
torch.meshgrid(pixel_indices_flattened, pixel_indices_flattened, indexing="ij")
]
# pixel embeddings [M, D]
pixel_embeddings_sampled = normalize_embeddings(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _get_embeddings_and_geodists_for_mesh(
geodists = mesh.geodists
if indices is not None:
embeddings = embeddings[indices]
geodists = geodists[torch.meshgrid(indices, indices)]
geodists = geodists[torch.meshgrid(indices, indices, indexing="ij")]
return embeddings, geodists

def _forward_one_pair(
Expand Down
2 changes: 1 addition & 1 deletion projects/DensePose/tests/test_video_keyframe_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

# copied from torchvision test/test_io.py
def _create_video_frames(num_frames, height, width):
y, x = torch.meshgrid(torch.linspace(-2, 2, height), torch.linspace(-2, 2, width))
y, x = torch.meshgrid(torch.linspace(-2, 2, height), torch.linspace(-2, 2, width), indexing="ij")
data = []
for i in range(num_frames):
xc = float(i) / num_frames
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def group_pixels(center_points, offsets):
y_coord, x_coord = torch.meshgrid(
torch.arange(height, dtype=offsets.dtype, device=offsets.device),
torch.arange(width, dtype=offsets.dtype, device=offsets.device),
indexing="ij",
)
coord = torch.cat((y_coord.unsqueeze(0), x_coord.unsqueeze(0)), dim=0)

Expand Down
4 changes: 2 additions & 2 deletions projects/TensorMask/tensormask/arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def grid_anchors_with_unit_lengths_and_indexes(self, grid_sizes):
shifts_y = torch.arange(
0, grid_height * stride, step=stride, dtype=torch.float32, device=device
)
shift_y, shift_x = torch.meshgrid(shifts_y, shifts_x)
shift_y, shift_x = torch.meshgrid(shifts_y, shifts_x, indexing="ij")
shifts = torch.stack((shift_x, shift_y, shift_x, shift_y), dim=2)
# Stack anchors in shapes of (HWA, 4)
cur_anchor = (shifts[:, :, None, :] + base_anchors.view(1, 1, -1, 4)).view(-1, 4)
Expand All @@ -261,7 +261,7 @@ def grid_anchors_with_unit_lengths_and_indexes(self, grid_sizes):
shifts_h = torch.arange(0, grid_height, dtype=torch.int64, device=device)
shifts_w = torch.arange(0, grid_width, dtype=torch.int64, device=device)
shifts_a = torch.arange(0, base_anchors.shape[0], dtype=torch.int64, device=device)
grids = torch.meshgrid(shifts_l, shifts_i, shifts_h, shifts_w, shifts_a)
grids = torch.meshgrid(shifts_l, shifts_i, shifts_h, shifts_w, shifts_a, indexing="ij")

indexes.append(torch.stack(grids, dim=5).view(-1, 5))

Expand Down
2 changes: 1 addition & 1 deletion tests/layers/test_mask_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def rasterize_polygons_with_grid_sample(full_image_bit_mask, box, mask_size, thr

mask_x = (mask_x - 0.5) / (img_w - 1) * 2 + -1
mask_y = (mask_y - 0.5) / (img_h - 1) * 2 + -1
gy, gx = torch.meshgrid(torch.from_numpy(mask_y), torch.from_numpy(mask_x))
gy, gx = torch.meshgrid(torch.from_numpy(mask_y), torch.from_numpy(mask_x), indexing="ij")
ind = torch.stack([gx, gy], dim=-1).to(dtype=torch.float32)

full_image_bit_mask = torch.from_numpy(full_image_bit_mask)
Expand Down