mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-08-02 03:42:50 +08:00
Summary: There are a couple of options for supporting non square images: 1) NDC stays at [-1, 1] in both directions with the distance calculations all modified by (W/H). There are a lot of distance based calculations (e.g. triangle areas for barycentric coordinates etc) so this requires changes in many places. 2) NDC is scaled by (W/H) so the smallest side has [-1, 1]. In this case none of the distance calculations need to be updated and only the pixel to NDC calculation needs to be modified. I decided to go with option 2 after trying option 1! API Changes: - Image size can now be specified optionally as a tuple TODO: - add a benchmark test for the non square case. Reviewed By: jcjohnson Differential Revision: D24404975 fbshipit-source-id: 545efb67c822d748ec35999b35762bce58db2cf4
93 lines
2.4 KiB
Python
93 lines
2.4 KiB
Python
# 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)
|
|
# 5: (10242 verts, 20480 faces)
|
|
# 6: (40962 verts, 81920 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,
|
|
"faces_per_pixel": 3,
|
|
}
|
|
]
|
|
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 = [1e-6]
|
|
faces_per_pixel = [3, 50]
|
|
test_cases = product(num_meshes, ico_level, image_size, blur, faces_per_pixel)
|
|
for case in test_cases:
|
|
n, ic, im, b, f = case
|
|
kwargs_list.append(
|
|
{
|
|
"num_meshes": n,
|
|
"ico_level": ic,
|
|
"image_size": im,
|
|
"blur_radius": b,
|
|
"faces_per_pixel": f,
|
|
}
|
|
)
|
|
benchmark(
|
|
TestRasterizeMeshes.rasterize_meshes_cpu_with_init,
|
|
"RASTERIZE_MESHES",
|
|
kwargs_list,
|
|
warmup_iters=1,
|
|
)
|
|
|
|
if torch.cuda.is_available():
|
|
kwargs_list = []
|
|
num_meshes = [8, 16]
|
|
ico_level = [4, 5, 6]
|
|
# Square and non square cases
|
|
image_size = [64, 128, 512, (512, 256), (256, 512)]
|
|
blur = [1e-6]
|
|
faces_per_pixel = [50]
|
|
test_cases = product(num_meshes, ico_level, image_size, blur, faces_per_pixel)
|
|
|
|
for case in test_cases:
|
|
n, ic, im, b, f = case
|
|
kwargs_list.append(
|
|
{
|
|
"num_meshes": n,
|
|
"ico_level": ic,
|
|
"image_size": im,
|
|
"blur_radius": b,
|
|
"faces_per_pixel": f,
|
|
}
|
|
)
|
|
benchmark(
|
|
TestRasterizeMeshes.rasterize_meshes_cuda_with_init,
|
|
"RASTERIZE_MESHES_CUDA",
|
|
kwargs_list,
|
|
warmup_iters=1,
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
bm_rasterize_meshes()
|