30 Commits

Author SHA1 Message Date
Amethyst Reese
3da7703c5a apply Black 2024 style in fbcode (4/16)
Summary:
Formats the covered files with pyfmt.

paintitblack

Reviewed By: aleivag

Differential Revision: D54447727

fbshipit-source-id: 8844b1caa08de94d04ac4df3c768dbf8c865fd2f
2024-03-02 17:31:19 -08:00
Jeremy Reizenstein
83bacda8fb lint
Summary: Fix recent flake complaints

Reviewed By: MichaelRamamonjisoa

Differential Revision: D51811912

fbshipit-source-id: 65183f5bc7058da910e4d5a63b2250ce8637f1cc
2023-12-04 13:43:34 -08:00
generatedunixname89002005287564
33b49cebf0 fbcode//vision/fair/pytorch3d
Reviewed By: bottler

Differential Revision: D43432438

fbshipit-source-id: 58159b2febb67febb533511eb2d1f47d40dad032
2023-02-20 07:19:15 -08:00
Jeremy Reizenstein
34f648ede0 move targets
Summary: Move testing targets from pytorch3d/tests/TARGETS to pytorch3d/TARGETS.

Reviewed By: shapovalov

Differential Revision: D36186940

fbshipit-source-id: a4c52c4d99351f885e2b0bf870532d530324039b
2022-05-25 06:16:03 -07:00
Krzysztof Chalupka
050f650ae8 Submesh 3/n: Add submeshing functionality
Summary:
Copypasting the docstring:
```
        Split a mesh into submeshes, defined by face indices of the original Meshes object.

        Args:
          face_indices:
            Let the original mesh have verts_list() of length N.
            Can be either
              - List of length N. The n-th element is a list of length num_submeshes_n
                (empty lists are allowed). Each element of the n-th sublist is a LongTensor
                of length num_faces.
              - List of length N. The n-th element is a possibly empty padded LongTensor of
                shape (num_submeshes_n, max_num_faces).

        Returns:
          Meshes object with selected submeshes. The submesh tensors are cloned.

        Currently submeshing only works with no textures or with the TexturesVertex texture.

        Example:

        Take a Meshes object `cubes` with 4 meshes, each a translated cube. Then:
            * len(cubes) is 4, len(cubes.verts_list()) is 4, len(cubes.faces_list()) is 4,
            * [cube_verts.size for cube_verts in cubes.verts_list()] is [8, 8, 8, 8],
            * [cube_faces.size for cube_faces in cubes.faces_list()] if [6, 6, 6, 6],

        Now let front_facet, top_and_bottom, all_facets be LongTensors of
        sizes (2), (4), and (12), each picking up a number of facets of a cube by specifying
        the appropriate triangular faces.

        Then let `subcubes = cubes.submeshes([[front_facet, top_and_bottom], [], [all_facets], []])`.
            * len(subcubes) is 3.
            * subcubes[0] is the front facet of the cube contained in cubes[0].
            * subcubes[1] is a mesh containing the (disconnected) top and bottom facets of cubes[0].
            * subcubes[2] is a clone of cubes[2].
            * There are no submeshes of cubes[1] and cubes[3] in subcubes.
            * subcubes[0] and subcubes[1] are not watertight. subcubes[2] is.
```

Reviewed By: bottler

Differential Revision: D35440657

fbshipit-source-id: 8a6d2d300ce226b5b9eb440688528b5e795195a1
2022-04-11 16:27:53 -07:00
Krzysztof Chalupka
8596fcacd2 Submesh 2/n: to_sorted
Summary:
Sort a mesh's vertices in alphabetical order, and resort the face coords accordingly. Textured meshes are not supported yet, but will be added down the stack.

This, togehter with mesh equality, can be used to compare two meshes in a way invariant to vertex permutations, as shown in the unit tests.

We do not want the submeshing mechanism to guarantee any particular vertex order, leaving that up to the implementation, so we need this function for testing.

Reviewed By: bottler

Differential Revision: D35440656

