From d3c533fd183eacdbeb149fc5889f36c5870d9e7d Mon Sep 17 00:00:00 2001 From: Thomas Pickles <thomas.pickles@ens-lyon.fr> Date: Fri, 3 Mar 2023 10:54:41 +0100 Subject: [PATCH] Output slices from command line Fixed bug in testbed code --- scripts/run.py | 18 ++++++++++-------- src/python_api.cu | 8 ++++---- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/scripts/run.py b/scripts/run.py index 489ad8a..526b191 100644 --- a/scripts/run.py +++ b/scripts/run.py @@ -57,6 +57,9 @@ def parse_args(): parser.add_argument("--save_mesh", default="", help="Output a marching-cubes based mesh from the NeRF or SDF model. Supports OBJ and PLY format.") parser.add_argument("--marching_cubes_res", default=256, type=int, help="Sets the resolution for the marching cubes grid.") + parser.add_argument("--save_slices", action="store_true", help="Output slices after training.") + parser.add_argument("--slices_res", default=256, type=int, help="Sets the resolution for the slices png.") + parser.add_argument("--width", "--screenshot_w", type=int, default=0, help="Resolution width of GUI and screenshots.") parser.add_argument("--height", "--screenshot_h", type=int, default=0, help="Resolution height of GUI and screenshots.") @@ -69,7 +72,7 @@ def parse_args(): parser.add_argument("--sharpen", default=0, help="Set amount of sharpening applied to NeRF training images. Range 0.0 to 1.0.") # parser.add_argument("--tomonerf", action="store_true", help="Apply tomography specific parameters to optimise NeRF output.") - parser.add_argument("--tomonerf", type=str, help="Which transforms to apply [single_channel, exponentiate img data, crop].") + parser.add_argument("--tomonerf", type=int, default=0, help="Which transforms to apply [single_channel, exponentiate img data, crop].") parser.add_argument("--crop", nargs=3, type=float, help="Percentage to crop unit cube to.") return parser.parse_args() @@ -128,13 +131,6 @@ if __name__ == "__main__": if args.tomonerf: print("***Entering NERF for Tomography mode***") - print(f"Saving density slices (no crop)") - # vertical slices - fname = "string" - # FIXME - doesn't work from command line yet - # testbed.compute_and_save_png_slices() - # testbed.compute_and_save_png_slices_vert() - # testbed.compute_and_save_png_slices('horiz', flip_y_and_z_axes=True) if (format(args.tomonerf, 'b')[-1] == '1'): print("TODO: Single channel mode") @@ -259,6 +255,12 @@ if __name__ == "__main__": if args.save_snapshot: testbed.save_snapshot(args.save_snapshot, False) + if args.save_slices: + res = args.slices_res or 256 + # does this work here? + testbed.compute_and_save_png_slices("slices_h", res) + testbed.compute_and_save_png_slices_vert("slices_v", res) + if args.test_transforms: print("Evaluating test transforms from ", args.test_transforms) with open(args.test_transforms) as f: diff --git a/src/python_api.cu b/src/python_api.cu index 299d01d..7f8b4f8 100644 --- a/src/python_api.cu +++ b/src/python_api.cu @@ -421,8 +421,8 @@ PYBIND11_MODULE(pyngp, m) { .def("load_file", &Testbed::load_file, py::arg("path"), "Load a file and automatically determine how to handle it. Can be a snapshot, dataset, network config, or camera path.") .def_property("loop_animation", &Testbed::loop_animation, &Testbed::set_loop_animation) .def("compute_and_save_png_slices", &Testbed::compute_and_save_png_slices, - py::arg("filename") = "horiz", - py::arg("resolution") = Eigen::Vector3i::Constant(256), + py::arg("filename"), + py::arg("resolution") = 256, py::arg("aabb") = BoundingBox{}, py::arg("thresh") = std::numeric_limits<float>::max(), py::arg("density_range") = 4.f, @@ -430,8 +430,8 @@ PYBIND11_MODULE(pyngp, m) { "Compute & save a PNG file representing the 3D density or distance field from the current SDF or NeRF model. " ) .def("compute_and_save_png_slices_vert", &Testbed::compute_and_save_png_slices, - py::arg("filename") = "vert", - py::arg("resolution") = Eigen::Vector3i::Constant(256), + py::arg("filename"), + py::arg("resolution") = 256, py::arg("aabb") = BoundingBox{}, py::arg("thresh") = std::numeric_limits<float>::max(), py::arg("density_range") = 4.f, -- GitLab