diff --git a/projects/nerf/__init__.py b/projects/nerf/__init__.py index 16234db9..40539064 100644 --- a/projects/nerf/__init__.py +++ b/projects/nerf/__init__.py @@ -1 +1 @@ -# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved +# Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. diff --git a/pytorch3d/csrc/blending/sigmoid_alpha_blend.cu b/pytorch3d/csrc/blending/sigmoid_alpha_blend.cu index 7554e874..84e9529a 100644 --- a/pytorch3d/csrc/blending/sigmoid_alpha_blend.cu +++ b/pytorch3d/csrc/blending/sigmoid_alpha_blend.cu @@ -9,9 +9,9 @@ template __global__ void SigmoidAlphaBlendForwardKernel( // clang-format off - const torch::PackedTensorAccessor distances, // (N, H, W, K) - const torch::PackedTensorAccessor pix_to_face, // (N, H, W, K) - torch::PackedTensorAccessor alphas, // (N, H, W) + const torch::PackedTensorAccessor64 distances, // (N, H, W, K) + const torch::PackedTensorAccessor64 pix_to_face, // (N, H, W, K) + torch::PackedTensorAccessor64 alphas, // (N, H, W) // clang-format on const scalar_t sigma, const int N, @@ -93,9 +93,9 @@ torch::Tensor SigmoidAlphaBlendForwardCuda( distances.scalar_type(), "sigmoid_alpha_blend_kernel", ([&] { // clang-format off SigmoidAlphaBlendForwardKernel<<>>( - distances.packed_accessor(), - pix_to_face.packed_accessor(), - alphas.packed_accessor(), + distances.packed_accessor64(), + pix_to_face.packed_accessor64(), + alphas.packed_accessor64(), sigma, N, H, @@ -111,11 +111,11 @@ torch::Tensor SigmoidAlphaBlendForwardCuda( template __global__ void SigmoidAlphaBlendBackwardKernel( // clang-format off - const torch::PackedTensorAccessor grad_alphas, // (N, H, W) - const torch::PackedTensorAccessor alphas, // (N, H, W) - const torch::PackedTensorAccessor distances, // (N, H, W, K) - const torch::PackedTensorAccessor pix_to_face, // (N, H, W, K) - torch::PackedTensorAccessor grad_distances, // (N, H, W) + const torch::PackedTensorAccessor64 grad_alphas, // (N, H, W) + const torch::PackedTensorAccessor64 alphas, // (N, H, W) + const torch::PackedTensorAccessor64 distances, // (N, H, W, K) + const torch::PackedTensorAccessor64 pix_to_face, // (N, H, W, K) + torch::PackedTensorAccessor64 grad_distances, // (N, H, W) // clang-format on const scalar_t sigma, const int N, @@ -192,11 +192,11 @@ torch::Tensor SigmoidAlphaBlendBackwardCuda( SigmoidAlphaBlendBackwardKernel <<>>( // clang-format off - grad_alphas.packed_accessor(), - alphas.packed_accessor(), - distances.packed_accessor(), - pix_to_face.packed_accessor(), - grad_distances.packed_accessor(), + grad_alphas.packed_accessor64(), + alphas.packed_accessor64(), + distances.packed_accessor64(), + pix_to_face.packed_accessor64(), + grad_distances.packed_accessor64(), // clang-format on sigma, N, diff --git a/pytorch3d/csrc/pulsar/pytorch/renderer.cpp b/pytorch3d/csrc/pulsar/pytorch/renderer.cpp index d58c1489..69f3420e 100644 --- a/pytorch3d/csrc/pulsar/pytorch/renderer.cpp +++ b/pytorch3d/csrc/pulsar/pytorch/renderer.cpp @@ -214,57 +214,63 @@ std::tuple Renderer::arg_check( batch_processing = true; batch_size = vert_pos.size(0); THArgCheck( - vert_col.ndimension() == 3 && vert_col.size(0) == batch_size, + vert_col.ndimension() == 3 && + vert_col.size(0) == static_cast(batch_size), 2, "vert_col needs to have batch size."); THArgCheck( - vert_radii.ndimension() == 2 && vert_radii.size(0) == batch_size, + vert_radii.ndimension() == 2 && + vert_radii.size(0) == static_cast(batch_size), 3, "vert_radii must be specified per batch."); THArgCheck( - cam_pos.ndimension() == 2 && cam_pos.size(0) == batch_size, + cam_pos.ndimension() == 2 && + cam_pos.size(0) == static_cast(batch_size), 4, "cam_pos must be specified per batch and have the correct batch size."); THArgCheck( pixel_0_0_center.ndimension() == 2 && - pixel_0_0_center.size(0) == batch_size, + pixel_0_0_center.size(0) == static_cast(batch_size), 5, "pixel_0_0_center must be specified per batch."); THArgCheck( - pixel_vec_x.ndimension() == 2 && pixel_vec_x.size(0) == batch_size, + pixel_vec_x.ndimension() == 2 && + pixel_vec_x.size(0) == static_cast(batch_size), 6, "pixel_vec_x must be specified per batch."); THArgCheck( - pixel_vec_y.ndimension() == 2 && pixel_vec_y.size(0) == batch_size, + pixel_vec_y.ndimension() == 2 && + pixel_vec_y.size(0) == static_cast(batch_size), 7, "pixel_vec_y must be specified per batch."); THArgCheck( - focal_length.ndimension() == 1 && focal_length.size(0) == batch_size, + focal_length.ndimension() == 1 && + focal_length.size(0) == static_cast(batch_size), 8, "focal_length must be specified per batch."); THArgCheck( principal_point_offsets.ndimension() == 2 && - principal_point_offsets.size(0) == batch_size, + principal_point_offsets.size(0) == static_cast(batch_size), 9, "principal_point_offsets must be specified per batch."); if (opacity.has_value()) { THArgCheck( opacity.value().ndimension() == 2 && - opacity.value().size(0) == batch_size, + opacity.value().size(0) == static_cast(batch_size), 13, "Opacity needs to be specified batch-wise."); } // Check all parameters are for a matching number of points. n_points = vert_pos.size(1); THArgCheck( - vert_col.size(1) == n_points, + vert_col.size(1) == static_cast(n_points), 2, ("The number of points for vertex positions (" + std::to_string(n_points) + ") and vertex colors (" + std::to_string(vert_col.size(1)) + ") doesn't agree.") .c_str()); THArgCheck( - vert_radii.size(1) == n_points, + vert_radii.size(1) == static_cast(n_points), 3, ("The number of points for vertex positions (" + std::to_string(n_points) + ") and vertex radii (" + @@ -272,7 +278,7 @@ std::tuple Renderer::arg_check( .c_str()); if (opacity.has_value()) { THArgCheck( - opacity.value().size(1) == n_points, + opacity.value().size(1) == static_cast(n_points), 13, "Opacity needs to be specified per point."); } @@ -352,14 +358,14 @@ std::tuple Renderer::arg_check( // Check each. n_points = vert_pos.size(0); THArgCheck( - vert_col.size(0) == n_points, + vert_col.size(0) == static_cast(n_points), 2, ("The number of points for vertex positions (" + std::to_string(n_points) + ") and vertex colors (" + std::to_string(vert_col.size(0)) + ") doesn't agree.") .c_str()); THArgCheck( - vert_radii.size(0) == n_points, + vert_radii.size(0) == static_cast(n_points), 3, ("The number of points for vertex positions (" + std::to_string(n_points) + ") and vertex radii (" + @@ -367,7 +373,7 @@ std::tuple Renderer::arg_check( .c_str()); if (opacity.has_value()) { THArgCheck( - opacity.value().size(0) == n_points, + opacity.value().size(0) == static_cast(n_points), 12, "Opacity needs to be specified per point."); } @@ -958,12 +964,15 @@ Renderer::backward( } if (batch_processing) { THArgCheck( - grad_im.size(0) == batch_size, + grad_im.size(0) == static_cast(batch_size), 1, "Gradient image batch size must agree."); - THArgCheck(image.size(0) == batch_size, 2, "Image batch size must agree."); THArgCheck( - forw_info.size(0) == batch_size, + image.size(0) == static_cast(batch_size), + 2, + "Image batch size must agree."); + THArgCheck( + forw_info.size(0) == static_cast(batch_size), 3, "forward info must have batch size."); } diff --git a/pytorch3d/csrc/rasterize_meshes/rasterize_meshes_cpu.cpp b/pytorch3d/csrc/rasterize_meshes/rasterize_meshes_cpu.cpp index 4b925f02..6659e3a6 100644 --- a/pytorch3d/csrc/rasterize_meshes/rasterize_meshes_cpu.cpp +++ b/pytorch3d/csrc/rasterize_meshes/rasterize_meshes_cpu.cpp @@ -291,8 +291,8 @@ RasterizeMeshesNaiveCpu( const float dist_neighbor = std::abs(std::get<2>(neighbor)); if (dist < dist_neighbor) { // Overwrite the neighbor face values. - q[idx_top_k] = { - pz, f, signed_dist, bary_clip.x, bary_clip.y, bary_clip.z}; + q[idx_top_k] = std::make_tuple( + pz, f, signed_dist, bary_clip.x, bary_clip.y, bary_clip.z); } } else { // Handle as a normal face. diff --git a/tests/test_build.py b/tests/test_build.py index e93e3db2..1c4fe2cb 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -1,4 +1,5 @@ # Copyright (c) Facebook, Inc. and its affiliates. All rights reserved. +import json import os import unittest from collections import Counter @@ -39,18 +40,33 @@ class TestBuild(unittest.TestCase): + " All rights reserved.\n" ) + files_missing_copyright_header = [] + for extension in extensions: - for i in root_dir.glob(f"**/*.{extension}"): - if str(i).endswith( + for path in root_dir.glob(f"**/*.{extension}"): + if str(path).endswith( "pytorch3d/transforms/external/kornia_angle_axis_to_rotation_matrix.py" ): continue - if str(i).endswith("pytorch3d/csrc/pulsar/include/fastermath.h"): + if str(path).endswith("pytorch3d/csrc/pulsar/include/fastermath.h"): continue - with open(i) as f: + with open(path) as f: firstline = f.readline() if firstline.startswith(("# -*-", "#!")): firstline = f.readline() - self.assertTrue( - firstline.endswith(expect), f"{i} missing copyright header." - ) + if not firstline.endswith(expect): + files_missing_copyright_header.append(str(path)) + + if len(files_missing_copyright_header) != 0: + self.fail("\n".join(files_missing_copyright_header)) + + @unittest.skipIf(in_conda_build, "In conda build") + def test_valid_ipynbs(self): + # Check that the ipython notebooks are valid json + test_dir = Path(__file__).resolve().parent + tutorials_dir = test_dir.parent / "docs" / "tutorials" + tutorials = sorted(tutorials_dir.glob("*.ipynb")) + + for tutorial in tutorials: + with open(tutorial) as f: + json.load(f)