fbshipit-source-id: 5a4dd921fdb00625a33da08b5fea79e20ac6402c
2022-04-11 16:27:53 -07:00
Krzysztof Chalupka
7f097b064b Submesh 1/n: Implement mesh equality
Summary: Adding a mesh equality operator. Two Meshes objects m1, m2 are equal iff their vertex lists, face lists, and normals lists are equal. Textures meshes are not supported yet, but will be added for vertex textures down the stack.

Reviewed By: bottler, nikhilaravi

Differential Revision: D35440655

fbshipit-source-id: 69974a59c091416afdb2892896859a189f5ebf3a
2022-04-11 16:27:53 -07:00
Krzysztof Chalupka
aab95575a6 Submesh 0/n: Default to empty Meshes
Summary:
The default behavior of Meshes (with verts=None, faces=None) throws an exception:
```
meshes = Meshes()
> ValueError: Verts and Faces must be either a list or a tensor with shape (batch_size, N, 3) where N is either the maximum number of verts or faces respectively.
```

Instead, let's default to an empty mesh, following e.g. PyTorch:
```
empty_tensor = torch.FloatTensor()
> torch.tensor([])
```

this change is backwards-compatible (you can still init with verts=[], faces=[]).

Reviewed By: bottler, nikhilaravi

Differential Revision: D35443453

fbshipit-source-id: d638a8fef49a089bf0da6dd2201727b94ceb21ec
2022-04-11 16:27:53 -07:00
Jeremy Reizenstein
9eeb456e82 Update license for company name
Summary: Update all FB license strings to the new format.

Reviewed By: patricklabatut

Differential Revision: D33403538

fbshipit-source-id: 97a4596c5c888f3c54f44456dc07e718a387a02c
2022-01-04 11:43:38 -08:00
Roman Shapovalov
0c02ae907e Adding utility methods to TensorProperties
Summary:
Context: in the code we are releasing with CO3D dataset, we use  `cuda()` on TensorProperties like Pointclouds and Cameras where we recursively move batch to a GPU. It would be good to push it to a release so we don’t need to depend on the nightly build.

Additionally, I aligned the logic of `.to("cuda")` without device index to the one of `torch.Tensor` where the current device is populated to index. It should not affect any actual use cases but some tests had to be changed.

Reviewed By: bottler

Differential Revision: D29659529

fbshipit-source-id: abe58aeaca14bacc68da3e6cf5ae07df3353e3ce
2021-07-13 10:29:26 -07:00
Georgia Gkioxari
07a5a68d50 refactor laplacian matrices
Summary:
Refactor of all functions to compute laplacian matrices in one file.
Support for:
* Standard Laplacian
* Cotangent Laplacian
* Norm Laplacian

Reviewed By: nikhilaravi

Differential Revision: D29297466

fbshipit-source-id: b96b88915ce8ef0c2f5693ec9b179fd27b70abf9
2021-06-24 03:53:21 -07:00
Patrick Labatut
af93f34834 License lint codebase
Summary: License lint codebase

Reviewed By: theschnitz

Differential Revision: D29001799

fbshipit-source-id: 5c59869911785b0181b1663bbf430bc8b7fb2909
2021-06-22 03:45:27 -07:00
Patrick Labatut
633d66f1f0 Tidy uses of torch.device in Meshes
Summary:
Tidy uses of `torch.device` in `Meshes`:
- Allow `str` or `torch.device` in `Meshes.to()` method
- Consistently use `torch.device` for internal type
- Fix comparison of devices

Reviewed By: nikhilaravi

Differential Revision: D28969461

fbshipit-source-id: 16d3c1f5458954bb11fdf0efea88542e94dccd7a
2021-06-09 15:50:09 -07:00
Jeremy Reizenstein
0ca839cc32 avoid running tests twice
Summary: Avoid test files explicitly importing TestCase objects from each other, because doing so causes the tests to be discovered twice by unittest discover. This means moving a few static functions out of their classes. I noticed this while trying to fix failures from yesterday.

Reviewed By: nikhilaravi

Differential Revision: D28194679

