PyTorch 1.7 compatibility

Summary: Small changes discovered based on circleCI failures.

Reviewed By: patricklabatut

Differential Revision: D34426807

fbshipit-source-id: 819860f34b2f367dd24057ca7490284204180a13
This commit is contained in:
Jeremy Reizenstein
2022-02-25 07:53:34 -08:00
committed by Facebook GitHub Bot
parent f816568735
commit 4d043fc9ac
9 changed files with 34 additions and 23 deletions

View File

@@ -11,11 +11,7 @@ import torch
from common_testing import TestCaseMixin, get_random_cuda_device
from pytorch3d import _C
from pytorch3d.loss import point_mesh_edge_distance, point_mesh_face_distance
from pytorch3d.structures import (
Meshes,
Pointclouds,
packed_to_list,
)
from pytorch3d.structures import Meshes, Pointclouds, packed_to_list
class TestPointMeshDistance(TestCaseMixin, unittest.TestCase):

View File

@@ -1033,7 +1033,7 @@ class TestPointclouds(TestCaseMixin, unittest.TestCase):
for i, cloud in enumerate(clouds.points_list()):
within_box_naive.append(inside_box_naive(cloud, box[i, 0], box[i, 1]))
within_box_naive = torch.cat(within_box_naive, 0)
self.assertClose(within_box, within_box_naive)
self.assertTrue(torch.equal(within_box, within_box_naive))
# box of shape 2x3
box2 = box[0, :]
@@ -1044,13 +1044,12 @@ class TestPointclouds(TestCaseMixin, unittest.TestCase):
for cloud in clouds.points_list():
within_box_naive2.append(inside_box_naive(cloud, box2[0], box2[1]))
within_box_naive2 = torch.cat(within_box_naive2, 0)
self.assertClose(within_box2, within_box_naive2)
self.assertTrue(torch.equal(within_box2, within_box_naive2))
# box of shape 1x2x3
box3 = box2.expand(1, 2, 3)
within_box3 = clouds.inside_box(box3)
self.assertClose(within_box2, within_box3)
self.assertTrue(torch.equal(within_box2, within_box3))
# invalid box
invalid_box = torch.cat(

View File

@@ -9,6 +9,7 @@ from typing import Callable
import torch
from common_testing import TestCaseMixin
from pytorch3d.common.compat import meshgrid_ij
from pytorch3d.ops import eyes
from pytorch3d.renderer import (
MonteCarloRaysampler,
@@ -86,7 +87,7 @@ class TestNDCRaysamplerConvention(TestCaseMixin, unittest.TestCase):
min_y = range_y - half_pix_height
max_y = -range_y + half_pix_height
y_grid, x_grid = torch.meshgrid(
y_grid, x_grid = meshgrid_ij(
torch.linspace(min_y, max_y, h, dtype=torch.float32),
torch.linspace(min_x, max_x, w, dtype=torch.float32),
)
@@ -540,7 +541,7 @@ class TestRaysampling(TestCaseMixin, unittest.TestCase):
self.assertTupleEqual(out.shape, data.shape)
# Check `out` is in ascending order
self.assertGreater(torch.diff(out, dim=-1).min(), 0)
self.assertGreater((out[..., 1:] - out[..., :-1]).min(), 0)
self.assertConstant(out[..., :-1] < data[..., 1:], True)
self.assertConstant(data[..., :-1] < out[..., 1:], True)

View File

@@ -10,6 +10,7 @@ import unittest
import numpy as np
import torch
from common_testing import TestCaseMixin
from pytorch3d.common.compat import meshgrid_ij
from pytorch3d.ops import eyes
from pytorch3d.renderer import (
AlphaCompositor,
@@ -129,8 +130,8 @@ class TestTensorProperties(TestCaseMixin, unittest.TestCase):
point_radius = 0.015
n_pts = n_grid_pts * n_grid_pts
pts = torch.stack(
torch.meshgrid(
[torch.linspace(-grid_scale, grid_scale, n_grid_pts)] * 2, indexing="ij"
meshgrid_ij(
[torch.linspace(-grid_scale, grid_scale, n_grid_pts)] * 2,
),
dim=-1,
)