Commit dbf06b50 authored by facebook-github-bot's avatar facebook-github-bot
Browse files

Initial commit

fbshipit-source-id: ad58e416e3ceeca85fae0583308968d04e78fe0d
parents
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
from fvcore.common.benchmark import benchmark
from test_obj_io import TestMeshObjIO
from test_ply_io import TestMeshPlyIO
def bm_save_load() -> None:
kwargs_list = [
{"V": 100, "F": 300},
{"V": 1000, "F": 3000},
{"V": 10000, "F": 30000},
]
benchmark(
TestMeshObjIO.load_obj_with_init,
"LOAD_OBJ",
kwargs_list,
warmup_iters=1,
)
benchmark(
TestMeshObjIO.save_obj_with_init,
"SAVE_OBJ",
kwargs_list,
warmup_iters=1,
)
benchmark(
TestMeshPlyIO.load_ply_bm, "LOAD_PLY", kwargs_list, warmup_iters=1
)
benchmark(
TestMeshPlyIO.save_ply_bm, "SAVE_PLY", kwargs_list, warmup_iters=1
)
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from itertools import product
import torch
from fvcore.common.benchmark import benchmark
from test_mesh_laplacian_smoothing import TestLaplacianSmoothing
def bm_mesh_laplacian_smoothing() -> None:
devices = ["cpu"]
if torch.cuda.is_available():
devices.append("cuda")
kwargs_list = []
num_meshes = [2, 10, 32]
num_verts = [100, 1000]
num_faces = [300, 3000]
test_cases = product(num_meshes, num_verts, num_faces, devices)
for case in test_cases:
n, v, f, d = case
kwargs_list.append(
{"num_meshes": n, "num_verts": v, "num_faces": f, "device": d}
)
benchmark(
TestLaplacianSmoothing.laplacian_smoothing_with_init,
"MESH_LAPLACIAN_SMOOTHING",
kwargs_list,
warmup_iters=1,
)
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from itertools import product
import torch
from fvcore.common.benchmark import benchmark
from test_mesh_normal_consistency import TestMeshNormalConsistency
def bm_mesh_normal_consistency() -> None:
devices = ["cpu"]
if torch.cuda.is_available():
devices.append("cuda")
kwargs_list = []
num_meshes = [16, 32, 64]
levels = [2, 3]
test_cases = product(num_meshes, levels, devices)
for case in test_cases:
n, l, d = case
kwargs_list.append({"num_meshes": n, "level": l, "device": d})
benchmark(
TestMeshNormalConsistency.mesh_normal_consistency_with_ico,
"MESH_NORMAL_CONSISTENCY_ICO",
kwargs_list,
warmup_iters=1,
)
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
from itertools import product
import torch
from fvcore.common.benchmark import benchmark
from test_meshes import TestMeshes
def bm_compute_packed_padded_meshes() -> None:
devices = ["cpu"]
if torch.cuda.is_available():
devices.append("cuda")
kwargs_list = []
num_meshes = [32, 128]
max_v = [100, 1000, 10000]
max_f = [300, 3000, 30000]
test_cases = product(num_meshes, max_v, max_f, devices)
for case in test_cases:
n, v, f, d = case
kwargs_list.append(
{"num_meshes": n, "max_v": v, "max_f": f, "device": d}
)
benchmark(
TestMeshes.compute_packed_with_init,
"COMPUTE_PACKED",
kwargs_list,
warmup_iters=1,
)
benchmark(
TestMeshes.compute_padded_with_init,
"COMPUTE_PADDED",
kwargs_list,
warmup_iters=1,
)
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
from itertools import product
import torch
from fvcore.common.benchmark import benchmark
from test_nearest_neighbor_points import TestNearestNeighborPoints
def bm_nn_points() -> None:
kwargs_list = []
N = [1, 4, 32]
D = [3, 4]
P1 = [1, 128]
P2 = [32, 128]
test_cases = product(N, D, P1, P2)
for case in test_cases:
n, d, p1, p2 = case
kwargs_list.append({"N": n, "D": d, "P1": p1, "P2": p2})
benchmark(
TestNearestNeighborPoints.bm_nn_points_python_with_init,
"NN_PYTHON",
kwargs_list,
warmup_iters=1,
)
if torch.cuda.is_available():
benchmark(
TestNearestNeighborPoints.bm_nn_points_cuda_with_init,
"NN_CUDA",
kwargs_list,
warmup_iters=1,
)
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
from itertools import product
import torch
from fvcore.common.benchmark import benchmark
from test_rasterize_meshes import TestRasterizeMeshes
# ico levels:
# 0: (12 verts, 20 faces)
# 1: (42 verts, 80 faces)
# 3: (642 verts, 1280 faces)
# 4: (2562 verts, 5120 faces)
def bm_rasterize_meshes() -> None:
kwargs_list = [
{
"num_meshes": 1,
"ico_level": 0,
"image_size": 10, # very slow with large image size
"blur_radius": 0.0,
}
]
benchmark(
TestRasterizeMeshes.rasterize_meshes_python_with_init,
"RASTERIZE_MESHES",
kwargs_list,
warmup_iters=1,
)
kwargs_list = []
num_meshes = [1]
ico_level = [1]
image_size = [64, 128]
blur = [0.0, 1e-8, 1e-4]
test_cases = product(num_meshes, ico_level, image_size, blur)
for case in test_cases:
n, ic, im, b = case
kwargs_list.append(
{
"num_meshes": n,
"ico_level": ic,
"image_size": im,
"blur_radius": b,
}
)
benchmark(
TestRasterizeMeshes.rasterize_meshes_cpu_with_init,
"RASTERIZE_MESHES",
kwargs_list,
warmup_iters=1,
)
if torch.cuda.is_available():
kwargs_list = []
num_meshes = [1, 8]
ico_level = [0, 1, 3, 4]
image_size = [64, 128, 512]
blur = [0.0, 1e-8, 1e-4]
bin_size = [0, 8, 32]
test_cases = product(num_meshes, ico_level, image_size, blur, bin_size)
# only keep cases where bin_size == 0 or image_size / bin_size < 16
test_cases = [
elem
for elem in test_cases
if (elem[-1] == 0 or elem[-3] / elem[-1] < 16)
]
for case in test_cases:
n, ic, im, b, bn = case
kwargs_list.append(
{
"num_meshes": n,
"ico_level": ic,
"image_size": im,
"blur_radius": b,
"bin_size": bn,
"max_faces_per_bin": 200,
}
)
benchmark(
TestRasterizeMeshes.rasterize_meshes_cuda_with_init,
"RASTERIZE_MESHES_CUDA",
kwargs_list,
warmup_iters=1,
)
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
from itertools import product
import torch
from fvcore.common.benchmark import benchmark
from test_sample_points_from_meshes import TestSamplePoints
def bm_sample_points() -> None:
if torch.cuda.is_available():
device = "cuda:0"
kwargs_list = []
num_meshes = [2, 10, 32]
num_verts = [100, 1000]
num_faces = [300, 3000]
num_samples = [5000, 10000]
test_cases = product(num_meshes, num_verts, num_faces, num_samples)
for case in test_cases:
n, v, f, s = case
kwargs_list.append(
{
"num_meshes": n,
"num_verts": v,
"num_faces": f,
"num_samples": s,
"device": device,
}
)
benchmark(
TestSamplePoints.sample_points_with_init,
"SAMPLE_MESH",
kwargs_list,
warmup_iters=1,
)
kwargs_list = []
backend_cuda = ["False"]
if torch.cuda.is_available():
backend_cuda.append("True")
num_meshes = [2, 10, 32]
num_verts = [100, 1000]
num_faces = [300, 3000]
test_cases = product(num_meshes, num_verts, num_faces, backend_cuda)
for case in test_cases:
n, v, f, c = case
kwargs_list.append(
{"num_meshes": n, "num_verts": v, "num_faces": f, "cuda": c}
)
benchmark(
TestSamplePoints.face_areas_with_init,
"FACE_AREAS",
kwargs_list,
warmup_iters=1,
)
benchmark(
TestSamplePoints.packed_to_padded_with_init,
"PACKED_TO_PADDED",
kwargs_list,
warmup_iters=1,
)
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
from fvcore.common.benchmark import benchmark
from test_so3 import TestSO3
def bm_so3() -> None:
kwargs_list = [
{"batch_size": 1},
{"batch_size": 10},
{"batch_size": 100},
{"batch_size": 1000},
]
benchmark(TestSO3.so3_expmap, "SO3_EXP", kwargs_list, warmup_iters=1)
benchmark(TestSO3.so3_logmap, "SO3_LOG", kwargs_list, warmup_iters=1)
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
from itertools import product
from fvcore.common.benchmark import benchmark
from test_subdivide_meshes import TestSubdivideMeshes
def bm_subdivide() -> None:
kwargs_list = []
num_meshes = [1, 16, 32]
same_topo = [True, False]
test_cases = product(num_meshes, same_topo)
for case in test_cases:
n, s = case
kwargs_list.append({"num_meshes": n, "same_topo": s})
benchmark(
TestSubdivideMeshes.subdivide_meshes_with_init,
"SUBDIVIDE",
kwargs_list,
warmup_iters=1,
)
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
from itertools import product
import torch
from fvcore.common.benchmark import benchmark
from test_vert_align import TestVertAlign
def bm_vert_align() -> None:
devices = ["cpu"]
if torch.cuda.is_available():
devices.append("cuda")
kwargs_list = []
num_meshes = [2, 10, 32]
num_verts = [100, 1000]
num_faces = [300, 3000]
test_cases = product(num_meshes, num_verts, num_faces, devices)
for case in test_cases:
n, v, f, d = case
kwargs_list.append(
{"num_meshes": n, "num_verts": v, "num_faces": f, "device": d}
)
benchmark(
TestVertAlign.vert_align_with_init,
"VERT_ALIGN",
kwargs_list,
warmup_iters=1,
)
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
import numpy as np
import unittest
import torch
class TestCaseMixin(unittest.TestCase):
def assertSeparate(self, tensor1, tensor2) -> None:
"""
Verify that tensor1 and tensor2 have their data in distinct locations.
"""
self.assertNotEqual(
tensor1.storage().data_ptr(), tensor2.storage().data_ptr()
)
def assertAllSeparate(self, tensor_list) -> None:
"""
Verify that all tensors in tensor_list have their data in
distinct locations.
"""
ptrs = [i.storage().data_ptr() for i in tensor_list]
self.assertCountEqual(ptrs, set(ptrs))
def assertClose(
self,
input,
other,
*,
rtol: float = 1e-05,
atol: float = 1e-08,
equal_nan: bool = False
) -> None:
"""
Verify that two tensors or arrays are the same shape and close.
Args:
input, other: two tensors or two arrays.
rtol, atol, equal_nan: as for torch.allclose.
Note:
Optional arguments here are all keyword-only, to avoid confusion
with msg arguments on other assert functions.
"""
self.assertEqual(np.shape(input), np.shape(other))
if torch.is_tensor(input):
close = torch.allclose(
input, other, rtol=rtol, atol=atol, equal_nan=equal_nan
)
else:
close = np.allclose(
input, other, rtol=rtol, atol=atol, equal_nan=equal_nan
)
self.assertTrue(close)
newmtl material_1
map_Kd material_1.png
# Test colors
Ka 1.000 1.000 1.000 # white
Kd 1.000 1.000 1.000 # white
Ks 0.000 0.000 0.000 # black
Ns 10.0
mtllib model.mtl
v 0.1 0.2 0.3
v 0.2 0.3 0.4
v 0.3 0.4 0.5
v 0.4 0.5 0.6
usemtl material_1
f 1 2 3
f 1 2 4
mtllib model2.mtl
v 0.1 0.2 0.3
v 0.2 0.3 0.4
v 0.3 0.4 0.5
v 0.4 0.5 0.6
usemtl material_1
f 1 2 3
f 1 2 4
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment