Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor precision fix on unproject #1471

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

idilsulo
Copy link

@idilsulo idilsulo commented Mar 6, 2023

Hi! I found a minor issue inside the code sample given for the unproject inside CameraBase.

The provided code block returns True as expected only when the camera is set without any Rotation R or Transformation T.

An example is given below:

torch.set_printoptions(precision=10)

xyz = # 3D points of shape (batch_size, num_points, 3)

R, T = look_at_view_transform(160, 180, 270)
cameras = FoVOrthographicCameras(device=device, R=R, T=T, znear=0.01)

# transform xyz to the camera view coordinates
xyz_cam = cameras.get_world_to_view_transform().transform_points(xyz)
# xyz_cam = cameras.get_full_projection_transform().transform_points(xyz)

# extract the depth of each point as the 3rd coord of xyz_cam
depth = xyz_cam[:, :, 2:]

# project the points xyz to the camera
xy = cameras.transform_points(xyz)[:, :, :2]

# append depth to xy
xy_depth = torch.cat((xy, depth), dim=2)

# unproject to the world coordinates
xyz_unproj_world = cameras.unproject_points(xy_depth, world_coordinates=True, from_ndc=True)

print(xyz)                           # Original set of 3D points
print(xyz_unproj_world)   # Unproject almost identical, except slight precision difference

print(torch.allclose(xyz, xyz_unproj_world)) # Expected: True - Returns: False

I at first thought that R and T were not being considered during unprojection, only to realize afterwards that the print statement above in this case returns False due to precision error.

Changing this line by increasing the absolute threshold atol as also done in the unit tests solves the issue:

self.assertTrue(torch.allclose(xyz_unproj, matching_xyz, atol=1e-4))

Thanks a lot!

@facebook-github-bot
Copy link
Contributor

Hi @idilsulo!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 6, 2023
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

2 similar comments
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot
Copy link
Contributor

@bottler has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@idilsulo has updated the pull request. You must reimport the pull request before landing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants