mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-12-20 14:20:38 +08:00
Convert directory fbcode/vision to use the Ruff Formatter
Summary:
Converts the directory specified to use the Ruff formatter in pyfmt
ruff_dog
If this diff causes merge conflicts when rebasing, please run
`hg status -n -0 --change . -I '**/*.{py,pyi}' | xargs -0 arc pyfmt`
on your diff, and amend any changes before rebasing onto latest.
That should help reduce or eliminate any merge conflicts.
allow-large-files
Reviewed By: bottler
Differential Revision: D66472063
fbshipit-source-id: 35841cb397e4f8e066e2159550d2f56b403b1bef
This commit is contained in:
committed by
Facebook GitHub Bot
parent
f6c2ca6bfc
commit
055ab3a2e3
@@ -11,7 +11,6 @@ from tests.test_ball_query import TestBallQuery
|
||||
|
||||
|
||||
def bm_ball_query() -> None:
|
||||
|
||||
backends = ["cpu", "cuda:0"]
|
||||
|
||||
kwargs_list = []
|
||||
|
||||
@@ -11,7 +11,6 @@ from tests.test_cameras_alignment import TestCamerasAlignment
|
||||
|
||||
|
||||
def bm_cameras_alignment() -> None:
|
||||
|
||||
case_grid = {
|
||||
"batch_size": [10, 100, 1000],
|
||||
"mode": ["centers", "extrinsics"],
|
||||
|
||||
@@ -11,7 +11,6 @@ from tests.test_knn import TestKNN
|
||||
|
||||
|
||||
def bm_knn() -> None:
|
||||
|
||||
backends = ["cpu", "cuda:0"]
|
||||
|
||||
kwargs_list = []
|
||||
|
||||
@@ -12,7 +12,6 @@ from tests.test_point_mesh_distance import TestPointMeshDistance
|
||||
|
||||
|
||||
def bm_point_mesh_distance() -> None:
|
||||
|
||||
backend = ["cuda:0"]
|
||||
|
||||
kwargs_list = []
|
||||
|
||||
@@ -12,7 +12,6 @@ from tests.test_points_alignment import TestCorrespondingPointsAlignment, TestIC
|
||||
|
||||
|
||||
def bm_iterative_closest_point() -> None:
|
||||
|
||||
case_grid = {
|
||||
"batch_size": [1, 10],
|
||||
"dim": [3, 20],
|
||||
@@ -43,7 +42,6 @@ def bm_iterative_closest_point() -> None:
|
||||
|
||||
|
||||
def bm_corresponding_points_alignment() -> None:
|
||||
|
||||
case_grid = {
|
||||
"allow_reflection": [True, False],
|
||||
"batch_size": [1, 10, 100],
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
|
||||
"""Test render speed."""
|
||||
|
||||
import logging
|
||||
import sys
|
||||
from os import path
|
||||
|
||||
@@ -11,7 +11,6 @@ from tests.test_sample_pdf import TestSamplePDF
|
||||
|
||||
|
||||
def bm_sample_pdf() -> None:
|
||||
|
||||
backends = ["python_cuda", "cuda", "python_cpu", "cpu"]
|
||||
|
||||
kwargs_list = []
|
||||
|
||||
@@ -13,7 +13,6 @@ from tests.test_sample_points_from_meshes import TestSamplePoints
|
||||
|
||||
|
||||
def bm_sample_points() -> None:
|
||||
|
||||
backend = ["cpu"]
|
||||
if torch.cuda.is_available():
|
||||
backend.append("cuda:0")
|
||||
|
||||
@@ -576,7 +576,6 @@ class TestConfig(unittest.TestCase):
|
||||
a: int = 9
|
||||
|
||||
for Unprocessed in [UnprocessedConfigurable, UnprocessedReplaceable]:
|
||||
|
||||
self.assertFalse(_is_actually_dataclass(Unprocessed))
|
||||
unprocessed = Unprocessed()
|
||||
self.assertTrue(_is_actually_dataclass(Unprocessed))
|
||||
|
||||
@@ -71,7 +71,6 @@ class TestEvaluation(unittest.TestCase):
|
||||
|
||||
for diff in 10 ** torch.linspace(-5, 0, 6):
|
||||
for crop in (0, 5):
|
||||
|
||||
pred = gt + (torch.rand_like(gt) - 0.5) * 2 * diff
|
||||
|
||||
# scaled prediction test
|
||||
|
||||
@@ -74,7 +74,6 @@ class TestGenericModel(unittest.TestCase):
|
||||
eval_test: bool = True,
|
||||
bw_test: bool = True,
|
||||
):
|
||||
|
||||
R, T = look_at_view_transform(azim=torch.rand(n_train_cameras) * 360)
|
||||
cameras = PerspectiveCameras(R=R, T=T, device=device)
|
||||
|
||||
|
||||
@@ -171,9 +171,7 @@ def _make_random_json_dataset_map_provider_v2_data(
|
||||
Image.fromarray(
|
||||
(mask * 255.0).astype(np.uint8),
|
||||
mode="L",
|
||||
).convert(
|
||||
"L"
|
||||
).save(mask_path)
|
||||
).convert("L").save(mask_path)
|
||||
|
||||
fa = FrameAnnotation(
|
||||
sequence_name=seq_name,
|
||||
|
||||
@@ -65,7 +65,6 @@ class TestModelVisualize(unittest.TestCase):
|
||||
visdom_show_preds = Visdom().check_connection()
|
||||
|
||||
for load_dataset_pointcloud in [True, False]:
|
||||
|
||||
model = _PointcloudRenderingModel(
|
||||
train_dataset,
|
||||
show_sequence_name,
|
||||
|
||||
@@ -142,7 +142,6 @@ class TestViewsampling(unittest.TestCase):
|
||||
expand_args_fields(ViewSampler)
|
||||
|
||||
for masked_sampling in (True, False):
|
||||
|
||||
view_sampler = ViewSampler(masked_sampling=masked_sampling)
|
||||
|
||||
feats_sampled, masks_sampled = view_sampler(
|
||||
|
||||
@@ -275,7 +275,6 @@ class TestVoxelGrids(TestCaseMixin, unittest.TestCase):
|
||||
return torch.cat(result)
|
||||
|
||||
def test_interpolation(self):
|
||||
|
||||
with self.subTest("1D interpolation"):
|
||||
points = self.get_random_normalized_points(
|
||||
n_grids=4, n_points=5, dimension=1
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
|
||||
"""Create multiview data."""
|
||||
|
||||
import sys
|
||||
from os import path
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
|
||||
"""Test number of channels."""
|
||||
|
||||
import logging
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
|
||||
"""Test the sorting of the closest spheres."""
|
||||
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
|
||||
"""Basic rendering test."""
|
||||
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
|
||||
"""Test right hand/left hand system compatibility."""
|
||||
|
||||
import logging
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
|
||||
"""Tests for the orthogonal projection."""
|
||||
|
||||
import logging
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
|
||||
"""Test right hand/left hand system compatibility."""
|
||||
|
||||
import sys
|
||||
import unittest
|
||||
from os import path
|
||||
|
||||
@@ -401,7 +401,10 @@ class TestBlending(TestCaseMixin, unittest.TestCase):
|
||||
dists1 = torch.randn(size=(N, S, S, K), requires_grad=True, device=device)
|
||||
zbuf = torch.randn(size=(N, S, S, K), requires_grad=True, device=device)
|
||||
fragments = Fragments(
|
||||
pix_to_face=pix_to_face, bary_coords=empty, zbuf=zbuf, dists=dists1 # dummy
|
||||
pix_to_face=pix_to_face,
|
||||
bary_coords=empty,
|
||||
zbuf=zbuf,
|
||||
dists=dists1, # dummy
|
||||
)
|
||||
blend_params = BlendParams(sigma=1e-3)
|
||||
|
||||
|
||||
@@ -495,8 +495,8 @@ class TestCamerasCommon(TestCaseMixin, unittest.TestCase):
|
||||
screen_cam_params["image_size"] = image_size
|
||||
screen_cam_params["focal_length"] = fcl * scale
|
||||
screen_cam_params["principal_point"] = (
|
||||
image_size[:, [1, 0]]
|
||||
) / 2.0 - prc * scale
|
||||
(image_size[:, [1, 0]]) / 2.0 - prc * scale
|
||||
)
|
||||
screen_cam_params["in_ndc"] = False
|
||||
else:
|
||||
raise ValueError(str(cam_type))
|
||||
@@ -615,7 +615,6 @@ class TestCamerasCommon(TestCaseMixin, unittest.TestCase):
|
||||
OrthographicCameras,
|
||||
PerspectiveCameras,
|
||||
):
|
||||
|
||||
# init the cameras
|
||||
cameras = init_random_cameras(cam_type, batch_size)
|
||||
# xyz - the ground truth point cloud
|
||||
|
||||
@@ -17,7 +17,6 @@ from .common_testing import get_random_cuda_device, TestCaseMixin
|
||||
|
||||
|
||||
class TestAccumulatePoints(TestCaseMixin, unittest.TestCase):
|
||||
|
||||
# NAIVE PYTHON IMPLEMENTATIONS (USED FOR TESTING)
|
||||
@staticmethod
|
||||
def accumulate_alphacomposite_python(points_idx, alphas, features):
|
||||
@@ -63,7 +62,6 @@ class TestAccumulatePoints(TestCaseMixin, unittest.TestCase):
|
||||
for c in range(0, C):
|
||||
for i in range(0, W):
|
||||
for j in range(0, H):
|
||||
|
||||
for k in range(0, K):
|
||||
n_idx = points_idx[b, k, j, i]
|
||||
|
||||
@@ -237,16 +235,16 @@ class TestAccumulatePoints(TestCaseMixin, unittest.TestCase):
|
||||
[
|
||||
# fmt: off
|
||||
[
|
||||
[0, 0, 0, 0], # noqa: E241, E201
|
||||
[0, 0, 0, 0], # noqa: E241, E201
|
||||
[0, -1, -1, -1], # noqa: E241, E201
|
||||
[0, 1, 1, 0], # noqa: E241, E201
|
||||
[0, 0, 0, 0], # noqa: E241, E201
|
||||
[0, 1, 1, 0], # noqa: E241, E201
|
||||
[0, 0, 0, 0], # noqa: E241, E201
|
||||
],
|
||||
[
|
||||
[2, 2, 2, 2], # noqa: E241, E201
|
||||
[2, 3, 3, 2], # noqa: E241, E201
|
||||
[2, 3, 3, 2], # noqa: E241, E201
|
||||
[2, 2, -1, 2], # noqa: E241, E201
|
||||
[2, 2, 2, 2], # noqa: E241, E201
|
||||
[2, 3, 3, 2], # noqa: E241, E201
|
||||
[2, 3, 3, 2], # noqa: E241, E201
|
||||
[2, 2, -1, 2], # noqa: E241, E201
|
||||
],
|
||||
# fmt: on
|
||||
]
|
||||
|
||||
@@ -95,7 +95,6 @@ class TestIoU3D(TestCaseMixin, unittest.TestCase):
|
||||
return ious
|
||||
|
||||
def _test_iou(self, overlap_fn, device):
|
||||
|
||||
box1 = torch.tensor(
|
||||
UNIT_BOX,
|
||||
dtype=torch.float32,
|
||||
|
||||
@@ -23,7 +23,6 @@ def convert_to_local(verts, volume_dim):
|
||||
|
||||
|
||||
class TestCubeConfiguration(TestCaseMixin, unittest.TestCase):
|
||||
|
||||
# Test single cubes. Each case corresponds to the corresponding
|
||||
# cube vertex configuration in each case here (0-indexed):
|
||||
# https://en.wikipedia.org/wiki/Marching_cubes#/media/File:MarchingCubes.svg
|
||||
|
||||
@@ -335,7 +335,6 @@ class TestMeshes(TestCaseMixin, unittest.TestCase):
|
||||
Meshes(verts=verts_padded, faces=faces_padded)
|
||||
|
||||
def test_simple_random_meshes(self):
|
||||
|
||||
# Define the test mesh object either as a list or tensor of faces/verts.
|
||||
for lists_to_tensors in (False, True):
|
||||
N = 10
|
||||
@@ -1120,7 +1119,6 @@ class TestMeshes(TestCaseMixin, unittest.TestCase):
|
||||
self.assertClose(face_areas, expected_areas)
|
||||
|
||||
def test_compute_normals(self):
|
||||
|
||||
# Simple case with one mesh where normals point in either +/- ijk
|
||||
verts = torch.tensor(
|
||||
[
|
||||
|
||||
@@ -1072,7 +1072,6 @@ class TestPointclouds(TestCaseMixin, unittest.TestCase):
|
||||
for with_normals in (True, False):
|
||||
for run_padded in (True, False):
|
||||
for run_packed in (True, False):
|
||||
|
||||
clouds = TestPointclouds.init_cloud(
|
||||
3,
|
||||
100,
|
||||
|
||||
@@ -56,7 +56,6 @@ class TestICP(TestCaseMixin, unittest.TestCase):
|
||||
use_pointclouds=False,
|
||||
estimate_scale=False,
|
||||
):
|
||||
|
||||
device = torch.device("cuda:0")
|
||||
|
||||
# initialize a ground truth point cloud
|
||||
@@ -433,7 +432,6 @@ class TestCorrespondingPointsAlignment(TestCaseMixin, unittest.TestCase):
|
||||
reflect=False,
|
||||
random_weights=False,
|
||||
):
|
||||
|
||||
device = torch.device("cuda:0")
|
||||
|
||||
# initialize a ground truth point cloud
|
||||
|
||||
@@ -258,9 +258,7 @@ class TestPointsToVolumes(TestCaseMixin, unittest.TestCase):
|
||||
batch_size = 4
|
||||
|
||||
for volume_size in ([25, 25, 25], [30, 25, 15]):
|
||||
|
||||
for python, interp_mode in product([True, False], ["trilinear", "nearest"]):
|
||||
|
||||
(pointclouds, initial_volumes) = init_volume_boundary_pointcloud(
|
||||
volume_size=volume_size,
|
||||
n_points=int(1e5),
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
"""
|
||||
Sanity checks for loading R2N2.
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import unittest
|
||||
|
||||
@@ -210,13 +210,11 @@ class TestRaysampling(TestCaseMixin, unittest.TestCase):
|
||||
device = torch.device("cuda")
|
||||
|
||||
for n_pts_per_ray in (100, 1):
|
||||
|
||||
for raysampler_type in (
|
||||
MonteCarloRaysampler,
|
||||
MultinomialRaysampler,
|
||||
NDCMultinomialRaysampler,
|
||||
):
|
||||
|
||||
raysampler = TestRaysampling.init_raysampler(
|
||||
raysampler_type=raysampler_type,
|
||||
min_x=min_x,
|
||||
@@ -258,7 +256,6 @@ class TestRaysampling(TestCaseMixin, unittest.TestCase):
|
||||
OrthographicCameras,
|
||||
PerspectiveCameras,
|
||||
):
|
||||
|
||||
# init a batch of random cameras
|
||||
cameras = init_random_cameras(
|
||||
cam_type, batch_size, random_z=True
|
||||
|
||||
@@ -215,9 +215,7 @@ class TestRenderImplicit(TestCaseMixin, unittest.TestCase):
|
||||
volumetric_function=spherical_volumetric_function,
|
||||
sphere_centroid=sphere_centroid,
|
||||
sphere_diameter=sphere_diameter,
|
||||
)[
|
||||
0
|
||||
]
|
||||
)[0]
|
||||
|
||||
# check that the renderer does not erase gradients
|
||||
loss = images_opacities.sum()
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"""
|
||||
Sanity checks for output images from the renderer.
|
||||
"""
|
||||
|
||||
import os
|
||||
import unittest
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -12,6 +12,7 @@ behind the image plane. These faces are clipped and then rasterized.
|
||||
See pytorch3d/renderer/mesh/clip.py for more details about the
|
||||
clipping process.
|
||||
"""
|
||||
|
||||
import unittest
|
||||
|
||||
import imageio
|
||||
|
||||
@@ -134,7 +134,6 @@ class TestRenderMeshesMultiGPU(TestCaseMixin, unittest.TestCase):
|
||||
self.renderer = self.init_render(device)
|
||||
|
||||
def init_render(self, device):
|
||||
|
||||
cameras = FoVPerspectiveCameras().to(device)
|
||||
raster_settings = RasterizationSettings(
|
||||
image_size=128, blur_radius=0.0, faces_per_pixel=1
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"""
|
||||
Sanity checks for output images from the pointcloud renderer.
|
||||
"""
|
||||
|
||||
import unittest
|
||||
import warnings
|
||||
from os import path
|
||||
@@ -220,7 +221,8 @@ class TestRenderPoints(TestCaseMixin, unittest.TestCase):
|
||||
# znear and zfar is required in this case.
|
||||
self.assertRaises(
|
||||
ValueError,
|
||||
lambda renderer=renderer, pointclouds=pointclouds: renderer.forward(
|
||||
lambda renderer=renderer,
|
||||
pointclouds=pointclouds: renderer.forward(
|
||||
point_clouds=pointclouds, gamma=(1e-4,)
|
||||
),
|
||||
)
|
||||
@@ -233,7 +235,8 @@ class TestRenderPoints(TestCaseMixin, unittest.TestCase):
|
||||
# znear and zfar must be batched.
|
||||
self.assertRaises(
|
||||
TypeError,
|
||||
lambda renderer=renderer, pointclouds=pointclouds: renderer.forward(
|
||||
lambda renderer=renderer,
|
||||
pointclouds=pointclouds: renderer.forward(
|
||||
point_clouds=pointclouds,
|
||||
gamma=(1e-4,),
|
||||
znear=1.0,
|
||||
@@ -242,7 +245,8 @@ class TestRenderPoints(TestCaseMixin, unittest.TestCase):
|
||||
)
|
||||
self.assertRaises(
|
||||
TypeError,
|
||||
lambda renderer=renderer, pointclouds=pointclouds: renderer.forward(
|
||||
lambda renderer=renderer,
|
||||
pointclouds=pointclouds: renderer.forward(
|
||||
point_clouds=pointclouds,
|
||||
gamma=(1e-4,),
|
||||
znear=(1.0,),
|
||||
@@ -253,7 +257,8 @@ class TestRenderPoints(TestCaseMixin, unittest.TestCase):
|
||||
# gamma must be batched.
|
||||
self.assertRaises(
|
||||
TypeError,
|
||||
lambda renderer=renderer, pointclouds=pointclouds: renderer.forward(
|
||||
lambda renderer=renderer,
|
||||
pointclouds=pointclouds: renderer.forward(
|
||||
point_clouds=pointclouds, gamma=1e-4
|
||||
),
|
||||
)
|
||||
@@ -262,7 +267,8 @@ class TestRenderPoints(TestCaseMixin, unittest.TestCase):
|
||||
renderer.rasterizer.raster_settings.image_size = 0
|
||||
self.assertRaises(
|
||||
ValueError,
|
||||
lambda renderer=renderer, pointclouds=pointclouds: renderer.forward(
|
||||
lambda renderer=renderer,
|
||||
pointclouds=pointclouds: renderer.forward(
|
||||
point_clouds=pointclouds, gamma=(1e-4,)
|
||||
),
|
||||
)
|
||||
@@ -372,7 +378,6 @@ class TestRenderPoints(TestCaseMixin, unittest.TestCase):
|
||||
self.assertClose(rgb, image_ref)
|
||||
|
||||
def test_compositor_background_color_rgba(self):
|
||||
|
||||
N, H, W, K, C, P = 1, 15, 15, 20, 4, 225
|
||||
ptclds = torch.randn((C, P))
|
||||
alphas = torch.rand((N, K, H, W))
|
||||
@@ -385,7 +390,6 @@ class TestRenderPoints(TestCaseMixin, unittest.TestCase):
|
||||
]
|
||||
|
||||
for compositor_class, composite_func in compositor_funcs:
|
||||
|
||||
compositor = compositor_class(background_color)
|
||||
|
||||
# run the forward method to generate masked images
|
||||
@@ -423,7 +427,6 @@ class TestRenderPoints(TestCaseMixin, unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_compositor_background_color_rgb(self):
|
||||
|
||||
N, H, W, K, C, P = 1, 15, 15, 20, 3, 225
|
||||
ptclds = torch.randn((C, P))
|
||||
alphas = torch.rand((N, K, H, W))
|
||||
@@ -436,7 +439,6 @@ class TestRenderPoints(TestCaseMixin, unittest.TestCase):
|
||||
]
|
||||
|
||||
for compositor_class, composite_func in compositor_funcs:
|
||||
|
||||
compositor = compositor_class(background_color)
|
||||
|
||||
# run the forward method to generate masked images
|
||||
|
||||
@@ -308,7 +308,6 @@ class TestRenderVolumes(TestCaseMixin, unittest.TestCase):
|
||||
|
||||
# init the boundary volume
|
||||
for shape in ("sphere", "cube"):
|
||||
|
||||
if not DEBUG and shape == "cube":
|
||||
# do not run numeric checks for the cube as the
|
||||
# differences in rendering equations make the renders incomparable
|
||||
@@ -515,7 +514,6 @@ class TestRenderVolumes(TestCaseMixin, unittest.TestCase):
|
||||
|
||||
for shape in ("sphere", "cube"):
|
||||
for sample_mode in ("bilinear", "nearest"):
|
||||
|
||||
volumes = init_boundary_volume(
|
||||
volume_size=volume_size, batch_size=n_frames, shape=shape
|
||||
)[0]
|
||||
@@ -593,7 +591,6 @@ class TestRenderVolumes(TestCaseMixin, unittest.TestCase):
|
||||
|
||||
for volume_size in ([25, 25, 25],):
|
||||
for sample_mode in ("bilinear", "nearest"):
|
||||
|
||||
volume_translation = torch.zeros(4, 3)
|
||||
volume_translation.requires_grad = True
|
||||
volumes, volume_voxel_size, _ = init_boundary_volume(
|
||||
|
||||
@@ -231,7 +231,6 @@ class TestTensorProperties(TestCaseMixin, unittest.TestCase):
|
||||
|
||||
# check both H > W and W > H
|
||||
for flip_axes in [False, True]:
|
||||
|
||||
# non-batched version
|
||||
for xy_ndc, xy_gs in xy_ndc_gs:
|
||||
xy_gs_predicted = ndc_to_grid_sample_coords(
|
||||
|
||||
@@ -301,7 +301,6 @@ class TestSamplePoints(TestCaseMixin, unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_outputs(self):
|
||||
|
||||
for add_texture in (True, False):
|
||||
meshes = init_meshes(device=torch.device("cuda:0"), add_texture=add_texture)
|
||||
out1 = sample_points_from_meshes(meshes, num_samples=100)
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
"""
|
||||
Sanity checks for loading ShapeNetCore.
|
||||
"""
|
||||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
|
||||
@@ -105,7 +105,6 @@ class TestStructUtils(TestCaseMixin, unittest.TestCase):
|
||||
ndim = 2
|
||||
|
||||
for ndim in (2, 3, 4):
|
||||
|
||||
dims = [K] * ndim
|
||||
x = torch.rand([N] + dims, device=device)
|
||||
|
||||
|
||||
@@ -308,9 +308,7 @@ class TestTransform(TestCaseMixin, unittest.TestCase):
|
||||
t1._matrix = torch.FloatTensor(persp_proj)
|
||||
points = torch.tensor(
|
||||
[[0.0, 1.0, 0.0], [0.0, 0.0, 1e-5], [-1.0, 0.0, 1e-5]]
|
||||
).view(
|
||||
1, 3, 3
|
||||
) # a set of points with z-coord very close to 0
|
||||
).view(1, 3, 3) # a set of points with z-coord very close to 0
|
||||
|
||||
proj = t1.transform_points(points)
|
||||
proj_eps = t1.transform_points(points, eps=1e-4)
|
||||
@@ -323,7 +321,6 @@ class TestTransform(TestCaseMixin, unittest.TestCase):
|
||||
|
||||
# generate a random chain of transforms
|
||||
for _ in range(10): # 10 different tries
|
||||
|
||||
# list of transform matrices
|
||||
ts = []
|
||||
|
||||
|
||||
@@ -66,7 +66,6 @@ class TestVolumes(TestCaseMixin, unittest.TestCase):
|
||||
volume_size=(10, 13, 8),
|
||||
dtype=torch.float32,
|
||||
):
|
||||
|
||||
device = torch.device("cuda:0")
|
||||
|
||||
# make sure we have at least 3 volumes to prevent indexing crash
|
||||
@@ -94,7 +93,6 @@ class TestVolumes(TestCaseMixin, unittest.TestCase):
|
||||
for features_, densities_ in zip(
|
||||
(None, features, features_list), (densities, densities, densities_list)
|
||||
):
|
||||
|
||||
# init the volume structure
|
||||
v = Volumes(
|
||||
features=features_,
|
||||
@@ -205,7 +203,6 @@ class TestVolumes(TestCaseMixin, unittest.TestCase):
|
||||
|
||||
# try for 10 sets of different random sizes/centers/voxel_sizes
|
||||
for _ in range(10):
|
||||
|
||||
size = torch.randint(high=10, size=(3,), low=3).tolist()
|
||||
|
||||
densities = torch.randn(
|
||||
@@ -433,7 +430,6 @@ class TestVolumes(TestCaseMixin, unittest.TestCase):
|
||||
|
||||
# try for 10 sets of different random sizes/centers/voxel_sizes
|
||||
for _ in range(10):
|
||||
|
||||
size = torch.randint(high=10, size=(3,), low=3).tolist()
|
||||
|
||||
center = torch.randn(num_volumes, 3, dtype=torch.float32, device=device)
|
||||
@@ -449,7 +445,6 @@ class TestVolumes(TestCaseMixin, unittest.TestCase):
|
||||
num_volumes, 3, size, num_channels, device, rand_sizes=None
|
||||
)[0],
|
||||
):
|
||||
|
||||
# init the volume structure
|
||||
v = Volumes(
|
||||
densities=densities,
|
||||
@@ -794,9 +789,7 @@ class TestVolumes(TestCaseMixin, unittest.TestCase):
|
||||
size=[num_volumes + 1, num_channels, *size],
|
||||
device=device,
|
||||
dtype=torch.float32,
|
||||
).unbind(
|
||||
0
|
||||
), # list with diff batch size
|
||||
).unbind(0), # list with diff batch size
|
||||
torch.randn(
|
||||
size=[num_volumes + 1, num_channels, *size],
|
||||
device=device,
|
||||
@@ -806,9 +799,7 @@ class TestVolumes(TestCaseMixin, unittest.TestCase):
|
||||
size=[num_volumes, num_channels, *diff_size],
|
||||
device=device,
|
||||
dtype=torch.float32,
|
||||
).unbind(
|
||||
0
|
||||
), # list with different size
|
||||
).unbind(0), # list with different size
|
||||
torch.randn(
|
||||
size=[num_volumes, num_channels, *diff_size],
|
||||
device=device,
|
||||
@@ -823,9 +814,7 @@ class TestVolumes(TestCaseMixin, unittest.TestCase):
|
||||
size=[num_volumes, num_channels, *size],
|
||||
device=diff_device,
|
||||
dtype=torch.float32,
|
||||
).unbind(
|
||||
0
|
||||
), # list with different device
|
||||
).unbind(0), # list with different device
|
||||
]
|
||||
|
||||
# good ways to define features
|
||||
@@ -834,9 +823,7 @@ class TestVolumes(TestCaseMixin, unittest.TestCase):
|
||||
size=[num_volumes, num_channels, *size],
|
||||
device=device,
|
||||
dtype=torch.float32,
|
||||
).unbind(
|
||||
0
|
||||
), # list of features of correct size
|
||||
).unbind(0), # list of features of correct size
|
||||
torch.randn(
|
||||
size=[num_volumes, num_channels, *size],
|
||||
device=device,
|
||||
@@ -872,9 +859,7 @@ class TestVolumes(TestCaseMixin, unittest.TestCase):
|
||||
size=[num_volumes, num_channels, *size],
|
||||
device=device,
|
||||
dtype=torch.float32,
|
||||
).unbind(
|
||||
0
|
||||
), # list of features
|
||||
).unbind(0), # list of features
|
||||
None, # no features
|
||||
]
|
||||
|
||||
@@ -890,9 +875,7 @@ class TestVolumes(TestCaseMixin, unittest.TestCase):
|
||||
), # 4 dims
|
||||
torch.randn(
|
||||
size=[num_volumes, *size], device=device, dtype=torch.float32
|
||||
).unbind(
|
||||
0
|
||||
), # list of 4 dim tensors
|
||||
).unbind(0), # list of 4 dim tensors
|
||||
]
|
||||
|
||||
# all ways to define densities
|
||||
@@ -902,9 +885,7 @@ class TestVolumes(TestCaseMixin, unittest.TestCase):
|
||||
), # padded tensor
|
||||
torch.randn(
|
||||
size=[num_volumes, 1, *size], device=device, dtype=torch.float32
|
||||
).unbind(
|
||||
0
|
||||
), # list of densities
|
||||
).unbind(0), # list of densities
|
||||
]
|
||||
|
||||
# bad ways to define densities
|
||||
@@ -915,9 +896,7 @@ class TestVolumes(TestCaseMixin, unittest.TestCase):
|
||||
), # 6-dim tensor
|
||||
torch.randn(
|
||||
size=[num_volumes, 1, 1, *size], device=device, dtype=torch.float32
|
||||
).unbind(
|
||||
0
|
||||
), # list of 5-dim densities
|
||||
).unbind(0), # list of 5-dim densities
|
||||
]
|
||||
|
||||
# all possible ways to define the voxels sizes
|
||||
|
||||
Reference in New Issue
Block a user