savoji commited on
Commit
7bcf401
·
verified ·
1 Parent(s): f13ecdb

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/.github/CODE_OF_CONDUCT.md +76 -0
  2. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/.github/CONTRIBUTING.md +53 -0
  3. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/.github/ISSUE_TEMPLATE/bugs.md +30 -0
  4. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/.github/ISSUE_TEMPLATE/config.yml +1 -0
  5. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/.github/ISSUE_TEMPLATE/feature_request.md +21 -0
  6. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/.github/ISSUE_TEMPLATE/questions-help.md +21 -0
  7. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/.github/workflows/build.yml +23 -0
  8. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/dev/linter.sh +40 -0
  9. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/dev/run_tutorials.sh +56 -0
  10. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/dev/test_list.py +65 -0
  11. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/feature_extractor/feature_extractor.rst +9 -0
  12. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/feature_extractor/index.rst +7 -0
  13. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/feature_extractor/resnet_feature_extractor.rst +9 -0
  14. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/global_encoder/autodecoder.rst +9 -0
  15. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/global_encoder/index.rst +7 -0
  16. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/implicit_function/base.rst +9 -0
  17. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/implicit_function/decoding_functions.rst +9 -0
  18. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/implicit_function/idr_feature_field.rst +9 -0
  19. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/implicit_function/index.rst +13 -0
  20. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/implicit_function/neural_radiance_field.rst +9 -0
  21. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/implicit_function/scene_representation_networks.rst +9 -0
  22. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/implicit_function/utils.rst +9 -0
  23. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/implicit_function/voxel_grid.rst +9 -0
  24. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/implicit_function/voxel_grid_implicit_function.rst +9 -0
  25. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/renderer/base.rst +9 -0
  26. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/renderer/index.rst +14 -0
  27. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/renderer/lstm_renderer.rst +9 -0
  28. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/renderer/multipass_ea.rst +9 -0
  29. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/renderer/ray_point_refiner.rst +9 -0
  30. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/renderer/ray_sampler.rst +9 -0
  31. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/renderer/ray_tracing.rst +9 -0
  32. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/renderer/raymarcher.rst +9 -0
  33. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/renderer/rgb_net.rst +9 -0
  34. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/renderer/sdf_renderer.rst +9 -0
  35. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/visualization/index.rst +6 -0
  36. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/visualization/render_flyaround.rst +9 -0
  37. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/notes/batching.md +32 -0
  38. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/notes/cameras.md +101 -0
  39. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/notes/cubify.md +12 -0
  40. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/notes/datasets.md +20 -0
  41. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/notes/io.md +34 -0
  42. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/notes/iou3d.md +93 -0
  43. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/notes/meshes_io.md +75 -0
  44. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/notes/renderer.md +76 -0
  45. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/notes/renderer_getting_started.md +147 -0
  46. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/notes/visualization.md +27 -0
  47. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/notes/why_pytorch3d.md +12 -0
  48. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/pytorch3d/ops/marching_cubes.py +305 -0
  49. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/pytorch3d/ops/marching_cubes_data.py +291 -0
  50. project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/tests/implicitron/common_resources.py +161 -0
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/.github/CODE_OF_CONDUCT.md ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to make participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, sex characteristics, gender identity and expression,
9
+ level of experience, education, socio-economic status, nationality, personal
10
+ appearance, race, religion, or sexual identity and orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies within all project spaces, and it also applies when
49
+ an individual is representing the project or its community in public spaces.
50
+ Examples of representing a project or community include using an official
51
+ project e-mail address, posting via an official social media account, or acting
52
+ as an appointed representative at an online or offline event. Representation of
53
+ a project may be further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at <opensource-conduct@fb.com>. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72
+
73
+ [homepage]: https://www.contributor-covenant.org
74
+
75
+ For answers to common questions about this code of conduct, see
76
+ https://www.contributor-covenant.org/faq
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/.github/CONTRIBUTING.md ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Contributing to PyTorch3D
2
+ We want to make contributing to this project as easy and transparent as
3
+ possible.
4
+
5
+ ## Pull Requests
6
+ We actively welcome your pull requests.
7
+
8
+ However, if you're adding any significant features, please make sure to have a corresponding issue to outline your proposal and motivation and allow time for us to give feedback, *before* you send a PR.
9
+ We do not always accept new features, and we take the following factors into consideration:
10
+
11
+ - Whether the same feature can be achieved without modifying PyTorch3D directly. If any aspect of the API is not extensible, please highlight this in an issue so we can work on making this more extensible.
12
+ - Whether the feature is potentially useful to a large audience, or only to a small portion of users.
13
+ - Whether the proposed solution has a good design and interface.
14
+ - Whether the proposed solution adds extra mental/practical overhead to users who don't need such feature.
15
+ - Whether the proposed solution breaks existing APIs.
16
+
17
+ When sending a PR, please ensure you complete the following steps:
18
+
19
+ 1. Fork the repo and create your branch from `main`. Follow the instructions
20
+ in [INSTALL.md](../INSTALL.md) to build the repo.
21
+ 2. If you've added code that should be tested, add tests.
22
+ 3. If you've changed any APIs, please update the documentation.
23
+ 4. Ensure the test suite passes, by running this from the project root:
24
+ ```
25
+ python -m unittest discover -v -s tests -t .
26
+ ```
27
+ 5. Make sure your code lints by running `dev/linter.sh` from the project root.
28
+ 6. If a PR contains multiple orthogonal changes, split it into multiple separate PRs.
29
+ 7. If you haven't already, complete the Contributor License Agreement ("CLA").
30
+
31
+ ## Contributor License Agreement ("CLA")
32
+ In order to accept your pull request, we need you to submit a CLA. You only need
33
+ to do this once to work on any of Facebook's open source projects.
34
+
35
+ Complete your CLA here: <https://code.facebook.com/cla>
36
+
37
+ ## Issues
38
+ We use GitHub issues to track public bugs. Please ensure your description is
39
+ clear and has sufficient instructions to be able to reproduce the issue.
40
+
41
+ Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe
42
+ disclosure of security bugs. In those cases, please go through the process
43
+ outlined on that page and do not file a public issue.
44
+
45
+ ## Coding Style
46
+ We follow these [python](http://google.github.io/styleguide/pyguide.html) and [C++](https://google.github.io/styleguide/cppguide.html) style guides.
47
+
48
+ For the linter to work, you will need to install `black`, `flake`, `usort` and `clang-format`, and
49
+ they need to be fairly up to date.
50
+
51
+ ## License
52
+ By contributing to PyTorch3D, you agree that your contributions will be licensed
53
+ under the LICENSE file in the root directory of this source tree.
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/.github/ISSUE_TEMPLATE/bugs.md ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ name: "🐛 Bugs / Unexpected behaviors"
3
+ about: Please report unexpected behaviors or bugs in PyTorch3D.
4
+
5
+ ---
6
+
7
+ If you do not know the root cause of the problem / bug, and wish someone to help you, please
8
+ post according to this template:
9
+
10
+ ## 🐛 Bugs / Unexpected behaviors
11
+ <!-- A clear and concise description of the issue -->
12
+
13
+ NOTE: Please look at the existing list of Issues tagged with the label ['bug`](https://github.com/facebookresearch/pytorch3d/issues?q=label%3Abug). **Only open a new issue if this bug has not already been reported. If an issue already exists, please comment there instead.**.
14
+
15
+ ## Instructions To Reproduce the Issue:
16
+
17
+ Please include the following (depending on what the issue is):
18
+
19
+ 1. Any changes you made (`git diff`) or code you wrote
20
+ ```
21
+ <put diff or code here>
22
+ ```
23
+ 2. The exact command(s) you ran:
24
+ 3. What you observed (including the full logs):
25
+ ```
26
+ <put logs here>
27
+ ```
28
+
29
+ Please also simplify the steps as much as possible so they do not require additional resources to
30
+ run, such as a private dataset.
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/.github/ISSUE_TEMPLATE/config.yml ADDED
@@ -0,0 +1 @@
 
 
1
+ blank_issues_enabled: false
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/.github/ISSUE_TEMPLATE/feature_request.md ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ name: "\U0001F680 Feature Request"
3
+ about: Submit a proposal/request for a new PyTorch3D feature
4
+
5
+ ---
6
+
7
+ ## 🚀 Feature
8
+ <!-- A clear and concise description of the feature proposal -->
9
+
10
+ NOTE: Please look at the existing list of Issues tagged with the label ['enhancement`](https://github.com/facebookresearch/pytorch3d/issues?q=label%3Aenhancement). **Only open a new issue if you do not see your feature request there**.
11
+
12
+ ## Motivation
13
+
14
+ <!-- Please outline the motivation for the proposal.
15
+ e.g. It would be great if I could do [...], I'm always frustrated when [...]. If this is related to another GitHub issue, please link here too -->
16
+
17
+ ## Pitch
18
+
19
+ <!-- A clear and concise description, optionally with code examples showing the functionality you want. -->
20
+
21
+ NOTE: we only consider adding new features if they are useful for many users.
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/.github/ISSUE_TEMPLATE/questions-help.md ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ name: "❓ Questions"
3
+ about: How do I do X with PyTorch3D? How does PyTorch3D do X?
4
+
5
+ ---
6
+
7
+ ## ❓ Questions on how to use PyTorch3D
8
+
9
+ <!-- A clear and concise description of the question you need help with. -->
10
+
11
+
12
+ NOTE: Please look at the existing list of Issues tagged with the label ['question`](https://github.com/facebookresearch/pytorch3d/issues?q=label%3Aquestion) or ['how-to`](https://github.com/facebookresearch/pytorch3d/issues?q=label%3A%22how+to%22). **Only open a new issue if you cannot find an answer there**.
13
+
14
+ Also note the following:
15
+
16
+ 1. If you encountered any errors or unexpected issues while using PyTorch3D and need help resolving them,
17
+ please use the "Bugs / Unexpected behaviors" issue template.
18
+
19
+ 2. We do not answer general machine learning / computer vision questions that are not specific to
20
+ PyTorch3D, such as how a model works or what algorithm/methods can be
21
+ used to achieve X.
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/.github/workflows/build.yml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: facebookresearch/pytorch3d/build_and_test
2
+ on:
3
+ pull_request:
4
+ branches:
5
+ - main
6
+ push:
7
+ branches:
8
+ - main
9
+ jobs:
10
+ binary_linux_conda_cuda:
11
+ runs-on: 4-core-ubuntu-gpu-t4
12
+ env:
13
+ PYTHON_VERSION: "3.12"
14
+ BUILD_VERSION: "${{ github.run_number }}"
15
+ PYTORCH_VERSION: "2.4.1"
16
+ CU_VERSION: "cu121"
17
+ JUST_TESTRUN: 1
18
+ steps:
19
+ - uses: actions/checkout@v4
20
+ - name: Build and run tests
21
+ run: |-
22
+ conda create --name env --yes --quiet conda-build
23
+ conda run --no-capture-output --name env python3 ./packaging/build_conda.py --use-conda-cuda
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/dev/linter.sh ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash -e
2
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ # All rights reserved.
4
+ #
5
+ # This source code is licensed under the BSD-style license found in the
6
+ # LICENSE file in the root directory of this source tree.
7
+
8
+ # Run this script at project root by "./dev/linter.sh" before you commit
9
+
10
+ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
11
+ DIR=$(dirname "${DIR}")
12
+
13
+ if [[ -f "${DIR}/BUCK" ]]
14
+ then
15
+ pyfmt "${DIR}"
16
+ else
17
+ # run usort externally only
18
+ echo "Running usort..."
19
+ usort "${DIR}"
20
+ fi
21
+
22
+ echo "Running black..."
23
+ black "${DIR}"
24
+
25
+ echo "Running flake..."
26
+ flake8 "${DIR}" || true
27
+
28
+ echo "Running clang-format ..."
29
+ clangformat=$(command -v clang-format-8 || echo clang-format)
30
+ find "${DIR}" -regex ".*\.\(cpp\|c\|cc\|cu\|cuh\|cxx\|h\|hh\|hpp\|hxx\|tcc\|mm\|m\)" -print0 | xargs -0 "${clangformat}" -i
31
+
32
+ # Run arc and pyre internally only.
33
+ if [[ -f "${DIR}/TARGETS" ]]
34
+ then
35
+ (cd "${DIR}"; command -v arc > /dev/null && arc lint) || true
36
+
37
+ echo "Running pyre..."
38
+ echo "To restart/kill pyre server, run 'pyre restart' or 'pyre kill' in fbcode/"
39
+ ( cd ~/fbsource/fbcode; arc pyre check //vision/fair/pytorch3d/... )
40
+ fi
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/dev/run_tutorials.sh ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/bash
2
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ # All rights reserved.
4
+ #
5
+ # This source code is licensed under the BSD-style license found in the
6
+ # LICENSE file in the root directory of this source tree.
7
+
8
+ # This script is for running some of the tutorials using the nightly build in
9
+ # an isolated environment. It is designed to be run in docker.
10
+
11
+ # If you run this script in this directory with
12
+ # sudo docker run --runtime=nvidia -it --rm -v $PWD/../docs/tutorials:/notebooks -v $PWD:/loc pytorch/conda-cuda bash /loc/run_tutorials.sh | tee log.txt
13
+ # it should execute some tutorials with the nightly build and resave them, and
14
+ # save a log in the current directory.
15
+
16
+ # We use nbconvert. runipy would be an alternative but it currently doesn't
17
+ # work well with plotly.
18
+
19
+ set -e
20
+
21
+ conda init bash
22
+ # shellcheck source=/dev/null
23
+ source ~/.bashrc
24
+ conda create -y -n myenv python=3.8 matplotlib ipython ipywidgets nbconvert
25
+ conda activate myenv
26
+ conda install -y -c iopath iopath
27
+ conda install -y -c pytorch pytorch=1.6.0 cudatoolkit=10.1 torchvision
28
+ conda install -y -c pytorch3d-nightly pytorch3d
29
+ pip install plotly scikit-image
30
+
31
+ for notebook in /notebooks/*.ipynb
32
+ do
33
+ name=$(basename "$notebook")
34
+
35
+ if [[ "$name" == "dataloaders_ShapeNetCore_R2N2.ipynb" ]]
36
+ then
37
+ #skip as data not easily available
38
+ continue
39
+ fi
40
+ if [[ "$name" == "render_densepose.ipynb" ]]
41
+ then
42
+ #skip as data not easily available
43
+ continue
44
+ fi
45
+
46
+ #comment the lines which install torch, torchvision and pytorch3d
47
+ sed -Ei '/(torchvision)|(pytorch3d)/ s/!pip/!#pip/' "$notebook"
48
+ #Don't let tqdm use widgets
49
+ sed -i 's/from tqdm.notebook import tqdm/from tqdm import tqdm/' "$notebook"
50
+
51
+ echo
52
+ echo "### ### ###"
53
+ echo "starting $name"
54
+ time jupyter nbconvert --to notebook --inplace --ExecutePreprocessor.kernel_name=python3 --execute "$notebook" || true
55
+ echo "ending $name"
56
+ done
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/dev/test_list.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ # All rights reserved.
3
+ #
4
+ # This source code is licensed under the BSD-style license found in the
5
+ # LICENSE file in the root directory of this source tree.
6
+
7
+ import ast
8
+ from pathlib import Path
9
+ from typing import List
10
+
11
+
12
+ """
13
+ This module outputs a list of tests for completion.
14
+ It has no dependencies.
15
+ """
16
+
17
+
18
+ def get_test_files() -> List[Path]:
19
+ root = Path(__file__).parent.parent
20
+ dirs = ["tests", "projects/implicitron_trainer"]
21
+ return [i for dir in dirs for i in (root / dir).glob("**/test*.py")]
22
+
23
+
24
+ def tests_from_file(path: Path, base: str) -> List[str]:
25
+ """
26
+ Returns all the tests in the given file, in format
27
+ expected as arguments when running the tests.
28
+ e.g.
29
+ file_stem
30
+ file_stem.TestFunctionality
31
+ file_stem.TestFunctionality.test_f
32
+ file_stem.TestFunctionality.test_g
33
+ """
34
+ with open(path) as f:
35
+ node = ast.parse(f.read())
36
+ out = [base]
37
+ for cls in node.body:
38
+ if not isinstance(cls, ast.ClassDef):
39
+ continue
40
+ if not cls.name.startswith("Test"):
41
+ continue
42
+ class_base = base + "." + cls.name
43
+ out.append(class_base)
44
+ for method in cls.body:
45
+ if not isinstance(method, ast.FunctionDef):
46
+ continue
47
+ if not method.name.startswith("test"):
48
+ continue
49
+ out.append(class_base + "." + method.name)
50
+ return out
51
+
52
+
53
+ def main() -> None:
54
+ files = get_test_files()
55
+ test_root = Path(__file__).parent.parent
56
+ all_tests = []
57
+ for f in files:
58
+ file_base = str(f.relative_to(test_root))[:-3].replace("/", ".")
59
+ all_tests.extend(tests_from_file(f, file_base))
60
+ for test in sorted(all_tests):
61
+ print(test)
62
+
63
+
64
+ if __name__ == "__main__":
65
+ main()
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/feature_extractor/feature_extractor.rst ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ pytorch3d.implicitron.models.feature_extractor.feature_extractor
2
+ ================================================================
3
+
4
+ feature_extractor
5
+
6
+ .. automodule:: pytorch3d.implicitron.models.feature_extractor.feature_extractor
7
+ :members:
8
+ :undoc-members:
9
+ :show-inheritance:
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/feature_extractor/index.rst ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ pytorch3d.implicitron.models.feature_extractor
2
+ ==============================================
3
+
4
+ .. toctree::
5
+
6
+ feature_extractor
7
+ resnet_feature_extractor
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/feature_extractor/resnet_feature_extractor.rst ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ pytorch3d.implicitron.models.feature_extractor.resnet_feature_extractor
2
+ =======================================================================
3
+
4
+ resnet_feature_extractor
5
+
6
+ .. automodule:: pytorch3d.implicitron.models.feature_extractor.resnet_feature_extractor
7
+ :members:
8
+ :undoc-members:
9
+ :show-inheritance:
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/global_encoder/autodecoder.rst ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ pytorch3d.implicitron.models.global_encoder.autodecoder
2
+ =======================================================
3
+
4
+ autodecoder
5
+
6
+ .. automodule:: pytorch3d.implicitron.models.global_encoder.autodecoder
7
+ :members:
8
+ :undoc-members:
9
+ :show-inheritance:
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/global_encoder/index.rst ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ pytorch3d.implicitron.models.global_encoder
2
+ ===========================================
3
+
4
+ .. toctree::
5
+
6
+ autodecoder
7
+ global_encoder
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/implicit_function/base.rst ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ pytorch3d.implicitron.models.implicit_function.base
2
+ ===================================================
3
+
4
+ base
5
+
6
+ .. automodule:: pytorch3d.implicitron.models.implicit_function.base
7
+ :members:
8
+ :undoc-members:
9
+ :show-inheritance:
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/implicit_function/decoding_functions.rst ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ pytorch3d.implicitron.models.implicit_function.decoding_functions
2
+ =================================================================
3
+
4
+ decoding_functions
5
+
6
+ .. automodule:: pytorch3d.implicitron.models.implicit_function.decoding_functions
7
+ :members:
8
+ :undoc-members:
9
+ :show-inheritance:
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/implicit_function/idr_feature_field.rst ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ pytorch3d.implicitron.models.implicit_function.idr_feature_field
2
+ ================================================================
3
+
4
+ idr_feature_field
5
+
6
+ .. automodule:: pytorch3d.implicitron.models.implicit_function.idr_feature_field
7
+ :members:
8
+ :undoc-members:
9
+ :show-inheritance:
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/implicit_function/index.rst ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pytorch3d.implicitron.models.implicit_function
2
+ ==============================================
3
+
4
+ .. toctree::
5
+
6
+ base
7
+ decoding_functions
8
+ idr_feature_field
9
+ neural_radiance_field
10
+ scene_representation_networks
11
+ utils
12
+ voxel_grid
13
+ voxel_grid_implicit_function
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/implicit_function/neural_radiance_field.rst ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ pytorch3d.implicitron.models.implicit_function.neural_radiance_field
2
+ ====================================================================
3
+
4
+ neural_radiance_field
5
+
6
+ .. automodule:: pytorch3d.implicitron.models.implicit_function.neural_radiance_field
7
+ :members:
8
+ :undoc-members:
9
+ :show-inheritance:
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/implicit_function/scene_representation_networks.rst ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ pytorch3d.implicitron.models.implicit_function.scene_representation_networks
2
+ ============================================================================
3
+
4
+ scene_representation_networks
5
+
6
+ .. automodule:: pytorch3d.implicitron.models.implicit_function.scene_representation_networks
7
+ :members:
8
+ :undoc-members:
9
+ :show-inheritance:
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/implicit_function/utils.rst ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ pytorch3d.implicitron.models.implicit_function.utils
2
+ ====================================================
3
+
4
+ utils
5
+
6
+ .. automodule:: pytorch3d.implicitron.models.implicit_function.utils
7
+ :members:
8
+ :undoc-members:
9
+ :show-inheritance:
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/implicit_function/voxel_grid.rst ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ pytorch3d.implicitron.models.implicit_function.voxel_grid
2
+ =========================================================
3
+
4
+ voxel_grid
5
+
6
+ .. automodule:: pytorch3d.implicitron.models.implicit_function.voxel_grid
7
+ :members:
8
+ :undoc-members:
9
+ :show-inheritance:
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/implicit_function/voxel_grid_implicit_function.rst ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ pytorch3d.implicitron.models.implicit_function.voxel_grid_implicit_function
2
+ ===========================================================================
3
+
4
+ voxel_grid_implicit_function
5
+
6
+ .. automodule:: pytorch3d.implicitron.models.implicit_function.voxel_grid_implicit_function
7
+ :members:
8
+ :undoc-members:
9
+ :show-inheritance:
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/renderer/base.rst ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ pytorch3d.implicitron.models.renderer.base
2
+ ==========================================
3
+
4
+ base
5
+
6
+ .. automodule:: pytorch3d.implicitron.models.renderer.base
7
+ :members:
8
+ :undoc-members:
9
+ :show-inheritance:
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/renderer/index.rst ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pytorch3d.implicitron.models.renderer
2
+ =====================================
3
+
4
+ .. toctree::
5
+
6
+ base
7
+ lstm_renderer
8
+ multipass_ea
9
+ ray_point_refiner
10
+ ray_sampler
11
+ ray_tracing
12
+ raymarcher
13
+ rgb_net
14
+ sdf_renderer
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/renderer/lstm_renderer.rst ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ pytorch3d.implicitron.models.renderer.lstm_renderer
2
+ ===================================================
3
+
4
+ lstm_renderer
5
+
6
+ .. automodule:: pytorch3d.implicitron.models.renderer.lstm_renderer
7
+ :members:
8
+ :undoc-members:
9
+ :show-inheritance:
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/renderer/multipass_ea.rst ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ pytorch3d.implicitron.models.renderer.multipass_ea
2
+ ==================================================
3
+
4
+ multipass_ea
5
+
6
+ .. automodule:: pytorch3d.implicitron.models.renderer.multipass_ea
7
+ :members:
8
+ :undoc-members:
9
+ :show-inheritance:
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/renderer/ray_point_refiner.rst ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ pytorch3d.implicitron.models.renderer.ray_point_refiner
2
+ =======================================================
3
+
4
+ ray_point_refiner
5
+
6
+ .. automodule:: pytorch3d.implicitron.models.renderer.ray_point_refiner
7
+ :members:
8
+ :undoc-members:
9
+ :show-inheritance:
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/renderer/ray_sampler.rst ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ pytorch3d.implicitron.models.renderer.ray_sampler
2
+ =================================================
3
+
4
+ ray_sampler
5
+
6
+ .. automodule:: pytorch3d.implicitron.models.renderer.ray_sampler
7
+ :members:
8
+ :undoc-members:
9
+ :show-inheritance:
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/renderer/ray_tracing.rst ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ pytorch3d.implicitron.models.renderer.ray_tracing
2
+ =================================================
3
+
4
+ ray_tracing
5
+
6
+ .. automodule:: pytorch3d.implicitron.models.renderer.ray_tracing
7
+ :members:
8
+ :undoc-members:
9
+ :show-inheritance:
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/renderer/raymarcher.rst ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ pytorch3d.implicitron.models.renderer.raymarcher
2
+ ================================================
3
+
4
+ raymarcher
5
+
6
+ .. automodule:: pytorch3d.implicitron.models.renderer.raymarcher
7
+ :members:
8
+ :undoc-members:
9
+ :show-inheritance:
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/renderer/rgb_net.rst ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ pytorch3d.implicitron.models.renderer.rgb_net
2
+ =============================================
3
+
4
+ rgb_net
5
+
6
+ .. automodule:: pytorch3d.implicitron.models.renderer.rgb_net
7
+ :members:
8
+ :undoc-members:
9
+ :show-inheritance:
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/renderer/sdf_renderer.rst ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ pytorch3d.implicitron.models.renderer.sdf_renderer
2
+ ==================================================
3
+
4
+ sdf_renderer
5
+
6
+ .. automodule:: pytorch3d.implicitron.models.renderer.sdf_renderer
7
+ :members:
8
+ :undoc-members:
9
+ :show-inheritance:
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/visualization/index.rst ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ pytorch3d.implicitron.models.visualization
2
+ ==========================================
3
+
4
+ .. toctree::
5
+
6
+ render_flyaround
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/modules/implicitron/models/visualization/render_flyaround.rst ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ pytorch3d.implicitron.models.visualization.render_flyaround
2
+ ===========================================================
3
+
4
+ render_flyaround
5
+
6
+ .. automodule:: pytorch3d.implicitron.models.visualization.render_flyaround
7
+ :members:
8
+ :undoc-members:
9
+ :show-inheritance:
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/notes/batching.md ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ hide_title: true
3
+ sidebar_label: Batching
4
+ ---
5
+
6
+ # Batching
7
+
8
+ In deep learning, every optimization step operates on multiple input examples for robust training. Thus, efficient batching is crucial. For image inputs, batching is straightforward; N images are resized to the same height and width and stacked as a 4 dimensional tensor of shape `N x 3 x H x W`. For meshes, batching is less straightforward.
9
+
10
+ <img src="assets/batch_intro.png" alt="batch_intro" align="middle"/>
11
+
12
+ ## Batch modes for meshes
13
+
14
+ Assume you want to construct a batch containing two meshes, with `mesh1 = (v1: V1 x 3, f1: F1 x 3)` containing `V1` vertices and `F1` faces, and `mesh2 = (v2: V2 x 3, f2: F2 x 3)` with `V2 (!= V1)` vertices and `F2 (!= F1)` faces. The [Meshes][meshes] data structure provides three different ways to batch *heterogeneous* meshes. If `meshes = Meshes(verts = [v1, v2], faces = [f1, f2])` is an instantiation of the data structure, then
15
+
16
+ * List: Returns the examples in the batch as a list of tensors. Specifically, `meshes.verts_list()` returns the list of vertices `[v1, v2]`. Similarly, `meshes.faces_list()` returns the list of faces `[f1, f2]`.
17
+ * Padded: The padded representation constructs a tensor by padding the extra values. Specifically, `meshes.verts_padded()` returns a tensor of shape `2 x max(V1, V2) x 3` and pads the extra vertices with `0`s. Similarly, `meshes.faces_padded()` returns a tensor of shape `2 x max(F1, F2) x 3` and pads the extra faces with `-1`s.
18
+ * Packed: The packed representation concatenates the examples in the batch into a tensor. In particular, `meshes.verts_packed()` returns a tensor of shape `(V1 + V2) x 3`. Similarly, `meshes.faces_packed()` returns a tensor of shape `(F1 + F2) x 3` for the faces. In the packed mode, auxiliary variables are computed that enable efficient conversion between packed and padded or list modes.
19
+
20
+ <img src="assets/batch_modes.gif" alt="batch_modes" height="450" align="middle" />
21
+
22
+ ## Use cases for batch modes
23
+
24
+ The need for different mesh batch modes is inherent to the way PyTorch operators are implemented. To fully utilize the optimized PyTorch ops, the [Meshes][meshes] data structure allows for efficient conversion between the different batch modes. This is crucial when aiming for a fast and efficient training cycle. An example of this is [Mesh R-CNN][meshrcnn]. Here, in the same forward pass different parts of the network assume different inputs, which are computed by converting between the different batch modes. In particular, [vert_align][vert_align] assumes a *padded* input tensor while immediately after [graph_conv][graphconv] assumes a *packed* input tensor.
25
+
26
+ <img src="assets/meshrcnn.png" alt="meshrcnn" width="700" align="middle" />
27
+
28
+
29
+ [meshes]: https://github.com/facebookresearch/pytorch3d/blob/main/pytorch3d/structures/meshes.py
30
+ [graphconv]: https://github.com/facebookresearch/pytorch3d/blob/main/pytorch3d/ops/graph_conv.py
31
+ [vert_align]: https://github.com/facebookresearch/pytorch3d/blob/main/pytorch3d/ops/vert_align.py
32
+ [meshrcnn]: https://github.com/facebookresearch/meshrcnn
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/notes/cameras.md ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ hide_title: true
3
+ sidebar_label: Cameras
4
+ ---
5
+
6
+ # Cameras
7
+
8
+ ## Camera Coordinate Systems
9
+
10
+ When working with 3D data, there are 4 coordinate systems users need to know
11
+ * **World coordinate system**
12
+ This is the system the object/scene lives - the world.
13
+ * **Camera view coordinate system**
14
+ This is the system that has its origin on the image plane and the `Z`-axis perpendicular to the image plane. In PyTorch3D, we assume that `+X` points left, and `+Y` points up and `+Z` points out from the image plane. The transformation from world to view happens after applying a rotation (`R`) and translation (`T`).
15
+ * **NDC coordinate system**
16
+ This is the normalized coordinate system that confines in a volume the rendered part of the object/scene. Also known as view volume. For square images, under the PyTorch3D convention, `(+1, +1, znear)` is the top left near corner, and `(-1, -1, zfar)` is the bottom right far corner of the volume. For non-square images, the side of the volume in `XY` with the smallest length ranges from `[-1, 1]` while the larger side from `[-s, s]`, where `s` is the aspect ratio and `s > 1` (larger divided by smaller side).
17
+ The transformation from view to NDC happens after applying the camera projection matrix (`P`).
18
+ * **Screen coordinate system**
19
+ This is another representation of the view volume with the `XY` coordinates defined in pixel space instead of a normalized space. (0,0) is the top left corner of the top left pixel
20
+ and (W,H) is the bottom right corner of the bottom right pixel.
21
+
22
+ An illustration of the 4 coordinate systems is shown below
23
+ ![cameras](https://user-images.githubusercontent.com/669761/145090051-67b506d7-6d73-4826-a677-5873b7cb92ba.png)
24
+
25
+ ## Defining Cameras in PyTorch3D
26
+
27
+ Cameras in PyTorch3D transform an object/scene from world to view by first transforming the object/scene to view (via transforms `R` and `T`) and then projecting the 3D object/scene to a normalized space via the projection matrix `P = K[R | T]`, where `K` is the intrinsic matrix. The camera parameters in `K` define the normalized space. If users define the camera parameters in NDC space, then the transform projects points to NDC. If the camera parameters are defined in screen space, the transformed points are in screen space.
28
+
29
+ Note that the base `CamerasBase` class makes no assumptions about the coordinate systems. All the above transforms are geometric transforms defined purely by `R`, `T` and `K`. This means that users can define cameras in any coordinate system and for any transforms. The method `transform_points` will apply `K` , `R` and `T` to the input points as a simple matrix transformation. However, if users wish to use cameras with the PyTorch3D renderer, they need to abide to PyTorch3D's coordinate system assumptions (read below).
30
+
31
+ We provide instantiations of common camera types in PyTorch3D and how users can flexibly define the projection space below.
32
+
33
+ ## Interfacing with the PyTorch3D Renderer
34
+
35
+ The PyTorch3D renderer for both meshes and point clouds assumes that the camera transformed points, meaning the points passed as input to the rasterizer, are in PyTorch3D's NDC space. So to get the expected rendering outcome, users need to make sure that their 3D input data and cameras abide by these PyTorch3D coordinate system assumptions. The PyTorch3D coordinate system assumes `+X:left`, `+Y: up` and `+Z: from us to scene` (right-handed) . Confusions regarding coordinate systems are common so we advise that you spend some time understanding your data and the coordinate system they live in and transform them accordingly before using the PyTorch3D renderer.
36
+
37
+ Examples of cameras and how they interface with the PyTorch3D renderer can be found in our tutorials.
38
+
39
+ ### Camera Types
40
+
41
+ All cameras inherit from `CamerasBase` which is a base class for all cameras. PyTorch3D provides four different camera types. The `CamerasBase` defines methods that are common to all camera models:
42
+ * `get_camera_center` that returns the optical center of the camera in world coordinates
43
+ * `get_world_to_view_transform` which returns a 3D transform from world coordinates to the camera view coordinates `(R, T)`
44
+ * `get_full_projection_transform` which composes the projection transform (`K`) with the world-to-view transform `(R, T)`
45
+ * `transform_points` which takes a set of input points in world coordinates and projects to NDC coordinates ranging from [-1, -1, znear] to [+1, +1, zfar].
46
+ * `get_ndc_camera_transform` which defines the conversion to PyTorch3D's NDC space and is called when interfacing with the PyTorch3D renderer. If the camera is defined in NDC space, then the identity transform is returned. If the cameras is defined in screen space, the conversion from screen to NDC is returned. If users define their own camera in screen space, they need to think of the screen to NDC conversion. We provide examples for the `PerspectiveCameras` and `OrthographicCameras`.
47
+ * `transform_points_ndc` which takes a set of points in world coordinates and projects them to PyTorch3D's NDC space
48
+ * `transform_points_screen` which takes a set of input points in world coordinates and projects them to the screen coordinates ranging from [0, 0, znear] to [W, H, zfar]
49
+
50
+ Users can easily customize their own cameras. For each new camera, users should implement the `get_projection_transform` routine that returns the mapping `P` from camera view coordinates to NDC coordinates.
51
+
52
+ #### FoVPerspectiveCameras, FoVOrthographicCameras
53
+ These two cameras follow the OpenGL convention for perspective and orthographic cameras respectively. The user provides the near `znear` and far `zfar` field which confines the view volume in the `Z` axis. The view volume in the `XY` plane is defined by field of view angle (`fov`) in the case of `FoVPerspectiveCameras` and by `min_x, min_y, max_x, max_y` in the case of `FoVOrthographicCameras`.
54
+ These cameras are by default in NDC space.
55
+
56
+ #### PerspectiveCameras, OrthographicCameras
57
+ These two cameras follow the Multi-View Geometry convention for cameras. The user provides the focal length (`fx`, `fy`) and the principal point (`px`, `py`). For example, `camera = PerspectiveCameras(focal_length=((fx, fy),), principal_point=((px, py),))`
58
+
59
+ The camera projection of a 3D point `(X, Y, Z)` in view coordinates to a point `(x, y, z)` in projection space (either NDC or screen) is
60
+
61
+ ```
62
+ # for perspective camera
63
+ x = fx * X / Z + px
64
+ y = fy * Y / Z + py
65
+ z = 1 / Z
66
+
67
+ # for orthographic camera
68
+ x = fx * X + px
69
+ y = fy * Y + py
70
+ z = Z
71
+ ```
72
+
73
+ The user can define the camera parameters in NDC or in screen space. Screen space camera parameters are common and for that case the user needs to set `in_ndc` to `False` and also provide the `image_size=(height, width)` of the screen, aka the image.
74
+
75
+ The `get_ndc_camera_transform` provides the transform from screen to NDC space in PyTorch3D. Note that the screen space assumes that the principal point is provided in the space with `+X left`, `+Y down` and origin at the top left corner of the image. To convert to NDC we need to account for the scaling of the normalized space as well as the change in `XY` direction.
76
+
77
+ Below are example of equivalent `PerspectiveCameras` instantiations in NDC and screen space, respectively.
78
+
79
+ ```python
80
+ # NDC space camera
81
+ fcl_ndc = (1.2,)
82
+ prp_ndc = ((0.2, 0.5),)
83
+ cameras_ndc = PerspectiveCameras(focal_length=fcl_ndc, principal_point=prp_ndc)
84
+
85
+ # Screen space camera
86
+ image_size = ((128, 256),) # (h, w)
87
+ fcl_screen = (76.8,) # fcl_ndc * min(image_size) / 2
88
+ prp_screen = ((115.2, 32), ) # w / 2 - px_ndc * min(image_size) / 2, h / 2 - py_ndc * min(image_size) / 2
89
+ cameras_screen = PerspectiveCameras(focal_length=fcl_screen, principal_point=prp_screen, in_ndc=False, image_size=image_size)
90
+ ```
91
+
92
+ The relationship between screen and NDC specifications of a camera's `focal_length` and `principal_point` is given by the following equations, where `s = min(image_width, image_height)`.
93
+ The transformation of x and y coordinates between screen and NDC is exactly the same as for px and py.
94
+
95
+ ```
96
+ fx_ndc = fx_screen * 2.0 / s
97
+ fy_ndc = fy_screen * 2.0 / s
98
+
99
+ px_ndc = - (px_screen - image_width / 2.0) * 2.0 / s
100
+ py_ndc = - (py_screen - image_height / 2.0) * 2.0 / s
101
+ ```
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/notes/cubify.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ hide_title: true
3
+ sidebar_label: Cubify
4
+ ---
5
+
6
+ # Cubify
7
+
8
+ The [cubify operator](https://github.com/facebookresearch/pytorch3d/blob/main/pytorch3d/ops/cubify.py) converts an 3D occupancy grid of shape `BxDxHxW`, where `B` is the batch size, into a mesh instantiated as a [Meshes](https://github.com/facebookresearch/pytorch3d/blob/main/pytorch3d/structures/meshes.py) data structure of `B` elements. The operator replaces every occupied voxel (if its occupancy probability is greater than a user defined threshold) with a cuboid of 12 faces and 8 vertices. Shared vertices are merged, and internal faces are removed resulting in a **watertight** mesh.
9
+
10
+ The operator provides three alignment modes {*topleft*, *corner*, *center*} which define the span of the mesh vertices with respect to the voxel grid. The alignment modes are described in the figure below for a 2D grid.
11
+
12
+ ![input](https://user-images.githubusercontent.com/4369065/81032959-af697380-8e46-11ea-91a8-fae89597f988.png)
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/notes/datasets.md ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ hide_title: true
3
+ sidebar_label: Data loaders
4
+ ---
5
+
6
+ # Data loaders for common 3D Datasets
7
+
8
+ ### ShapetNetCore
9
+
10
+ ShapeNet is a dataset of 3D CAD models. ShapeNetCore is a subset of the ShapeNet dataset and can be downloaded from https://www.shapenet.org/. There are two versions ShapeNetCore: v1 (55 categories) and v2 (57 categories).
11
+
12
+ The PyTorch3D [ShapeNetCore data loader](https://github.com/facebookresearch/pytorch3d/blob/main/pytorch3d/datasets/shapenet/shapenet_core.py) inherits from `torch.utils.data.Dataset`. It takes the path where the ShapeNetCore dataset is stored locally and loads models in the dataset. The ShapeNetCore class loads and returns models with their `categories`, `model_ids`, `vertices` and `faces`. The `ShapeNetCore` data loader also has a customized `render` function that renders models by the specified `model_ids (List[int])`, `categories (List[str])` or `indices (List[int])` with PyTorch3D's differentiable renderer.
13
+
14
+ The loaded dataset can be passed to `torch.utils.data.DataLoader` with PyTorch3D's customized collate_fn: `collate_batched_meshes` from the `pytorch3d.dataset.utils` module. The `vertices` and `faces` of the models are used to construct a [Meshes](https://github.com/facebookresearch/pytorch3d/blob/main/pytorch3d/structures/meshes.py) object representing the batched meshes. This `Meshes` representation can be easily used with other ops and rendering in PyTorch3D.
15
+
16
+ ### R2N2
17
+
18
+ The R2N2 dataset contains 13 categories that are a subset of the ShapeNetCore v.1 dataset. The R2N2 dataset also contains its own 24 renderings of each object and voxelized models. The R2N2 Dataset can be downloaded following the instructions [here](http://3d-r2n2.stanford.edu/).
19
+
20
+ The PyTorch3D [R2N2 data loader](https://github.com/facebookresearch/pytorch3d/blob/main/pytorch3d/datasets/r2n2/r2n2.py) is initialized with the paths to the ShapeNet dataset, the R2N2 dataset and the splits file for R2N2. Just like `ShapeNetCore`, it can be passed to `torch.utils.data.DataLoader` with a customized collate_fn: `collate_batched_R2N2` from the `pytorch3d.dataset.r2n2.utils` module. It returns all the data that `ShapeNetCore` returns, and in addition, it returns the R2N2 renderings (24 views for each model) along with the camera calibration matrices and a voxel representation for each model. Similar to `ShapeNetCore`, it has a customized `render` function that supports rendering specified models with the PyTorch3D differentiable renderer. In addition, it supports rendering models with the same orientations as R2N2's original renderings.
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/notes/io.md ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ hide_title: true
3
+ sidebar_label: File IO
4
+ ---
5
+
6
+ # File IO
7
+ There is a flexible interface for loading and saving point clouds and meshes from different formats.
8
+
9
+ The main usage is via the `pytorch3d.io.IO` object, and its methods
10
+ `load_mesh`, `save_mesh`, `load_pointcloud` and `save_pointcloud`.
11
+
12
+ For example, to load a mesh you might do
13
+ ```
14
+ from pytorch3d.io import IO
15
+
16
+ device=torch.device("cuda:0")
17
+ mesh = IO().load_mesh("mymesh.obj", device=device)
18
+ ```
19
+
20
+ and to save a pointcloud you might do
21
+ ```
22
+ pcl = Pointclouds(...)
23
+ IO().save_pointcloud(pcl, "output_pointcloud.ply")
24
+ ```
25
+
26
+ For meshes, this supports OBJ, PLY and OFF files.
27
+
28
+ For pointclouds, this supports PLY files.
29
+
30
+ In addition, there is experimental support for loading meshes from
31
+ [glTF 2 assets](https://github.com/KhronosGroup/glTF/tree/master/specification/2.0)
32
+ stored either in a GLB container file or a glTF JSON file with embedded binary data.
33
+ This must be enabled explicitly, as described in
34
+ `pytorch3d/io/experimental_gltf_io.py`.
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/notes/iou3d.md ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ hide_title: true
3
+ sidebar_label: IoU3D
4
+ ---
5
+
6
+ # Intersection Over Union of Oriented 3D Boxes: A New Algorithm
7
+
8
+ Author: Georgia Gkioxari
9
+
10
+ Implementation: Georgia Gkioxari and Nikhila Ravi
11
+
12
+ ## Description
13
+
14
+ Intersection over union (IoU) of boxes is widely used as an evaluation metric in object detection ([1][pascalvoc], [2][coco]).
15
+ In 2D, IoU is commonly applied to axis-aligned boxes, namely boxes with edges parallel to the image axis.
16
+ In 3D, boxes are usually not axis aligned and can be oriented in any way in the world.
17
+ We introduce a new algorithm which computes the *exact* IoU of two *oriented 3D boxes*.
18
+
19
+ Our algorithm is based on the simple observation that the intersection of two oriented 3D boxes, `box1` and `box2`, is a convex polyhedron (convex n-gon in 2D) with `n > 2` comprised of connected *planar units*.
20
+ In 3D, these planar units are 3D triangular faces.
21
+ In 2D, they are 2D edges.
22
+ Each planar unit belongs strictly to either `box1` or `box2`.
23
+ Our algorithm finds these units by iterating through the sides of each box.
24
+
25
+ 1. For each 3D triangular face `e` in `box1` we check wether `e` is *inside* `box2`.
26
+ 2. If `e` is not *inside*, then we discard it.
27
+ 3. If `e` is *inside* or *partially inside*, then the part of `e` *inside* `box2` is added to the units that comprise the final intersection shape.
28
+ 4. We repeat for `box2`.
29
+
30
+ Below, we show a visualization of our algorithm for the case of 2D oriented boxes.
31
+
32
+ <p align="center">
33
+ <img src="assets/iou3d.gif" alt="drawing" width="400"/>
34
+ </p>
35
+
36
+ Note that when a box's unit `e` is *partially inside* a `box` then `e` breaks into smaller units. In 2D, `e` is an edge and breaks into smaller edges. In 3D, `e` is a 3D triangular face and is clipped to more and smaller faces by the plane of the `box` it intersects with.
37
+ This is the sole fundamental difference between the algorithms for 2D and 3D.
38
+
39
+ ## Comparison With Other Algorithms
40
+
41
+ Current algorithms for 3D box IoU rely on crude approximations or make box assumptions, for example they restrict the orientation of the 3D boxes.
42
+ [Objectron][objectron] provides a nice discussion on the limitations of prior works.
43
+ [Objectron][objectron] introduces a great algorithm for exact IoU computation of oriented 3D boxes.
44
+ Objectron's algorithm computes the intersection points of two boxes using the [Sutherland-Hodgman algorithm][clipalgo].
45
+ The intersection shape is formed by the convex hull from the intersection points, using the [Qhull library][qhull].
46
+
47
+ Our algorithm has several advantages over Objectron's:
48
+
49
+ * Our algorithm also computes the points of intersection, similar to Objectron, but in addition stores the *planar units* the points belong to. This eliminates the need for convex hull computation which is `O(nlogn)` and relies on a third party library which often crashes with nondescript error messages.
50
+ * Objectron's implementation assumes that boxes are a rotation away from axis aligned. Our algorithm and implementation make no such assumption and work for any 3D boxes.
51
+ * Our implementation supports batching, unlike Objectron which assumes single element inputs for `box1` and `box2`.
52
+ * Our implementation is easily parallelizable and in fact we provide a custom C++/CUDA implementation which is **450 times faster than Objectron**.
53
+
54
+ Below we compare the performance for Objectron (in C++) and our algorithm, in C++ and CUDA. We benchmark for a common use case in object detection where `boxes1` hold M predictions and `boxes2` hold N ground truth 3D boxes in an image and compute the `MxN` IoU matrix. We report the time in ms for `M=N=16`.
55
+
56
+ <p align="center">
57
+ <img src="assets/iou3d_comp.png" alt="drawing" width="400"/>
58
+ </p>
59
+
60
+ ## Usage and Code
61
+
62
+ ```python
63
+ from pytorch3d.ops import box3d_overlap
64
+ # Assume inputs: boxes1 (M, 8, 3) and boxes2 (N, 8, 3)
65
+ intersection_vol, iou_3d = box3d_overlap(boxes1, boxes2)
66
+ ```
67
+
68
+ For more details, read [iou_box3d.py](https://github.com/facebookresearch/pytorch3d/blob/main/pytorch3d/ops/iou_box3d.py).
69
+
70
+ Note that our implementation is not differentiable as of now. We plan to add gradient support soon.
71
+
72
+ We also include have extensive [tests](https://github.com/facebookresearch/pytorch3d/blob/main/tests/test_iou_box3d.py) comparing our implementation with Objectron and MeshLab.
73
+
74
+
75
+ ## Cite
76
+
77
+ If you use our 3D IoU algorithm, please cite PyTorch3D
78
+
79
+ ```bibtex
80
+ @article{ravi2020pytorch3d,
81
+ author = {Nikhila Ravi and Jeremy Reizenstein and David Novotny and Taylor Gordon
82
+ and Wan-Yen Lo and Justin Johnson and Georgia Gkioxari},
83
+ title = {Accelerating 3D Deep Learning with PyTorch3D},
84
+ journal = {arXiv:2007.08501},
85
+ year = {2020},
86
+ }
87
+ ```
88
+
89
+ [pascalvoc]: http://host.robots.ox.ac.uk/pascal/VOC/
90
+ [coco]: https://cocodataset.org/
91
+ [objectron]: https://arxiv.org/abs/2012.09988
92
+ [qhull]: http://www.qhull.org/
93
+ [clipalgo]: https://en.wikipedia.org/wiki/Sutherland%E2%80%93Hodgman_algorithm
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/notes/meshes_io.md ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ sidebar_label: Loading from file
3
+ hide_title: true
4
+ ---
5
+
6
+ # Meshes and IO
7
+
8
+ The Meshes object represents a batch of triangulated meshes, and is central to
9
+ much of the functionality of PyTorch3D. There is no insistence that each mesh in
10
+ the batch has the same number of vertices or faces. When available, it can store
11
+ other data which pertains to the mesh, for example face normals, face areas
12
+ and textures.
13
+
14
+ Two common file formats for storing single meshes are ".obj" and ".ply" files,
15
+ and PyTorch3D has functions for reading these.
16
+
17
+ ## OBJ
18
+
19
+ Obj files have a standard way to store extra information about a mesh. Given an
20
+ obj file, it can be read with
21
+
22
+ ```
23
+ verts, faces, aux = load_obj(filename)
24
+ ```
25
+
26
+ which sets `verts` to be a (V,3)-tensor of vertices and `faces.verts_idx` to be
27
+ an (F,3)- tensor of the vertex-indices of each of the corners of the faces.
28
+ Faces which are not triangles will be split into triangles. `aux` is an object
29
+ which may contain normals, uv coordinates, material colors and textures if they
30
+ are present, and `faces` may additionally contain indices into these normals,
31
+ textures and materials in its NamedTuple structure. A Meshes object containing a
32
+ single mesh can be created from just the vertices and faces using
33
+ ```
34
+ meshes = Meshes(verts=[verts], faces=[faces.verts_idx])
35
+ ```
36
+
37
+ If there is texture information in the `.obj` it can be used to initialize a
38
+ `Textures` class which is passed into the `Meshes` constructor. Currently we
39
+ support loading of texture maps for meshes which have one texture map for the
40
+ entire mesh e.g.
41
+
42
+ ```
43
+ verts_uvs = aux.verts_uvs[None, ...] # (1, V, 2)
44
+ faces_uvs = faces.textures_idx[None, ...] # (1, F, 3)
45
+ tex_maps = aux.texture_images
46
+
47
+ # tex_maps is a dictionary of {material name: texture image}.
48
+ # Take the first image:
49
+ texture_image = list(tex_maps.values())[0]
50
+ texture_image = texture_image[None, ...] # (1, H, W, 3)
51
+
52
+ # Create a textures object
53
+ tex = Textures(verts_uvs=verts_uvs, faces_uvs=faces_uvs, maps=texture_image)
54
+
55
+ # Initialise the mesh with textures
56
+ meshes = Meshes(verts=[verts], faces=[faces.verts_idx], textures=tex)
57
+ ```
58
+
59
+ The `load_objs_as_meshes` function provides this procedure.
60
+
61
+ ## PLY
62
+
63
+ Ply files are flexible in the way they store additional information. PyTorch3D
64
+ provides a function just to read the vertices and faces from a ply file.
65
+ The call
66
+ ```
67
+ verts, faces = load_ply(filename)
68
+ ```
69
+ sets `verts` to be a (V,3)-tensor of vertices and `faces` to be an (F,3)-
70
+ tensor of the vertex-indices of each of the corners of the faces. Faces which
71
+ are not triangles will be split into triangles. A Meshes object containing a
72
+ single mesh can be created from this data using
73
+ ```
74
+ meshes = Meshes(verts=[verts], faces=[faces])
75
+ ```
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/notes/renderer.md ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ hide_title: true
3
+ sidebar_label: Overview
4
+ ---
5
+
6
+ # Rendering Overview
7
+
8
+ Differentiable rendering is a relatively new and exciting research area in computer vision, bridging the gap between 2D and 3D by allowing 2D image pixels to be related back to 3D properties of a scene.
9
+
10
+ For example, by rendering an image from a 3D shape predicted by a neural network, it is possible to compute a 2D loss with a reference image. Inverting the rendering step means we can relate the 2D loss from the pixels back to the 3D properties of the shape such as the positions of mesh vertices, enabling 3D shapes to be learnt without any explicit 3D supervision.
11
+
12
+ We extensively researched existing codebases for differentiable rendering and found that:
13
+ - the rendering pipeline is complex with more than 7 separate components which need to interoperate and be differentiable
14
+ - popular existing approaches [[1](#1), [2](#2)] are based on the same core implementation which bundles many of the key components into large CUDA kernels which require significant expertise to understand, and has limited scope for extensions
15
+ - existing methods either do not support batching or assume that meshes in a batch have the same number of vertices and faces
16
+ - existing projects only provide CUDA implementations so they cannot be used without GPUs
17
+
18
+ In order to experiment with different approaches, we wanted a modular implementation that is easy to use and extend, and supports [heterogeneous batching](batching.md). Taking inspiration from existing work [[1](#1), [2](#2)], we have created a new, modular, differentiable renderer with **parallel implementations in PyTorch, C++ and CUDA**, as well as comprehensive documentation and tests, with the aim of helping to further research in this field.
19
+
20
+ Our implementation decouples the rasterization and shading steps of rendering. The core rasterization step (based on [[2]](#2)) returns several intermediate variables and has an optimized implementation in CUDA. The rest of the pipeline is implemented purely in PyTorch, and is designed to be customized and extended. With this approach, the PyTorch3D differentiable renderer can be imported as a library.
21
+
22
+ ## <u>Get started</u>
23
+
24
+ To learn about more the implementation and start using the renderer refer to [getting started with renderer](renderer_getting_started.md), which also contains the [architecture overview](assets/architecture_renderer.jpg) and [coordinate transformation conventions](assets/transforms_overview.jpg).
25
+
26
+ ## <u>Tech Report</u>
27
+
28
+ For an in depth explanation of the renderer design, key features and benchmarks please refer to the PyTorch3D Technical Report on ArXiv: [Accelerating 3D Deep Learning with PyTorch3D](https://arxiv.org/abs/2007.08501), for the pulsar backend see here: [Fast Differentiable Raycasting for Neural Rendering using Sphere-based Representations](https://arxiv.org/abs/2004.07484).
29
+
30
+ ---
31
+
32
+ **NOTE: CUDA Memory usage**
33
+
34
+ The main comparison in the Technical Report is with SoftRasterizer [[2](#2)]. The SoftRasterizer forward CUDA kernel only outputs one `(N, H, W, 4)` FloatTensor compared with the PyTorch3D rasterizer forward CUDA kernel which outputs 4 tensors:
35
+
36
+ - `pix_to_face`, LongTensor `(N, H, W, K)`
37
+ - `zbuf`, FloatTensor `(N, H, W, K)`
38
+ - `dist`, FloatTensor `(N, H, W, K)`
39
+ - `bary_coords`, FloatTensor `(N, H, W, K, 3)`
40
+
41
+ where **N** = batch size, **H/W** are image height/width, **K** is the faces per pixel. The PyTorch3D backward pass returns gradients for `zbuf`, `dist` and `bary_coords`.
42
+
43
+ Returning intermediate variables from rasterization has an associated memory cost. We can calculate the theoretical lower bound on the memory usage for the forward and backward pass as follows:
44
+
45
+ ```
46
+ # Assume 4 bytes per float, and 8 bytes for long
47
+
48
+ memory_forward_pass = ((N * H * W * K) * 2 + (N * H * W * K * 3)) * 4 + (N * H * W * K) * 8
49
+ memory_backward_pass = ((N * H * W * K) * 2 + (N * H * W * K * 3)) * 4
50
+
51
+ total_memory = memory_forward_pass + memory_backward_pass
52
+ = (N * H * W * K) * (5 * 4 * 2 + 8)
53
+ = (N * H * W * K) * 48
54
+ ```
55
+
56
+ We need 48 bytes per face per pixel of the rasterized output. In order to remain within bounds for memory usage we can vary the batch size (**N**), image size (**H/W**) and faces per pixel (**K**). For example, for a fixed batch size, if using a larger image size, try reducing the faces per pixel.
57
+
58
+ ---
59
+
60
+ ### References
61
+
62
+ <a id="1">[1]</a> Kato et al, 'Neural 3D Mesh Renderer', CVPR 2018
63
+
64
+ <a id="2">[2]</a> Liu et al, 'Soft Rasterizer: A Differentiable Renderer for Image-based 3D Reasoning', ICCV 2019
65
+
66
+ <a id="3">[3]</a> Loper et al, 'OpenDR: An Approximate Differentiable Renderer', ECCV 2014
67
+
68
+ <a id="4">[4]</a> De La Gorce et al, 'Model-based 3D Hand Pose Estimation from Monocular Video', PAMI 2011
69
+
70
+ <a id="5">[5]</a> Li et al, 'Differentiable Monte Carlo Ray Tracing through Edge Sampling', SIGGRAPH Asia 2018
71
+
72
+ <a id="6">[6]</a> Yifan et al, 'Differentiable Surface Splatting for Point-based Geometry Processing', SIGGRAPH Asia 2019
73
+
74
+ <a id="7">[7]</a> Loubet et al, 'Reparameterizing Discontinuous Integrands for Differentiable Rendering', SIGGRAPH Asia 2019
75
+
76
+ <a id="8">[8]</a> Chen et al, 'Learning to Predict 3D Objects with an Interpolation-based Differentiable Renderer', NeurIPS 2019
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/notes/renderer_getting_started.md ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ hide_title: true
3
+ sidebar_label: Getting Started
4
+ ---
5
+
6
+ # Getting Started With Renderer
7
+
8
+ ### Architecture Overview
9
+
10
+ The renderer is designed to be modular, extensible and support batching and gradients for all inputs. The following figure describes all the components of the rendering pipeline.
11
+
12
+ <img src="assets/architecture_renderer.jpg" width="1000">
13
+
14
+ ##### Fragments
15
+
16
+ The **rasterizer** returns 4 output tensors in a named tuple.
17
+
18
+ - **`pix_to_face`**: LongTensor of shape `(N, image_size, image_size, faces_per_pixel)` specifying the indices of the faces (in the packed faces) which overlap each pixel in the image.
19
+ - **`zbuf`**: FloatTensor of shape `(N, image_size, image_size, faces_per_pixel)` giving the z-coordinates of the nearest faces at each pixel in world coordinates, sorted in ascending z-order.
20
+ - **`bary_coords`**: FloatTensor of shape `(N, image_size, image_size, faces_per_pixel, 3)`
21
+ giving the barycentric coordinates in NDC units of the nearest faces at each pixel, sorted in ascending z-order.
22
+ - **`pix_dists`**: FloatTensor of shape `(N, image_size, image_size, faces_per_pixel)` giving the signed Euclidean distance (in NDC units) in the x/y plane of each point closest to the pixel.
23
+
24
+
25
+ See the renderer API reference for more details about each component in the pipeline.
26
+
27
+ ---
28
+
29
+ **NOTE:**
30
+
31
+ The differentiable renderer API is experimental and subject to change!.
32
+
33
+ ---
34
+
35
+ ### Coordinate transformation conventions
36
+
37
+ Rendering requires transformations between several different coordinate frames: world space, view/camera space, NDC space and screen space. At each step it is important to know where the camera is located, how the +X, +Y, +Z axes are aligned and the possible range of values. The following figure outlines the conventions used PyTorch3D.
38
+
39
+ <img src="assets/transforms_overview.jpg" width="1000">
40
+
41
+
42
+ For example, given a teapot mesh, the world coordinate frame, camera coordinate frame and image are shown in the figure below. Note that the world and camera coordinate frames have the +z direction pointing in to the page.
43
+
44
+ <img src="assets/world_camera_image.jpg" width="1000">
45
+
46
+ ---
47
+
48
+ **NOTE: PyTorch3D vs OpenGL**
49
+
50
+ While we tried to emulate several aspects of OpenGL, there are differences in the coordinate frame conventions.
51
+ - The default world coordinate frame in PyTorch3D has +Z pointing in to the screen whereas in OpenGL, +Z is pointing out of the screen. Both are right handed.
52
+ - The NDC coordinate system in PyTorch3D is **right-handed** compared with a **left-handed** NDC coordinate system in OpenGL (the projection matrix switches the handedness).
53
+
54
+ <img align="center" src="assets/opengl_coordframes.png" width="300">
55
+
56
+ ---
57
+
58
+ ### Rasterizing Non Square Images
59
+
60
+ To rasterize an image where H != W, you can specify the `image_size` in the `RasterizationSettings` as a tuple of (H, W).
61
+
62
+ The aspect ratio needs special consideration. There are two aspect ratios to be aware of:
63
+ - the aspect ratio of each pixel
64
+ - the aspect ratio of the output image
65
+ In the cameras e.g. `FoVPerspectiveCameras`, the `aspect_ratio` argument can be used to set the pixel aspect ratio. In the rasterizer, we assume square pixels, but variable image aspect ratio (i.e rectangle images).
66
+
67
+ In most cases you will want to set the camera aspect ratio to 1.0 (i.e. square pixels) and only vary the `image_size` in the `RasterizationSettings`(i.e. the output image dimensions in pixels).
68
+
69
+ ---
70
+
71
+ ### The pulsar backend
72
+
73
+ Since v0.3, [pulsar](https://arxiv.org/abs/2004.07484) can be used as a backend for point-rendering. It has a focus on efficiency, which comes with pros and cons: it is highly optimized and all rendering stages are integrated in the CUDA kernels. This leads to significantly higher speed and better scaling behavior. We use it at Facebook Reality Labs to render and optimize scenes with millions of spheres in resolutions up to 4K. You can find a runtime comparison plot below (settings: `bin_size=None`, `points_per_pixel=5`, `image_size=1024`, `radius=1e-2`, `composite_params.radius=1e-4`; benchmarked on an RTX 2070 GPU).
74
+
75
+ <img align="center" src="assets/pulsar_bm.png" width="300">
76
+
77
+ Pulsar's processing steps are tightly integrated CUDA kernels and do not work with custom `rasterizer` and `compositor` components. We provide two ways to use Pulsar: (1) there is a unified interface to match the PyTorch3D calling convention seamlessly. This is, for example, illustrated in the [point cloud tutorial](https://github.com/facebookresearch/pytorch3d/blob/main/docs/tutorials/render_colored_points.ipynb). (2) There is a direct interface available to the pulsar backend, which exposes the full functionality of the backend (including opacity, which is not yet available in PyTorch3D). Examples showing its use as well as the matching PyTorch3D interface code are available in [this folder](https://github.com/facebookresearch/pytorch3d/tree/master/docs/examples).
78
+
79
+ ---
80
+
81
+ ### Texturing options
82
+
83
+ For mesh texturing we offer several options (in `pytorch3d/renderer/mesh/texturing.py`):
84
+
85
+ 1. **Vertex Textures**: D dimensional textures for each vertex (for example an RGB color) which can be interpolated across the face. This can be represented as an `(N, V, D)` tensor. This is a fairly simple representation though and cannot model complex textures if the mesh faces are large.
86
+ 2. **UV Textures**: vertex UV coordinates and **one** texture map for the whole mesh. For a point on a face with given barycentric coordinates, the face color can be computed by interpolating the vertex uv coordinates and then sampling from the texture map. This representation requires two tensors (UVs: `(N, V, 2), Texture map: `(N, H, W, 3)`), and is limited to only support one texture map per mesh.
87
+ 3. **Face Textures**: In more complex cases such as ShapeNet meshes, there are multiple texture maps per mesh and some faces have texture while other do not. For these cases, a more flexible representation is a texture atlas, where each face is represented as an `(RxR)` texture map where R is the texture resolution. For a given point on the face, the texture value can be sampled from the per face texture map using the barycentric coordinates of the point. This representation requires one tensor of shape `(N, F, R, R, 3)`. This texturing method is inspired by the SoftRasterizer implementation. For more details refer to the [`make_material_atlas`](https://github.com/facebookresearch/pytorch3d/blob/main/pytorch3d/io/mtl_io.py#L123) and [`sample_textures`](https://github.com/facebookresearch/pytorch3d/blob/main/pytorch3d/renderer/mesh/textures.py#L452) functions. **NOTE:**: The `TexturesAtlas` texture sampling is only differentiable with respect to the texture atlas but not differentiable with respect to the barycentric coordinates.
88
+
89
+
90
+ <img src="assets/texturing.jpg" width="1000">
91
+
92
+ ---
93
+
94
+ ### A simple renderer
95
+
96
+ A renderer in PyTorch3D is composed of a **rasterizer** and a **shader**. Create a renderer in a few simple steps:
97
+
98
+ ```
99
+ # Imports
100
+ from pytorch3d.renderer import (
101
+ FoVPerspectiveCameras, look_at_view_transform,
102
+ RasterizationSettings, BlendParams,
103
+ MeshRenderer, MeshRasterizer, HardPhongShader
104
+ )
105
+
106
+ # Initialize an OpenGL perspective camera.
107
+ R, T = look_at_view_transform(2.7, 10, 20)
108
+ cameras = FoVPerspectiveCameras(device=device, R=R, T=T)
109
+
110
+ # Define the settings for rasterization and shading. Here we set the output image to be of size
111
+ # 512x512. As we are rendering images for visualization purposes only we will set faces_per_pixel=1
112
+ # and blur_radius=0.0. Refer to rasterize_meshes.py for explanations of these parameters.
113
+ raster_settings = RasterizationSettings(
114
+ image_size=512,
115
+ blur_radius=0.0,
116
+ faces_per_pixel=1,
117
+ )
118
+
119
+ # Create a Phong renderer by composing a rasterizer and a shader. Here we can use a predefined
120
+ # PhongShader, passing in the device on which to initialize the default parameters
121
+ renderer = MeshRenderer(
122
+ rasterizer=MeshRasterizer(cameras=cameras, raster_settings=raster_settings),
123
+ shader=HardPhongShader(device=device, cameras=cameras)
124
+ )
125
+ ```
126
+
127
+ ---
128
+
129
+ ### A custom shader
130
+
131
+ Shaders are the most flexible part of the PyTorch3D rendering API. We have created some examples of shaders in `shaders.py` but this is a non exhaustive set.
132
+
133
+ A shader can incorporate several steps:
134
+ - **texturing** (e.g interpolation of vertex RGB colors or interpolation of vertex UV coordinates followed by sampling from a texture map (interpolation uses barycentric coordinates output from rasterization))
135
+ - **lighting/shading** (e.g. ambient, diffuse, specular lighting, Phong, Gouraud, Flat)
136
+ - **blending** (e.g. hard blending using only the closest face for each pixel, or soft blending using a weighted sum of the top K faces per pixel)
137
+
138
+ We have examples of several combinations of these functions based on the texturing/shading/blending support we have currently. These are summarised in this table below. Many other combinations are possible and we plan to expand the options available for texturing, shading and blending.
139
+
140
+ |Example Shaders | Vertex Textures| UV Textures | Textures Atlas | Flat Shading| Gouraud Shading| Phong Shading | Hard blending | Soft Blending |
141
+ | ------------- |:-------------: | :--------------:| :--------------:| :--------------:| :--------------:| :--------------:|:--------------:|:--------------:|
142
+ | HardPhongShader | ✔️ |✔️|✔️||| ✔️ | ✔️||
143
+ | SoftPhongShader | ✔️ |✔️|✔️||| ✔️ | | ✔️|
144
+ | HardGouraudShader | ✔️ |✔️|✔️|| ✔️ || ✔️||
145
+ | SoftGouraudShader | ✔️ |✔️|✔️|| ✔️ ||| ✔️|
146
+ | HardFlatShader | ✔️ |✔️|✔️| ✔️ ||| ✔️||
147
+ | SoftSilhouetteShader |||||||| ✔️|
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/notes/visualization.md ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ hide_title: true
3
+ sidebar_label: Plotly Visualization
4
+ ---
5
+
6
+ # Overview
7
+
8
+ PyTorch3D provides a modular differentiable renderer, but for instances where we want interactive plots or are not concerned with the differentiability of the rendering process, we provide [functions to render meshes and pointclouds in plotly](https://github.com/facebookresearch/pytorch3d/blob/main/pytorch3d/vis/plotly_vis.py). These plotly figures allow you to rotate and zoom the rendered images and support plotting batched data as multiple traces in a singular plot or divided into individual subplots.
9
+
10
+
11
+ # Examples
12
+
13
+ These rendering functions accept plotly x,y, and z axis arguments as `kwargs`, allowing us to customize the plots. Here are two plots with colored axes, a [Pointclouds plot](assets/plotly_pointclouds.png), a [batched Meshes plot in subplots](assets/plotly_meshes_batch.png), and a [batched Meshes plot with multiple traces](assets/plotly_meshes_trace.png). Refer to the [render textured meshes](https://pytorch3d.org/tutorials/render_textured_meshes) and [render colored pointclouds](https://pytorch3d.org/tutorials/render_colored_points) tutorials for code examples.
14
+
15
+ # Saving plots to images
16
+
17
+ If you want to save these plotly plots, you will need to install a separate library such as [Kaleido](https://plotly.com/python/static-image-export/).
18
+
19
+ Install Kaleido
20
+ ```
21
+ $ pip install Kaleido
22
+ ```
23
+ Export a figure as a .png image. The image will be saved in the current working directory.
24
+ ```
25
+ fig = ...
26
+ fig.write_image("image_name.png")
27
+ ```
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/docs/notes/why_pytorch3d.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ hide_title: true
3
+ sidebar_label: Why PyTorch3D
4
+ ---
5
+
6
+
7
+ # Why PyTorch3D
8
+
9
+
10
+ Our goal with PyTorch3D is to help accelerate research at the intersection of deep learning and 3D. 3D data is more complex than 2D images and while working on projects such as [Mesh R-CNN](https://github.com/facebookresearch/meshrcnn) and [C3DPO](https://github.com/facebookresearch/c3dpo_nrsfm), we encountered several challenges including 3D data representation, batching, and speed. We have developed many useful operators and abstractions for working on 3D deep learning and want to share this with the community to drive novel research in this area.
11
+
12
+ In PyTorch3D we have included efficient 3D operators, heterogeneous batching capabilities, and a modular differentiable rendering API, to equip researchers in this field with a much needed toolkit to implement cutting-edge research with complex 3D inputs.
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/pytorch3d/ops/marching_cubes.py ADDED
@@ -0,0 +1,305 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ # All rights reserved.
3
+ #
4
+ # This source code is licensed under the BSD-style license found in the
5
+ # LICENSE file in the root directory of this source tree.
6
+
7
+ # pyre-unsafe
8
+
9
+ from typing import List, Optional, Tuple
10
+
11
+ import torch
12
+ from pytorch3d import _C
13
+ from pytorch3d.ops.marching_cubes_data import EDGE_TO_VERTICES, FACE_TABLE, INDEX
14
+ from pytorch3d.transforms import Translate
15
+ from torch.autograd import Function
16
+
17
+
18
+ EPS = 0.00001
19
+
20
+
21
+ class Cube:
22
+ def __init__(
23
+ self,
24
+ bfl_v: Tuple[int, int, int],
25
+ volume: torch.Tensor,
26
+ isolevel: float,
27
+ ) -> None:
28
+ """
29
+ Initializes a cube given the bottom front left vertex coordinate
30
+ and computes the cube configuration given vertex values and isolevel.
31
+
32
+ Edge and vertex convention:
33
+
34
+ v4_______e4____________v5
35
+ /| /|
36
+ / | / |
37
+ e7/ | e5/ |
38
+ /___|______e6_________/ |
39
+ v7| | |v6 |e9
40
+ | | | |
41
+ | |e8 |e10|
42
+ e11| | | |
43
+ | |______e0_________|___|
44
+ | / v0(bfl_v) | |v1
45
+ | / | /
46
+ | /e3 | /e1
47
+ |/_____________________|/
48
+ v3 e2 v2
49
+
50
+ Args:
51
+ bfl_vertex: a tuple of size 3 corresponding to the bottom front left vertex
52
+ of the cube in (x, y, z) format
53
+ volume: the 3D scalar data
54
+ isolevel: the isosurface value used as a threshold for determining whether a point
55
+ is inside/outside the volume
56
+ """
57
+ x, y, z = bfl_v
58
+ self.x, self.y, self.z = x, y, z
59
+ self.bfl_v = bfl_v
60
+ self.verts = [
61
+ [x + (v & 1), y + (v >> 1 & 1), z + (v >> 2 & 1)] for v in range(8)
62
+ ] # vertex position (x, y, z) for v0-v1-v4-v5-v3-v2-v7-v6
63
+
64
+ # Calculates cube configuration index given values of the cube vertices
65
+ self.cube_index = 0
66
+ for i in range(8):
67
+ v = self.verts[INDEX[i]]
68
+ value = volume[v[2]][v[1]][v[0]]
69
+ if value < isolevel:
70
+ self.cube_index |= 1 << i
71
+
72
+ def get_vpair_from_edge(self, edge: int, W: int, H: int) -> Tuple[int, int]:
73
+ """
74
+ Get a tuple of global vertex ID from a local edge ID
75
+ Global vertex ID is calculated as (x + dx) + (y + dy) * W + (z + dz) * W * H
76
+
77
+ Args:
78
+ edge: local edge ID in the cube
79
+ bfl_vertex: bottom-front-left coordinate of the cube
80
+
81
+ Returns:
82
+ a pair of global vertex ID
83
+ """
84
+ v1, v2 = EDGE_TO_VERTICES[edge] # two end-points on the edge
85
+ v1_id = self.verts[v1][0] + self.verts[v1][1] * W + self.verts[v1][2] * W * H
86
+ v2_id = self.verts[v2][0] + self.verts[v2][1] * W + self.verts[v2][2] * W * H
87
+ return (v1_id, v2_id)
88
+
89
+ def vert_interp(
90
+ self,
91
+ isolevel: float,
92
+ edge: int,
93
+ vol: torch.Tensor,
94
+ ) -> List:
95
+ """
96
+ Linearly interpolate a vertex where an isosurface cuts an edge
97
+ between the two endpoint vertices, based on their values
98
+
99
+ Args:
100
+ isolevel: the isosurface value to use as the threshold to determine
101
+ whether points are within a volume.
102
+ edge: edge (ID) to interpolate
103
+ cube: current cube vertices
104
+ vol: 3D scalar field
105
+
106
+ Returns:
107
+ interpolated vertex: position of the interpolated vertex on the edge
108
+ """
109
+ v1, v2 = EDGE_TO_VERTICES[edge]
110
+ p1, p2 = self.verts[v1], self.verts[v2]
111
+ val1, val2 = (
112
+ vol[p1[2]][p1[1]][p1[0]],
113
+ vol[p2[2]][p2[1]][p2[0]],
114
+ )
115
+ point = None
116
+ if abs(isolevel - val1) < EPS:
117
+ point = p1
118
+ elif abs(isolevel - val2) < EPS:
119
+ point = p2
120
+ elif abs(val1 - val2) < EPS:
121
+ point = p1
122
+
123
+ if point is None:
124
+ mu = (isolevel - val1) / (val2 - val1)
125
+ x1, y1, z1 = p1
126
+ x2, y2, z2 = p2
127
+ x = x1 + mu * (x2 - x1)
128
+ y = y1 + mu * (y2 - y1)
129
+ z = z1 + mu * (z2 - z1)
130
+ else:
131
+ x, y, z = point
132
+ return [x, y, z]
133
+
134
+
135
+ def marching_cubes_naive(
136
+ vol_batch: torch.Tensor,
137
+ isolevel: Optional[float] = None,
138
+ return_local_coords: bool = True,
139
+ ) -> Tuple[List[torch.Tensor], List[torch.Tensor]]:
140
+ """
141
+ Runs the classic marching cubes algorithm, iterating over
142
+ the coordinates of the volume and using a given isolevel
143
+ for determining intersected edges of cubes.
144
+ Returns vertices and faces of the obtained mesh.
145
+ This operation is non-differentiable.
146
+
147
+ Args:
148
+ vol_batch: a Tensor of size (N, D, H, W) corresponding to
149
+ a batch of 3D scalar fields
150
+ isolevel: the isosurface value to use as the threshold to determine
151
+ whether points are within a volume. If None, then the average of the
152
+ maximum and minimum value of the scalar field will be used.
153
+ return_local_coords: bool. If True the output vertices will be in local coordinates in
154
+ the range [-1, 1] x [-1, 1] x [-1, 1]. If False they will be in the range
155
+ [0, W-1] x [0, H-1] x [0, D-1]
156
+ Returns:
157
+ verts: [{V_0}, {V_1}, ...] List of N sets of vertices of shape (|V_i|, 3) in FloatTensor
158
+ faces: [{F_0}, {F_1}, ...] List of N sets of faces of shape (|F_i|, 3) in LongTensors
159
+ """
160
+ batched_verts, batched_faces = [], []
161
+ D, H, W = vol_batch.shape[1:]
162
+
163
+ # each edge is represented with its two endpoints (represented with global id)
164
+ for i in range(len(vol_batch)):
165
+ vol = vol_batch[i]
166
+ thresh = ((vol.max() + vol.min()) / 2).item() if isolevel is None else isolevel
167
+ vpair_to_edge = {} # maps from tuple of edge endpoints to edge_id
168
+ edge_id_to_v = {} # maps from edge ID to vertex position
169
+ uniq_edge_id = {} # unique edge IDs
170
+ verts = [] # store vertex positions
171
+ faces = [] # store face indices
172
+ # enumerate each cell in the 3d grid
173
+ for z in range(0, D - 1):
174
+ for y in range(0, H - 1):
175
+ for x in range(0, W - 1):
176
+ cube = Cube((x, y, z), vol, thresh)
177
+ edge_indices = FACE_TABLE[cube.cube_index]
178
+ # cube is entirely in/out of the surface
179
+ if len(edge_indices) == 0:
180
+ continue
181
+
182
+ # gather mesh vertices/faces by processing each cube
183
+ interp_points = [[0.0, 0.0, 0.0]] * 12
184
+ # triangle vertex IDs and positions
185
+ tri = []
186
+ ps = []
187
+ for i, edge in enumerate(edge_indices):
188
+ interp_points[edge] = cube.vert_interp(thresh, edge, vol)
189
+
190
+ # Bind interpolated vertex with a global edge_id, which
191
+ # is represented by a pair of vertex ids (v1_id, v2_id)
192
+ # corresponding to a local edge.
193
+ (v1_id, v2_id) = cube.get_vpair_from_edge(edge, W, H)
194
+ edge_id = vpair_to_edge.setdefault(
195
+ (v1_id, v2_id), len(vpair_to_edge)
196
+ )
197
+ tri.append(edge_id)
198
+ ps.append(interp_points[edge])
199
+ # when the isolevel are the same as the edge endpoints, the interploated
200
+ # vertices can share the same values, and lead to degenerate triangles.
201
+ if (
202
+ (i + 1) % 3 == 0
203
+ and ps[0] != ps[1]
204
+ and ps[1] != ps[2]
205
+ and ps[2] != ps[0]
206
+ ):
207
+ for j, edge_id in enumerate(tri):
208
+ edge_id_to_v[edge_id] = ps[j]
209
+ if edge_id not in uniq_edge_id:
210
+ uniq_edge_id[edge_id] = len(verts)
211
+ verts.append(edge_id_to_v[edge_id])
212
+ faces.append([uniq_edge_id[tri[j]] for j in range(3)])
213
+ tri = []
214
+ ps = []
215
+
216
+ if len(faces) > 0 and len(verts) > 0:
217
+ verts = torch.tensor(verts, dtype=vol.dtype)
218
+ # Convert from world coordinates ([0, D-1], [0, H-1], [0, W-1]) to
219
+ # local coordinates in the range [-1, 1]
220
+ if return_local_coords:
221
+ verts = (
222
+ Translate(x=+1.0, y=+1.0, z=+1.0, device=vol_batch.device)
223
+ .scale((vol_batch.new_tensor([W, H, D])[None] - 1) * 0.5)
224
+ .inverse()
225
+ ).transform_points(verts[None])[0]
226
+ batched_verts.append(verts)
227
+ batched_faces.append(torch.tensor(faces, dtype=torch.int64))
228
+ else:
229
+ batched_verts.append([])
230
+ batched_faces.append([])
231
+ return batched_verts, batched_faces
232
+
233
+
234
+ ########################################
235
+ # Marching Cubes Implementation in C++/Cuda
236
+ ########################################
237
+ class _marching_cubes(Function):
238
+ """
239
+ Torch Function wrapper for marching_cubes implementation.
240
+ This function is not differentiable. An autograd wrapper is used
241
+ to ensure an error if user tries to get gradients.
242
+ """
243
+
244
+ @staticmethod
245
+ def forward(ctx, vol, isolevel):
246
+ verts, faces, ids = _C.marching_cubes(vol, isolevel)
247
+ return verts, faces, ids
248
+
249
+ @staticmethod
250
+ def backward(ctx, grad_verts, grad_faces):
251
+ raise ValueError("marching_cubes backward is not supported")
252
+
253
+
254
+ def marching_cubes(
255
+ vol_batch: torch.Tensor,
256
+ isolevel: Optional[float] = None,
257
+ return_local_coords: bool = True,
258
+ ) -> Tuple[List[torch.Tensor], List[torch.Tensor]]:
259
+ """
260
+ Run marching cubes over a volume scalar field with a designated isolevel.
261
+ Returns vertices and faces of the obtained mesh.
262
+ This operation is non-differentiable.
263
+
264
+ Args:
265
+ vol_batch: a Tensor of size (N, D, H, W) corresponding to
266
+ a batch of 3D scalar fields
267
+ isolevel: float used as threshold to determine if a point is inside/outside
268
+ the volume. If None, then the average of the maximum and minimum value
269
+ of the scalar field is used.
270
+ return_local_coords: bool. If True the output vertices will be in local coordinates in
271
+ the range [-1, 1] x [-1, 1] x [-1, 1]. If False they will be in the range
272
+ [0, W-1] x [0, H-1] x [0, D-1]
273
+
274
+ Returns:
275
+ verts: [{V_0}, {V_1}, ...] List of N sets of vertices of shape (|V_i|, 3) in FloatTensor
276
+ faces: [{F_0}, {F_1}, ...] List of N sets of faces of shape (|F_i|, 3) in LongTensors
277
+ """
278
+ batched_verts, batched_faces = [], []
279
+ D, H, W = vol_batch.shape[1:]
280
+ for i in range(len(vol_batch)):
281
+ vol = vol_batch[i]
282
+ thresh = ((vol.max() + vol.min()) / 2).item() if isolevel is None else isolevel
283
+ verts, faces, ids = _marching_cubes.apply(vol, thresh)
284
+ if len(faces) > 0 and len(verts) > 0:
285
+ # Convert from world coordinates ([0, D-1], [0, H-1], [0, W-1]) to
286
+ # local coordinates in the range [-1, 1]
287
+ if return_local_coords:
288
+ verts = (
289
+ Translate(x=+1.0, y=+1.0, z=+1.0, device=vol.device)
290
+ .scale((vol.new_tensor([W, H, D])[None] - 1) * 0.5)
291
+ .inverse()
292
+ ).transform_points(verts[None])[0]
293
+ # deduplication for cuda
294
+ if vol.is_cuda:
295
+ unique_ids, inverse_idx = torch.unique(ids, return_inverse=True)
296
+ verts_ = verts.new_zeros(unique_ids.shape[0], 3)
297
+ verts_[inverse_idx] = verts
298
+ verts = verts_
299
+ faces = inverse_idx[faces]
300
+ batched_verts.append(verts)
301
+ batched_faces.append(faces)
302
+ else:
303
+ batched_verts.append([])
304
+ batched_faces.append([])
305
+ return batched_verts, batched_faces
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/pytorch3d/ops/marching_cubes_data.py ADDED
@@ -0,0 +1,291 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ # All rights reserved.
3
+ #
4
+ # This source code is licensed under the BSD-style license found in the
5
+ # LICENSE file in the root directory of this source tree.
6
+
7
+ # pyre-unsafe
8
+
9
+
10
+ # Maps each edge (by index) to the corresponding cube vertices
11
+ EDGE_TO_VERTICES = [
12
+ [0, 1],
13
+ [1, 5],
14
+ [4, 5],
15
+ [0, 4],
16
+ [2, 3],
17
+ [3, 7],
18
+ [6, 7],
19
+ [2, 6],
20
+ [0, 2],
21
+ [1, 3],
22
+ [5, 7],
23
+ [4, 6],
24
+ ]
25
+
26
+ # A list of lists mapping a cube_index (a given configuration)
27
+ # to a list of faces corresponding to that configuration. Each face is represented
28
+ # by 3 consecutive numbers. A configuration will at most have 5 faces.
29
+ #
30
+ # Table taken from http://paulbourke.net/geometry/polygonise/
31
+ FACE_TABLE = [
32
+ [],
33
+ [0, 8, 3],
34
+ [0, 1, 9],
35
+ [1, 8, 3, 9, 8, 1],
36
+ [1, 2, 10],
37
+ [0, 8, 3, 1, 2, 10],
38
+ [9, 2, 10, 0, 2, 9],
39
+ [2, 8, 3, 2, 10, 8, 10, 9, 8],
40
+ [3, 11, 2],
41
+ [0, 11, 2, 8, 11, 0],
42
+ [1, 9, 0, 2, 3, 11],
43
+ [1, 11, 2, 1, 9, 11, 9, 8, 11],
44
+ [3, 10, 1, 11, 10, 3],
45
+ [0, 10, 1, 0, 8, 10, 8, 11, 10],
46
+ [3, 9, 0, 3, 11, 9, 11, 10, 9],
47
+ [9, 8, 10, 10, 8, 11],
48
+ [4, 7, 8],
49
+ [4, 3, 0, 7, 3, 4],
50
+ [0, 1, 9, 8, 4, 7],
51
+ [4, 1, 9, 4, 7, 1, 7, 3, 1],
52
+ [1, 2, 10, 8, 4, 7],
53
+ [3, 4, 7, 3, 0, 4, 1, 2, 10],
54
+ [9, 2, 10, 9, 0, 2, 8, 4, 7],
55
+ [2, 10, 9, 2, 9, 7, 2, 7, 3, 7, 9, 4],
56
+ [8, 4, 7, 3, 11, 2],
57
+ [11, 4, 7, 11, 2, 4, 2, 0, 4],
58
+ [9, 0, 1, 8, 4, 7, 2, 3, 11],
59
+ [4, 7, 11, 9, 4, 11, 9, 11, 2, 9, 2, 1],
60
+ [3, 10, 1, 3, 11, 10, 7, 8, 4],
61
+ [1, 11, 10, 1, 4, 11, 1, 0, 4, 7, 11, 4],
62
+ [4, 7, 8, 9, 0, 11, 9, 11, 10, 11, 0, 3],
63
+ [4, 7, 11, 4, 11, 9, 9, 11, 10],
64
+ [9, 5, 4],
65
+ [9, 5, 4, 0, 8, 3],
66
+ [0, 5, 4, 1, 5, 0],
67
+ [8, 5, 4, 8, 3, 5, 3, 1, 5],
68
+ [1, 2, 10, 9, 5, 4],
69
+ [3, 0, 8, 1, 2, 10, 4, 9, 5],
70
+ [5, 2, 10, 5, 4, 2, 4, 0, 2],
71
+ [2, 10, 5, 3, 2, 5, 3, 5, 4, 3, 4, 8],
72
+ [9, 5, 4, 2, 3, 11],
73
+ [0, 11, 2, 0, 8, 11, 4, 9, 5],
74
+ [0, 5, 4, 0, 1, 5, 2, 3, 11],
75
+ [2, 1, 5, 2, 5, 8, 2, 8, 11, 4, 8, 5],
76
+ [10, 3, 11, 10, 1, 3, 9, 5, 4],
77
+ [4, 9, 5, 0, 8, 1, 8, 10, 1, 8, 11, 10],
78
+ [5, 4, 0, 5, 0, 11, 5, 11, 10, 11, 0, 3],
79
+ [5, 4, 8, 5, 8, 10, 10, 8, 11],
80
+ [9, 7, 8, 5, 7, 9],
81
+ [9, 3, 0, 9, 5, 3, 5, 7, 3],
82
+ [0, 7, 8, 0, 1, 7, 1, 5, 7],
83
+ [1, 5, 3, 3, 5, 7],
84
+ [9, 7, 8, 9, 5, 7, 10, 1, 2],
85
+ [10, 1, 2, 9, 5, 0, 5, 3, 0, 5, 7, 3],
86
+ [8, 0, 2, 8, 2, 5, 8, 5, 7, 10, 5, 2],
87
+ [2, 10, 5, 2, 5, 3, 3, 5, 7],
88
+ [7, 9, 5, 7, 8, 9, 3, 11, 2],
89
+ [9, 5, 7, 9, 7, 2, 9, 2, 0, 2, 7, 11],
90
+ [2, 3, 11, 0, 1, 8, 1, 7, 8, 1, 5, 7],
91
+ [11, 2, 1, 11, 1, 7, 7, 1, 5],
92
+ [9, 5, 8, 8, 5, 7, 10, 1, 3, 10, 3, 11],
93
+ [5, 7, 0, 5, 0, 9, 7, 11, 0, 1, 0, 10, 11, 10, 0],
94
+ [11, 10, 0, 11, 0, 3, 10, 5, 0, 8, 0, 7, 5, 7, 0],
95
+ [11, 10, 5, 7, 11, 5],
96
+ [10, 6, 5],
97
+ [0, 8, 3, 5, 10, 6],
98
+ [9, 0, 1, 5, 10, 6],
99
+ [1, 8, 3, 1, 9, 8, 5, 10, 6],
100
+ [1, 6, 5, 2, 6, 1],
101
+ [1, 6, 5, 1, 2, 6, 3, 0, 8],
102
+ [9, 6, 5, 9, 0, 6, 0, 2, 6],
103
+ [5, 9, 8, 5, 8, 2, 5, 2, 6, 3, 2, 8],
104
+ [2, 3, 11, 10, 6, 5],
105
+ [11, 0, 8, 11, 2, 0, 10, 6, 5],
106
+ [0, 1, 9, 2, 3, 11, 5, 10, 6],
107
+ [5, 10, 6, 1, 9, 2, 9, 11, 2, 9, 8, 11],
108
+ [6, 3, 11, 6, 5, 3, 5, 1, 3],
109
+ [0, 8, 11, 0, 11, 5, 0, 5, 1, 5, 11, 6],
110
+ [3, 11, 6, 0, 3, 6, 0, 6, 5, 0, 5, 9],
111
+ [6, 5, 9, 6, 9, 11, 11, 9, 8],
112
+ [5, 10, 6, 4, 7, 8],
113
+ [4, 3, 0, 4, 7, 3, 6, 5, 10],
114
+ [1, 9, 0, 5, 10, 6, 8, 4, 7],
115
+ [10, 6, 5, 1, 9, 7, 1, 7, 3, 7, 9, 4],
116
+ [6, 1, 2, 6, 5, 1, 4, 7, 8],
117
+ [1, 2, 5, 5, 2, 6, 3, 0, 4, 3, 4, 7],
118
+ [8, 4, 7, 9, 0, 5, 0, 6, 5, 0, 2, 6],
119
+ [7, 3, 9, 7, 9, 4, 3, 2, 9, 5, 9, 6, 2, 6, 9],
120
+ [3, 11, 2, 7, 8, 4, 10, 6, 5],
121
+ [5, 10, 6, 4, 7, 2, 4, 2, 0, 2, 7, 11],
122
+ [0, 1, 9, 4, 7, 8, 2, 3, 11, 5, 10, 6],
123
+ [9, 2, 1, 9, 11, 2, 9, 4, 11, 7, 11, 4, 5, 10, 6],
124
+ [8, 4, 7, 3, 11, 5, 3, 5, 1, 5, 11, 6],
125
+ [5, 1, 11, 5, 11, 6, 1, 0, 11, 7, 11, 4, 0, 4, 11],
126
+ [0, 5, 9, 0, 6, 5, 0, 3, 6, 11, 6, 3, 8, 4, 7],
127
+ [6, 5, 9, 6, 9, 11, 4, 7, 9, 7, 11, 9],
128
+ [10, 4, 9, 6, 4, 10],
129
+ [4, 10, 6, 4, 9, 10, 0, 8, 3],
130
+ [10, 0, 1, 10, 6, 0, 6, 4, 0],
131
+ [8, 3, 1, 8, 1, 6, 8, 6, 4, 6, 1, 10],
132
+ [1, 4, 9, 1, 2, 4, 2, 6, 4],
133
+ [3, 0, 8, 1, 2, 9, 2, 4, 9, 2, 6, 4],
134
+ [0, 2, 4, 4, 2, 6],
135
+ [8, 3, 2, 8, 2, 4, 4, 2, 6],
136
+ [10, 4, 9, 10, 6, 4, 11, 2, 3],
137
+ [0, 8, 2, 2, 8, 11, 4, 9, 10, 4, 10, 6],
138
+ [3, 11, 2, 0, 1, 6, 0, 6, 4, 6, 1, 10],
139
+ [6, 4, 1, 6, 1, 10, 4, 8, 1, 2, 1, 11, 8, 11, 1],
140
+ [9, 6, 4, 9, 3, 6, 9, 1, 3, 11, 6, 3],
141
+ [8, 11, 1, 8, 1, 0, 11, 6, 1, 9, 1, 4, 6, 4, 1],
142
+ [3, 11, 6, 3, 6, 0, 0, 6, 4],
143
+ [6, 4, 8, 11, 6, 8],
144
+ [7, 10, 6, 7, 8, 10, 8, 9, 10],
145
+ [0, 7, 3, 0, 10, 7, 0, 9, 10, 6, 7, 10],
146
+ [10, 6, 7, 1, 10, 7, 1, 7, 8, 1, 8, 0],
147
+ [10, 6, 7, 10, 7, 1, 1, 7, 3],
148
+ [1, 2, 6, 1, 6, 8, 1, 8, 9, 8, 6, 7],
149
+ [2, 6, 9, 2, 9, 1, 6, 7, 9, 0, 9, 3, 7, 3, 9],
150
+ [7, 8, 0, 7, 0, 6, 6, 0, 2],
151
+ [7, 3, 2, 6, 7, 2],
152
+ [2, 3, 11, 10, 6, 8, 10, 8, 9, 8, 6, 7],
153
+ [2, 0, 7, 2, 7, 11, 0, 9, 7, 6, 7, 10, 9, 10, 7],
154
+ [1, 8, 0, 1, 7, 8, 1, 10, 7, 6, 7, 10, 2, 3, 11],
155
+ [11, 2, 1, 11, 1, 7, 10, 6, 1, 6, 7, 1],
156
+ [8, 9, 6, 8, 6, 7, 9, 1, 6, 11, 6, 3, 1, 3, 6],
157
+ [0, 9, 1, 11, 6, 7],
158
+ [7, 8, 0, 7, 0, 6, 3, 11, 0, 11, 6, 0],
159
+ [7, 11, 6],
160
+ [7, 6, 11],
161
+ [3, 0, 8, 11, 7, 6],
162
+ [0, 1, 9, 11, 7, 6],
163
+ [8, 1, 9, 8, 3, 1, 11, 7, 6],
164
+ [10, 1, 2, 6, 11, 7],
165
+ [1, 2, 10, 3, 0, 8, 6, 11, 7],
166
+ [2, 9, 0, 2, 10, 9, 6, 11, 7],
167
+ [6, 11, 7, 2, 10, 3, 10, 8, 3, 10, 9, 8],
168
+ [7, 2, 3, 6, 2, 7],
169
+ [7, 0, 8, 7, 6, 0, 6, 2, 0],
170
+ [2, 7, 6, 2, 3, 7, 0, 1, 9],
171
+ [1, 6, 2, 1, 8, 6, 1, 9, 8, 8, 7, 6],
172
+ [10, 7, 6, 10, 1, 7, 1, 3, 7],
173
+ [10, 7, 6, 1, 7, 10, 1, 8, 7, 1, 0, 8],
174
+ [0, 3, 7, 0, 7, 10, 0, 10, 9, 6, 10, 7],
175
+ [7, 6, 10, 7, 10, 8, 8, 10, 9],
176
+ [6, 8, 4, 11, 8, 6],
177
+ [3, 6, 11, 3, 0, 6, 0, 4, 6],
178
+ [8, 6, 11, 8, 4, 6, 9, 0, 1],
179
+ [9, 4, 6, 9, 6, 3, 9, 3, 1, 11, 3, 6],
180
+ [6, 8, 4, 6, 11, 8, 2, 10, 1],
181
+ [1, 2, 10, 3, 0, 11, 0, 6, 11, 0, 4, 6],
182
+ [4, 11, 8, 4, 6, 11, 0, 2, 9, 2, 10, 9],
183
+ [10, 9, 3, 10, 3, 2, 9, 4, 3, 11, 3, 6, 4, 6, 3],
184
+ [8, 2, 3, 8, 4, 2, 4, 6, 2],
185
+ [0, 4, 2, 4, 6, 2],
186
+ [1, 9, 0, 2, 3, 4, 2, 4, 6, 4, 3, 8],
187
+ [1, 9, 4, 1, 4, 2, 2, 4, 6],
188
+ [8, 1, 3, 8, 6, 1, 8, 4, 6, 6, 10, 1],
189
+ [10, 1, 0, 10, 0, 6, 6, 0, 4],
190
+ [4, 6, 3, 4, 3, 8, 6, 10, 3, 0, 3, 9, 10, 9, 3],
191
+ [10, 9, 4, 6, 10, 4],
192
+ [4, 9, 5, 7, 6, 11],
193
+ [0, 8, 3, 4, 9, 5, 11, 7, 6],
194
+ [5, 0, 1, 5, 4, 0, 7, 6, 11],
195
+ [11, 7, 6, 8, 3, 4, 3, 5, 4, 3, 1, 5],
196
+ [9, 5, 4, 10, 1, 2, 7, 6, 11],
197
+ [6, 11, 7, 1, 2, 10, 0, 8, 3, 4, 9, 5],
198
+ [7, 6, 11, 5, 4, 10, 4, 2, 10, 4, 0, 2],
199
+ [3, 4, 8, 3, 5, 4, 3, 2, 5, 10, 5, 2, 11, 7, 6],
200
+ [7, 2, 3, 7, 6, 2, 5, 4, 9],
201
+ [9, 5, 4, 0, 8, 6, 0, 6, 2, 6, 8, 7],
202
+ [3, 6, 2, 3, 7, 6, 1, 5, 0, 5, 4, 0],
203
+ [6, 2, 8, 6, 8, 7, 2, 1, 8, 4, 8, 5, 1, 5, 8],
204
+ [9, 5, 4, 10, 1, 6, 1, 7, 6, 1, 3, 7],
205
+ [1, 6, 10, 1, 7, 6, 1, 0, 7, 8, 7, 0, 9, 5, 4],
206
+ [4, 0, 10, 4, 10, 5, 0, 3, 10, 6, 10, 7, 3, 7, 10],
207
+ [7, 6, 10, 7, 10, 8, 5, 4, 10, 4, 8, 10],
208
+ [6, 9, 5, 6, 11, 9, 11, 8, 9],
209
+ [3, 6, 11, 0, 6, 3, 0, 5, 6, 0, 9, 5],
210
+ [0, 11, 8, 0, 5, 11, 0, 1, 5, 5, 6, 11],
211
+ [6, 11, 3, 6, 3, 5, 5, 3, 1],
212
+ [1, 2, 10, 9, 5, 11, 9, 11, 8, 11, 5, 6],
213
+ [0, 11, 3, 0, 6, 11, 0, 9, 6, 5, 6, 9, 1, 2, 10],
214
+ [11, 8, 5, 11, 5, 6, 8, 0, 5, 10, 5, 2, 0, 2, 5],
215
+ [6, 11, 3, 6, 3, 5, 2, 10, 3, 10, 5, 3],
216
+ [5, 8, 9, 5, 2, 8, 5, 6, 2, 3, 8, 2],
217
+ [9, 5, 6, 9, 6, 0, 0, 6, 2],
218
+ [1, 5, 8, 1, 8, 0, 5, 6, 8, 3, 8, 2, 6, 2, 8],
219
+ [1, 5, 6, 2, 1, 6],
220
+ [1, 3, 6, 1, 6, 10, 3, 8, 6, 5, 6, 9, 8, 9, 6],
221
+ [10, 1, 0, 10, 0, 6, 9, 5, 0, 5, 6, 0],
222
+ [0, 3, 8, 5, 6, 10],
223
+ [10, 5, 6],
224
+ [11, 5, 10, 7, 5, 11],
225
+ [11, 5, 10, 11, 7, 5, 8, 3, 0],
226
+ [5, 11, 7, 5, 10, 11, 1, 9, 0],
227
+ [10, 7, 5, 10, 11, 7, 9, 8, 1, 8, 3, 1],
228
+ [11, 1, 2, 11, 7, 1, 7, 5, 1],
229
+ [0, 8, 3, 1, 2, 7, 1, 7, 5, 7, 2, 11],
230
+ [9, 7, 5, 9, 2, 7, 9, 0, 2, 2, 11, 7],
231
+ [7, 5, 2, 7, 2, 11, 5, 9, 2, 3, 2, 8, 9, 8, 2],
232
+ [2, 5, 10, 2, 3, 5, 3, 7, 5],
233
+ [8, 2, 0, 8, 5, 2, 8, 7, 5, 10, 2, 5],
234
+ [9, 0, 1, 5, 10, 3, 5, 3, 7, 3, 10, 2],
235
+ [9, 8, 2, 9, 2, 1, 8, 7, 2, 10, 2, 5, 7, 5, 2],
236
+ [1, 3, 5, 3, 7, 5],
237
+ [0, 8, 7, 0, 7, 1, 1, 7, 5],
238
+ [9, 0, 3, 9, 3, 5, 5, 3, 7],
239
+ [9, 8, 7, 5, 9, 7],
240
+ [5, 8, 4, 5, 10, 8, 10, 11, 8],
241
+ [5, 0, 4, 5, 11, 0, 5, 10, 11, 11, 3, 0],
242
+ [0, 1, 9, 8, 4, 10, 8, 10, 11, 10, 4, 5],
243
+ [10, 11, 4, 10, 4, 5, 11, 3, 4, 9, 4, 1, 3, 1, 4],
244
+ [2, 5, 1, 2, 8, 5, 2, 11, 8, 4, 5, 8],
245
+ [0, 4, 11, 0, 11, 3, 4, 5, 11, 2, 11, 1, 5, 1, 11],
246
+ [0, 2, 5, 0, 5, 9, 2, 11, 5, 4, 5, 8, 11, 8, 5],
247
+ [9, 4, 5, 2, 11, 3],
248
+ [2, 5, 10, 3, 5, 2, 3, 4, 5, 3, 8, 4],
249
+ [5, 10, 2, 5, 2, 4, 4, 2, 0],
250
+ [3, 10, 2, 3, 5, 10, 3, 8, 5, 4, 5, 8, 0, 1, 9],
251
+ [5, 10, 2, 5, 2, 4, 1, 9, 2, 9, 4, 2],
252
+ [8, 4, 5, 8, 5, 3, 3, 5, 1],
253
+ [0, 4, 5, 1, 0, 5],
254
+ [8, 4, 5, 8, 5, 3, 9, 0, 5, 0, 3, 5],
255
+ [9, 4, 5],
256
+ [4, 11, 7, 4, 9, 11, 9, 10, 11],
257
+ [0, 8, 3, 4, 9, 7, 9, 11, 7, 9, 10, 11],
258
+ [1, 10, 11, 1, 11, 4, 1, 4, 0, 7, 4, 11],
259
+ [3, 1, 4, 3, 4, 8, 1, 10, 4, 7, 4, 11, 10, 11, 4],
260
+ [4, 11, 7, 9, 11, 4, 9, 2, 11, 9, 1, 2],
261
+ [9, 7, 4, 9, 11, 7, 9, 1, 11, 2, 11, 1, 0, 8, 3],
262
+ [11, 7, 4, 11, 4, 2, 2, 4, 0],
263
+ [11, 7, 4, 11, 4, 2, 8, 3, 4, 3, 2, 4],
264
+ [2, 9, 10, 2, 7, 9, 2, 3, 7, 7, 4, 9],
265
+ [9, 10, 7, 9, 7, 4, 10, 2, 7, 8, 7, 0, 2, 0, 7],
266
+ [3, 7, 10, 3, 10, 2, 7, 4, 10, 1, 10, 0, 4, 0, 10],
267
+ [1, 10, 2, 8, 7, 4],
268
+ [4, 9, 1, 4, 1, 7, 7, 1, 3],
269
+ [4, 9, 1, 4, 1, 7, 0, 8, 1, 8, 7, 1],
270
+ [4, 0, 3, 7, 4, 3],
271
+ [4, 8, 7],
272
+ [9, 10, 8, 10, 11, 8],
273
+ [3, 0, 9, 3, 9, 11, 11, 9, 10],
274
+ [0, 1, 10, 0, 10, 8, 8, 10, 11],
275
+ [3, 1, 10, 11, 3, 10],
276
+ [1, 2, 11, 1, 11, 9, 9, 11, 8],
277
+ [3, 0, 9, 3, 9, 11, 1, 2, 9, 2, 11, 9],
278
+ [0, 2, 11, 8, 0, 11],
279
+ [3, 2, 11],
280
+ [2, 3, 8, 2, 8, 10, 10, 8, 9],
281
+ [9, 10, 2, 0, 9, 2],
282
+ [2, 3, 8, 2, 8, 10, 0, 1, 8, 1, 10, 8],
283
+ [1, 10, 2],
284
+ [1, 3, 8, 9, 1, 8],
285
+ [0, 9, 1],
286
+ [0, 3, 8],
287
+ [],
288
+ ]
289
+
290
+ # mapping from 0-7 to v0-v7 in cube.vertices
291
+ INDEX = [0, 1, 5, 4, 2, 3, 7, 6]
project/ManiSkill3/src/maniskill2_benchmark/cfdp_experiment/cfdp/pytorch3d/tests/implicitron/common_resources.py ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ # All rights reserved.
3
+ #
4
+ # This source code is licensed under the BSD-style license found in the
5
+ # LICENSE file in the root directory of this source tree.
6
+
7
+ import contextlib
8
+ import logging
9
+ import os
10
+ import tempfile
11
+ import unittest
12
+ from pathlib import Path
13
+ from typing import Generator, Tuple
14
+ from zipfile import ZipFile
15
+
16
+ from iopath.common.file_io import PathManager
17
+
18
+
19
+ CO3D_MANIFOLD_PATH: str = "manifold://co3d/tree/extracted"
20
+ CO3DV2_MANIFOLD_PATH: str = "manifold://co3d/tree/v2/extracted"
21
+
22
+ INSIDE_RE_WORKER: bool = os.environ.get("INSIDE_RE_WORKER", False)
23
+
24
+
25
+ def get_path_manager(silence_logs: bool = False) -> PathManager:
26
+ """
27
+ Returns a path manager which can access manifold internally.
28
+
29
+ Args:
30
+ silence_logs: Whether to reduce log output from iopath library.
31
+ """
32
+ if silence_logs:
33
+ logging.getLogger("iopath.fb.manifold").setLevel(logging.CRITICAL)
34
+ logging.getLogger("iopath.common.file_io").setLevel(logging.CRITICAL)
35
+
36
+ if INSIDE_RE_WORKER:
37
+ raise ValueError("Cannot get to manifold from RE")
38
+
39
+ path_manager = PathManager()
40
+
41
+ if os.environ.get("FB_TEST", False):
42
+ from iopath.fb.manifold import ManifoldPathHandler
43
+
44
+ path_manager.register_handler(ManifoldPathHandler())
45
+
46
+ return path_manager
47
+
48
+
49
+ @contextlib.contextmanager
50
+ def get_skateboard_data(
51
+ avoid_manifold: bool = False, silence_logs: bool = False
52
+ ) -> Generator[Tuple[str, PathManager], None, None]:
53
+ """
54
+ Context manager for accessing Co3D dataset by tests, at least for
55
+ the first 5 skateboards. Internally, we want this to exercise the
56
+ normal way to access the data directly manifold, but on an RE
57
+ worker this is impossible so we use a workaround.
58
+
59
+ Args:
60
+ avoid_manifold: Use the method used by RE workers even locally.
61
+ silence_logs: Whether to reduce log output from iopath library.
62
+
63
+ Yields:
64
+ dataset_root: (str) path to dataset root.
65
+ path_manager: path_manager to access it with.
66
+ """
67
+ if silence_logs:
68
+ logging.getLogger("iopath.fb.manifold").setLevel(logging.CRITICAL)
69
+ logging.getLogger("iopath.common.file_io").setLevel(logging.CRITICAL)
70
+
71
+ if not os.environ.get("FB_TEST", False):
72
+ if os.getenv("FAIR_ENV_CLUSTER", "") == "":
73
+ raise unittest.SkipTest("Unknown environment. Data not available.")
74
+ yield "/datasets01/co3d/081922", PathManager()
75
+
76
+ elif avoid_manifold or INSIDE_RE_WORKER:
77
+ from libfb.py.parutil import get_file_path
78
+
79
+ par_path = "skateboard_first_5"
80
+ source = get_file_path(par_path)
81
+ assert Path(source).is_file()
82
+ with tempfile.TemporaryDirectory() as dest:
83
+ with ZipFile(source) as f:
84
+ f.extractall(dest)
85
+ yield os.path.join(dest, "extracted"), PathManager()
86
+ else:
87
+ yield CO3D_MANIFOLD_PATH, get_path_manager()
88
+
89
+
90
+ def _provide_torchvision_weights(par_path: str, filename: str) -> None:
91
+ """
92
+ Ensure the weights files are available for a torchvision model.
93
+ """
94
+ # In OSS, torchvision looks for vgg16 weights in
95
+ # https://download.pytorch.org/models/vgg16-397923af.pth
96
+ # Inside fbcode, this is replaced by asking iopath for
97
+ # manifold://torchvision/tree/models/vgg16-397923af.pth
98
+ # (the code for this replacement is in
99
+ # fbcode/pytorch/vision/fb/_internally_replaced_utils.py )
100
+ #
101
+ # iopath does this by looking for the file at the cache location
102
+ # and if it is not there getting it from manifold.
103
+ # (the code for this is in
104
+ # fbcode/fair_infra/data/iopath/iopath/fb/manifold.py )
105
+ #
106
+ # On the remote execution worker, manifold is inaccessible.
107
+ # We solve this by making the cached file available before iopath
108
+ # looks.
109
+ #
110
+ # By default the cache location is
111
+ # ~/.torch/iopath_cache/manifold_cache/tree/models/vgg16-397923af.pth
112
+ # But we can't write to the home directory on the RE worker.
113
+ # We define FVCORE_CACHE to change the cache location to
114
+ # iopath_cache/manifold_cache/tree/models/vgg16-397923af.pth
115
+ # (Without it, manifold caches in unstable temporary locations on RE.)
116
+ #
117
+ # The file we want has been copied from
118
+ # tree/models/vgg16-397923af.pth in the torchvision bucket
119
+ # to
120
+ # tree/testing/vgg16-397923af.pth in the co3d bucket
121
+ # and the TARGETS file copies it somewhere in the PAR which we
122
+ # recover with get_file_path.
123
+ # (It can't copy straight to a nested location, see
124
+ # https://fb.workplace.com/groups/askbuck/posts/2644615728920359/)
125
+ # Here we symlink it to the new cache location.
126
+ if INSIDE_RE_WORKER:
127
+ from libfb.py.parutil import get_file_path
128
+
129
+ os.environ["FVCORE_CACHE"] = "iopath_cache"
130
+
131
+ source = Path(get_file_path(par_path))
132
+ assert source.is_file()
133
+
134
+ dest = Path("iopath_cache/manifold_cache/tree/models")
135
+ if not dest.exists():
136
+ dest.mkdir(parents=True)
137
+
138
+ if not (dest / filename).is_symlink():
139
+ try:
140
+ (dest / filename).symlink_to(source)
141
+ except FileExistsError:
142
+ print("FileExistsError: no symlink created.")
143
+
144
+
145
+ def provide_lpips_vgg() -> None:
146
+ """
147
+ Ensure the weights files are available for lpips.LPIPS(net="vgg")
148
+ to be called. Specifically, torchvision's vgg16.
149
+ """
150
+ _provide_torchvision_weights("vgg_weights_for_lpips", "vgg16-397923af.pth")
151
+
152
+
153
+ def provide_resnet34() -> None:
154
+ """
155
+ Ensure the weights files are available for
156
+
157
+ torchvision.models.resnet34(pretrained=True)
158
+
159
+ to be called.
160
+ """
161
+ _provide_torchvision_weights("resnet34_weights", "resnet34-b627a593.pth")