fbshipit-source-id: ac6e6585603bd4ef9c098cdd56891d94f8923ba6
2021-05-07 05:04:08 -07:00
Jeremy Reizenstein
e3624b4e9d test_meshes numeric fixes
Summary:
A couple of tests are failing in open source after my changes yesterday because of numerical issues calculating normals. In particular we have meshes with very few vertices and several faces, where the normals should be zero but end up non-negligible after F.normalize. I have no idea why the different environments produce different results, so that the tests are passing internally.

An example. Consider a mesh with the following faces:
```
tensor([[4, 0, 2],
        [4, 1, 2],
        [3, 1, 0],
        [1, 3, 1],
        [3, 0, 1],
        [4, 0, 0],
        [4, 0, 2]])
```
At vertex 3, there is one zero-area face and there are two other faces, which are back-to-back with each other. This vertex should have zero normal. The open source calculation produces a small but nonzero normal which varies unpredictably with changes in scale/offset, which can cause test failures.

In this diff, the main change is to increase the number of vertices to make this less likely to happen. Also a small change to init_mesh to make it not generate a batch of empty meshes.

Reviewed By: nikhilaravi

Differential Revision: D28220984

fbshipit-source-id: 79fdc62e5f5f8836de5a3a9980cfd6fe44590359
2021-05-07 05:04:08 -07:00
Jeremy Reizenstein
66b97a0c28 has_verts_normals for Meshes
Summary: Add ability to ask a Meshes if it already has normals. If it does, then requesting normals will not trigger a calculation. MeshesFormatInterpreters will therefore be able to decide whether to save normals.

Reviewed By: theschnitz, nikhilaravi

Differential Revision: D27765261

fbshipit-source-id: 7c87dbf999d5616d20f5eb2c01039ee5ff65a830
2021-05-04 05:36:51 -07:00
Jeremy Reizenstein
2bbca5f2a7 Allow setting verts_normals on Meshes
Summary: Add ability to set the vertex normals when creating a Meshes, so that the pluggable loaders can return them from a file.

Reviewed By: nikhilaravi

Differential Revision: D27765258

fbshipit-source-id: b5ddaa00de3707f636f94d9f74d1da12ecce0608
2021-05-04 05:36:51 -07:00
Jeremy Reizenstein
502f15aca7 avoid recalculating normals for simple move
Summary: If offset_verts_ is used to move meshes with a single vector, the normals won't change so don't need to recalculate. I am planning to allow user-specified vertex normals. This change means that user-specified vertex normals won't get overwritten when they don't need to be.

Reviewed By: nikhilaravi

Differential Revision: D27765256

fbshipit-source-id: f6e4d308ac9ac023030325cb75a18d39b966cf88
2021-05-04 05:36:51 -07:00
Jeremy Reizenstein
ddebdfbcd7 Allow single offset in offset_verts
Summary:
It is common when trying things out to want to move a whole mesh or point cloud by the same amount. Here we allow the offset functions to broadcast.

Also add a sanity check to join_meshes_as_scene which it is easy to call wrongly.

Reviewed By: nikhilaravi

Differential Revision: D25980593

