diff --git a/docs/generate_implicitron_stubs.py b/docs/generate_implicitron_stubs.py index 2a2e54dd..3404136e 100755 --- a/docs/generate_implicitron_stubs.py +++ b/docs/generate_implicitron_stubs.py @@ -49,7 +49,7 @@ def iterate_directory(directory_path, dest): toc = [] if not dest.exists(): dest.mkdir() - for file in directory_path.glob("*.py"): + for file in sorted(directory_path.glob("*.py")): if file.stem.startswith("_"): continue module = paths_to_modules([file]) @@ -121,7 +121,7 @@ basic_dataset = [ ] basic_dataset_modules = [f"pytorch3d.implicitron.dataset.{i}" for i in basic_dataset] create_one_file( - "pytorch3d.implicitron.dataset", + "pytorch3d.implicitron.dataset in general", "Basics of data for implicitron", basic_dataset_modules, DEST_DIR / "data_basics.rst", @@ -131,7 +131,7 @@ specific_dataset_files = [ i for i in dataset_files if i.stem.find("_dataset_map_provider") != -1 ] create_one_file( - "pytorch3d.impliciton.dataset", + "pytorch3d.implicitron.dataset specific datasets", "specific datasets", paths_to_modules(specific_dataset_files), DEST_DIR / "datasets.rst", @@ -139,7 +139,7 @@ create_one_file( evaluation_files = sorted(ROOT_DIR.glob("pytorch3d/implicitron/evaluation/*.py")) create_one_file( - "pytorch3d.impliciton.evaluation", + "pytorch3d.implicitron.evaluation", "evaluation", paths_to_modules(evaluation_files), DEST_DIR / "evaluation.rst", diff --git a/docs/modules/implicitron/data_basics.rst b/docs/modules/implicitron/data_basics.rst index 078e0762..3d0bdd87 100644 --- a/docs/modules/implicitron/data_basics.rst +++ b/docs/modules/implicitron/data_basics.rst @@ -1,5 +1,5 @@ -pytorch3d.implicitron.dataset -============================= +pytorch3d.implicitron.dataset in general +======================================== Basics of data for implicitron diff --git a/docs/modules/implicitron/datasets.rst b/docs/modules/implicitron/datasets.rst index 144afb41..f012fe8b 100644 --- a/docs/modules/implicitron/datasets.rst +++ b/docs/modules/implicitron/datasets.rst @@ -1,5 +1,5 @@ -pytorch3d.impliciton.dataset -============================ +pytorch3d.implicitron.dataset specific datasets +=============================================== specific datasets diff --git a/docs/modules/implicitron/evaluation.rst b/docs/modules/implicitron/evaluation.rst index 326f5557..094d22e3 100644 --- a/docs/modules/implicitron/evaluation.rst +++ b/docs/modules/implicitron/evaluation.rst @@ -1,5 +1,5 @@ -pytorch3d.impliciton.evaluation -=============================== +pytorch3d.implicitron.evaluation +================================ evaluation diff --git a/docs/modules/implicitron/models/implicit_function/index.rst b/docs/modules/implicitron/models/implicit_function/index.rst index 343c377b..60fdcd7a 100644 --- a/docs/modules/implicitron/models/implicit_function/index.rst +++ b/docs/modules/implicitron/models/implicit_function/index.rst @@ -4,10 +4,10 @@ pytorch3d.implicitron.models.implicit_function .. toctree:: base + decoding_functions idr_feature_field neural_radiance_field scene_representation_networks utils - decoding_functions voxel_grid voxel_grid_implicit_function diff --git a/pytorch3d/implicitron/dataset/json_index_dataset_map_provider_v2.py b/pytorch3d/implicitron/dataset/json_index_dataset_map_provider_v2.py index 3c152f92..7f3d1a8a 100644 --- a/pytorch3d/implicitron/dataset/json_index_dataset_map_provider_v2.py +++ b/pytorch3d/implicitron/dataset/json_index_dataset_map_provider_v2.py @@ -57,8 +57,8 @@ class JsonIndexDatasetMapProviderV2(DatasetMapProviderBase): # pyre-ignore [13] Generates the training, validation, and testing dataset objects for a dataset laid out on disk like CO3Dv2, with annotations in gzipped json files. - The dataset is organized in the filesystem as follows: - ``` + The dataset is organized in the filesystem as follows:: + self.dataset_root ├── │ ├── @@ -90,7 +90,6 @@ class JsonIndexDatasetMapProviderV2(DatasetMapProviderBase): # pyre-ignore [13] ├── ├── ... ├── - ``` The dataset contains sequences named `` from `K` categories with names ``. Each category comprises sequence folders @@ -106,8 +105,8 @@ class JsonIndexDatasetMapProviderV2(DatasetMapProviderBase): # pyre-ignore [13] the list of all frames and sequences of the given category stored as lists of `FrameAnnotation` and `SequenceAnnotation` objects respectivelly. - Each `set_lists_.json` file contains the following dictionary: - ``` + Each `set_lists_.json` file contains the following dictionary:: + { "train": [ (sequence_name: str, frame_number: int, image_path: str), @@ -122,7 +121,7 @@ class JsonIndexDatasetMapProviderV2(DatasetMapProviderBase): # pyre-ignore [13] ... ], ] - ``` + defining the list of frames (identified with their `sequence_name` and `frame_number`) in the "train", "val", and "test" subsets of the dataset. Note that `frame_number` can be obtained only from `frame_annotations.jgz` and @@ -131,8 +130,8 @@ class JsonIndexDatasetMapProviderV2(DatasetMapProviderBase): # pyre-ignore [13] have its frame number set to `20`, not 5). Each `eval_batches_.json` file contains a list of evaluation examples - in the following form: - ``` + in the following form:: + [ [ # batch 1 (sequence_name: str, frame_number: int, image_path: str), @@ -143,7 +142,7 @@ class JsonIndexDatasetMapProviderV2(DatasetMapProviderBase): # pyre-ignore [13] ... ], ] - ``` + Note that the evaluation examples always come from the `"test"` subset of the dataset. (test frames can repeat across batches). @@ -341,14 +340,13 @@ class JsonIndexDatasetMapProviderV2(DatasetMapProviderBase): # pyre-ignore [13] Returns: category_to_subset_name_list: A dictionary containing subset names available - per category of the following form: - ``` + per category of the following form:: + { category_0: [category_0_subset_name_0, category_0_subset_name_1, ...], category_1: [category_1_subset_name_0, category_1_subset_name_1, ...], ... } - ``` """ category_to_subset_name_list_json = "category_to_subset_name_list.json" diff --git a/pytorch3d/implicitron/evaluation/evaluate_new_view_synthesis.py b/pytorch3d/implicitron/evaluation/evaluate_new_view_synthesis.py index 39b313d9..f73e66f8 100644 --- a/pytorch3d/implicitron/evaluation/evaluate_new_view_synthesis.py +++ b/pytorch3d/implicitron/evaluation/evaluate_new_view_synthesis.py @@ -554,8 +554,8 @@ def _get_flat_nvs_metric_key(result, metric_name) -> str: def flatten_nvs_results(results): """ - Takes input `results` list of dicts of the form: - ``` + Takes input `results` list of dicts of the form:: + [ { 'subset':'train/test/...', @@ -564,12 +564,14 @@ def flatten_nvs_results(results): }, ... ] - ``` - And converts to a flat dict as follows: - { - 'subset=train/test/...|subsubset=src=1/src=2/...': nvs_eval_metrics, - ... - } + + And converts to a flat dict as follows:: + + { + 'subset=train/test/...|subsubset=src=1/src=2/...': nvs_eval_metrics, + ... + } + """ results_flat = {} for result in results: diff --git a/pytorch3d/implicitron/models/renderer/multipass_ea.py b/pytorch3d/implicitron/models/renderer/multipass_ea.py index 648e7f37..b937afc0 100644 --- a/pytorch3d/implicitron/models/renderer/multipass_ea.py +++ b/pytorch3d/implicitron/models/renderer/multipass_ea.py @@ -29,21 +29,21 @@ class MultiPassEmissionAbsorptionRenderer( # pyre-ignore: 13 During each ray marching pass, features, depth map, and masks are integrated: Let o_i be the opacity estimated by the implicit function, and d_i be the offset between points `i` and `i+1` along the respective ray. - Ray marching is performed using the following equations: - ``` - ray_opacity_n = cap_fn(sum_i=1^n cap_fn(d_i * o_i)), - weight_n = weight_fn(cap_fn(d_i * o_i), 1 - ray_opacity_{n-1}), - ``` + Ray marching is performed using the following equations:: + + ray_opacity_n = cap_fn(sum_i=1^n cap_fn(d_i * o_i)), + weight_n = weight_fn(cap_fn(d_i * o_i), 1 - ray_opacity_{n-1}), + and the final rendered quantities are computed by a dot-product of ray values with the weights, e.g. `features = sum_n(weight_n * ray_features_n)`. By default, for the EA raymarcher from [1] ( activated with `self.raymarcher_class_type="EmissionAbsorptionRaymarcher"` - ): - ``` + ):: + cap_fn(x) = 1 - exp(-x), weight_fn(x) = w * x. - ``` + Note that the latter can altered by changing `self.raymarcher_class_type`, e.g. to "CumsumRaymarcher" which implements the cumulative-sum raymarcher from NeuralVolumes [2]. diff --git a/pytorch3d/implicitron/models/view_pooler/feature_aggregator.py b/pytorch3d/implicitron/models/view_pooler/feature_aggregator.py index b51cd0c0..798541ea 100644 --- a/pytorch3d/implicitron/models/view_pooler/feature_aggregator.py +++ b/pytorch3d/implicitron/models/view_pooler/feature_aggregator.py @@ -250,12 +250,11 @@ class AngleWeightedReductionFeatureAggregator(torch.nn.Module, FeatureAggregator Performs a weighted aggregation using a set of predefined `reduction_functions` and concatenates the results of each aggregation function along the channel dimension. The weights are proportional to the cosine of the - angle between the target ray and the source ray: - ``` - weight = ( - dot(target_ray, source_ray) * 0.5 + 0.5 + self.min_ray_angle_weight - )**self.weight_by_ray_angle_gamma - ``` + angle between the target ray and the source ray:: + + weight = ( + dot(target_ray, source_ray) * 0.5 + 0.5 + self.min_ray_angle_weight + )**self.weight_by_ray_angle_gamma The reduction functions singularize the second dimension of the sampled features which stacks the source views. @@ -359,12 +358,11 @@ class AngleWeightedIdentityFeatureAggregator(torch.nn.Module, FeatureAggregatorB """ This aggregator does not perform any feature aggregation. It only weights the features by the weights proportional to the cosine of the - angle between the target ray and the source ray: - ``` - weight = ( - dot(target_ray, source_ray) * 0.5 + 0.5 + self.min_ray_angle_weight - )**self.weight_by_ray_angle_gamma - ``` + angle between the target ray and the source ray:: + + weight = ( + dot(target_ray, source_ray) * 0.5 + 0.5 + self.min_ray_angle_weight + )**self.weight_by_ray_angle_gamma Settings: min_ray_angle_weight: The minimum possible aggregation weight diff --git a/pytorch3d/implicitron/models/view_pooler/view_sampler.py b/pytorch3d/implicitron/models/view_pooler/view_sampler.py index 5cc3156c..66e65e06 100644 --- a/pytorch3d/implicitron/models/view_pooler/view_sampler.py +++ b/pytorch3d/implicitron/models/view_pooler/view_sampler.py @@ -218,8 +218,8 @@ def cameras_points_cartesian_product( ) -> Tuple[CamerasBase, torch.Tensor]: """ Generates all pairs of pairs of elements from 'camera' and 'pts' and returns - `camera_rep` and `pts_rep` such that: - ``` + `camera_rep` and `pts_rep` such that:: + camera_rep = [ pts_rep = [ camera[0] pts[0], camera[0] pts[1], @@ -235,15 +235,14 @@ def cameras_points_cartesian_product( camera[n_cameras-1] ..., ... pts[batch_pts-1], ] ] - ``` Args: camera: A batch of `n_cameras` cameras. pts: A batch of `batch_pts` points of shape `(batch_pts, ..., dim)` Returns: - camera_rep: A batch of batch_pts*n_cameras cameras such that: - ``` + camera_rep: A batch of batch_pts*n_cameras cameras such that:: + camera_rep = [ camera[0] camera[0] @@ -258,11 +257,11 @@ def cameras_points_cartesian_product( camera[n_cameras-1] camera[n_cameras-1] ] - ``` + pts_rep: Repeated `pts` of shape `(batch_pts*n_cameras, ..., dim)`, - such that: - ``` + such that:: + pts_rep = [ pts[0], pts[1], @@ -278,7 +277,7 @@ def cameras_points_cartesian_product( ..., pts[batch_pts-1], ] - ``` + """ n_cameras = camera.R.shape[0] batch_pts = pts.shape[0] diff --git a/pytorch3d/implicitron/tools/stats.py b/pytorch3d/implicitron/tools/stats.py index 49acfeae..a2826a09 100644 --- a/pytorch3d/implicitron/tools/stats.py +++ b/pytorch3d/implicitron/tools/stats.py @@ -73,29 +73,29 @@ class Stats(object): # TODO: update this with context manager """ stats logging object useful for gathering statistics of training a deep net in pytorch - Example: - ``` - # init stats structure that logs statistics 'objective' and 'top1e' - stats = Stats( ('objective','top1e') ) - network = init_net() # init a pytorch module (=nueral network) - dataloader = init_dataloader() # init a dataloader - for epoch in range(10): - # start of epoch -> call new_epoch - stats.new_epoch() + Example:: - # iterate over batches - for batch in dataloader: + # init stats structure that logs statistics 'objective' and 'top1e' + stats = Stats( ('objective','top1e') ) + network = init_net() # init a pytorch module (=nueral network) + dataloader = init_dataloader() # init a dataloader + for epoch in range(10): + # start of epoch -> call new_epoch + stats.new_epoch() - output = network(batch) # run and save into a dict of output variables "output" + # iterate over batches + for batch in dataloader: + + output = network(batch) # run and save into a dict of output variables + + # stats.update() automatically parses the 'objective' and 'top1e' from + # the "output" dict and stores this into the db + stats.update(output) + stats.print() # prints the averages over given epoch + # stores the training plots into '/tmp/epoch_stats.pdf' + # and plots into a visdom server running at localhost (if running) + stats.plot_stats(plot_file='/tmp/epoch_stats.pdf') - # stats.update() automatically parses the 'objective' and 'top1e' from - # the "output" dict and stores this into the db - stats.update(output) - stats.print() # prints the averages over given epoch - # stores the training plots into '/tmp/epoch_stats.pdf' - # and plots into a visdom server running at localhost (if running) - stats.plot_stats(plot_file='/tmp/epoch_stats.pdf') - ``` """ def __init__( diff --git a/pytorch3d/implicitron/tools/utils.py b/pytorch3d/implicitron/tools/utils.py index 430c117c..6cb0d4ec 100644 --- a/pytorch3d/implicitron/tools/utils.py +++ b/pytorch3d/implicitron/tools/utils.py @@ -181,11 +181,11 @@ class Timer: """ A simple class for timing execution. - Example: - ``` + Example:: + with Timer(): print("This print statement is timed.") - ``` + """ def __init__(self, name="timer", quiet=False):