fbshipit-source-id: cdf1568e1317e3b81ad94ed4e608ba7eef81290b
2021-01-22 07:33:31 -08:00
Evgeniy Zheltonozhskiy
569e5229a9 Add check for verts and faces being on same device and also checks for pointclouds/features/normals being on the same device (#384)
Summary: Pull Request resolved: https://github.com/facebookresearch/pytorch3d/pull/384

Test Plan: `test_meshes` and `test_points`

Reviewed By: gkioxari

Differential Revision: D24730524

Pulled By: nikhilaravi

fbshipit-source-id: acbd35be5d9f1b13b4d56f3db14f6e8c2c0f7596
2020-12-14 16:18:19 -08:00
Jeremy Reizenstein
e25ccab3d9 align_corners and padding for TexturesUV
Summary:
Allow, and make default, align_corners=True for texture maps. Allow changing the padding_mode and set the default to be "border" which produces more logical results. Some new documentation.

The previous behavior corresponds to padding_mode="zeros" and align_corners=False.

Reviewed By: gkioxari

Differential Revision: D23268775

fbshipit-source-id: 58d6229baa591baa69705bcf97471c80ba3651de
2020-08-25 11:28:40 -07:00
Georgia Gkioxari
7f2f95f225 detach for meshes, pointclouds, textures
Summary: Add `detach` for Meshes, Pointclouds, Textures

Reviewed By: nikhilaravi

Differential Revision: D23070418

fbshipit-source-id: 68671124ce114c4495d7ef3c944c9aac3d0db2d8
2020-08-17 14:55:54 -07:00
Georgia Gkioxari
2f0fd60186 fix pts scale, save ply
Summary:
Fix:
* Scaling of point clouds for scalars
* save_ply compatible cat

Reviewed By: nikhilaravi

Differential Revision: D22298609

fbshipit-source-id: abe94a5b64baf325587202d20adfc36912cc1478
2020-07-03 10:21:12 -07:00
Georgia Gkioxari
1fb97f9c84 update padded in meshes
Summary:
Three changes to Meshes

1. `num_verts_per_mesh` and `num_faces_per_mesh` are assigned at construction time and are returned without the need for `compute_packed`
2. `update_padded` updates `verts_padded` and shallow copies faces list and faces_padded and existing attributes from construction.
3. `padded_to_packed_idx` does not need `compute_packed`

Reviewed By: nikhilaravi

Differential Revision: D21653674

fbshipit-source-id: dc6815a2e2a925fe4a834fe357919da2b2c14527
2020-05-22 22:38:29 -07:00
Georgia Gkioxari
487d4d6607 point mesh distances
Summary:
Implementation of point to mesh distances. The current diff contains two types:
(a) Point to Edge
(b) Point to Face

```

Benchmark                                       Avg Time(μs)      Peak Time(μs) Iterations
--------------------------------------------------------------------------------
POINT_MESH_EDGE_4_100_300_5000_cuda:0                2745            3138            183
POINT_MESH_EDGE_4_100_300_10000_cuda:0               4408            4499            114
POINT_MESH_EDGE_4_100_3000_5000_cuda:0               4978            5070            101
POINT_MESH_EDGE_4_100_3000_10000_cuda:0              9076            9187             56
POINT_MESH_EDGE_4_1000_300_5000_cuda:0               1411            1487            355
POINT_MESH_EDGE_4_1000_300_10000_cuda:0              4829            5030            104
POINT_MESH_EDGE_4_1000_3000_5000_cuda:0              7539            7620             67
POINT_MESH_EDGE_4_1000_3000_10000_cuda:0            12088           12272             42
POINT_MESH_EDGE_8_100_300_5000_cuda:0                3106            3222            161
POINT_MESH_EDGE_8_100_300_10000_cuda:0               8561            8648             59
POINT_MESH_EDGE_8_100_3000_5000_cuda:0               6932            7021             73
POINT_MESH_EDGE_8_100_3000_10000_cuda:0             24032           24176             21
POINT_MESH_EDGE_8_1000_300_5000_cuda:0               5272            5399             95
POINT_MESH_EDGE_8_1000_300_10000_cuda:0             11348           11430             45
POINT_MESH_EDGE_8_1000_3000_5000_cuda:0             17478           17683             29
POINT_MESH_EDGE_8_1000_3000_10000_cuda:0            25961           26236             20
POINT_MESH_EDGE_16_100_300_5000_cuda:0               8244            8323             61
POINT_MESH_EDGE_16_100_300_10000_cuda:0             18018           18071             28
POINT_MESH_EDGE_16_100_3000_5000_cuda:0             19428           19544             26
POINT_MESH_EDGE_16_100_3000_10000_cuda:0            44967           45135             12
POINT_MESH_EDGE_16_1000_300_5000_cuda:0              7825            7937             64
POINT_MESH_EDGE_16_1000_300_10000_cuda:0            18504           18571             28
POINT_MESH_EDGE_16_1000_3000_5000_cuda:0            65805           66132              8
POINT_MESH_EDGE_16_1000_3000_10000_cuda:0           90885           91089              6
--------------------------------------------------------------------------------

Benchmark                                       Avg Time(μs)      Peak Time(μs) Iterations
--------------------------------------------------------------------------------
POINT_MESH_FACE_4_100_300_5000_cuda:0                1561            1685            321
POINT_MESH_FACE_4_100_300_10000_cuda:0               2818            2954            178
POINT_MESH_FACE_4_100_3000_5000_cuda:0              15893           16018             32
POINT_MESH_FACE_4_100_3000_10000_cuda:0             16350           16439             31
POINT_MESH_FACE_4_1000_300_5000_cuda:0               3179            3278            158
POINT_MESH_FACE_4_1000_300_10000_cuda:0              2353            2436            213
POINT_MESH_FACE_4_1000_3000_5000_cuda:0             16262           16336             31
POINT_MESH_FACE_4_1000_3000_10000_cuda:0             9334            9448             54
POINT_MESH_FACE_8_100_300_5000_cuda:0                4377            4493            115
POINT_MESH_FACE_8_100_300_10000_cuda:0               9728            9822             52
POINT_MESH_FACE_8_100_3000_5000_cuda:0              26428           26544             19
POINT_MESH_FACE_8_100_3000_10000_cuda:0             42238           43031             12
POINT_MESH_FACE_8_1000_300_5000_cuda:0               3891            3982            129
POINT_MESH_FACE_8_1000_300_10000_cuda:0              5363            5429             94
POINT_MESH_FACE_8_1000_3000_5000_cuda:0             20998           21084             24
POINT_MESH_FACE_8_1000_3000_10000_cuda:0            39711           39897             13
POINT_MESH_FACE_16_100_300_5000_cuda:0               5955            6001             84
POINT_MESH_FACE_16_100_300_10000_cuda:0             12082           12144             42
POINT_MESH_FACE_16_100_3000_5000_cuda:0             44996           45176             12
POINT_MESH_FACE_16_100_3000_10000_cuda:0            73042           73197              7
POINT_MESH_FACE_16_1000_300_5000_cuda:0              8292            8374             61
POINT_MESH_FACE_16_1000_300_10000_cuda:0            19442           19506             26
POINT_MESH_FACE_16_1000_3000_5000_cuda:0            36059           36194             14
POINT_MESH_FACE_16_1000_3000_10000_cuda:0           64644           64822              8
--------------------------------------------------------------------------------
```

Reviewed By: jcjohnson

Differential Revision: D20590462

fbshipit-source-id: 42a39837b514a546ac9471bfaff60eefe7fae829
2020-04-11 00:21:24 -07:00
Patrick Labatut
d57daa6f85 Address black + isort fbsource linter warnings
Summary: Address black + isort fbsource linter warnings from D20558374 (previous diff)

Reviewed By: nikhilaravi

Differential Revision: D20558373

fbshipit-source-id: d3607de4a01fb24c0d5269634563a7914bddf1c8
2020-03-29 14:51:02 -07:00
Jeremy Reizenstein
595aca27ea use assertClose
Summary: use assertClose in some tests, which enforces shape equality. Fixes some small problems, including graph_conv on an empty graph.

Reviewed By: nikhilaravi

Differential Revision: D20556912

fbshipit-source-id: 60a61eafe3c03ce0f6c9c1a842685708fb10ac5b
2020-03-23 11:36:38 -07:00
Nikhila Ravi
5d3cc3569a Rendering texturing fixes
Summary:
Fix errors raised by issue on GitHub - extending mesh textures + rendering with Gourad and Phong shaders.

https://github.com/facebookresearch/pytorch3d/issues/97

Reviewed By: gkioxari

Differential Revision: D20319610

fbshipit-source-id: d1c692ff0b9397a77a9b829c5c731790de70c09f
2020-03-17 08:58:40 -07:00
Patrick Labatut
3c71ab64cc Remove shebang line when not strictly required
Summary: The shebang line `#!<path to interpreter>` is only required for Python scripts, so remove it on source files for class or function definitions. Additionally explicitly mark as executable the actual Python scripts in the codebase.

Reviewed By: nikhilaravi

Differential Revision: D20095778

fbshipit-source-id: d312599fba485e978a243292f88a180d71e1b55a
2020-03-12 10:39:44 -07:00
facebook-github-bot
dbf06b504b Initial commit
fbshipit-source-id: ad58e416e3ceeca85fae0583308968d04e78fe0d
2020-01-23 11:53:46 -08:00