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

Feature: Adding Surface Normals Sensor #24

Open
mathfac opened this issue Apr 3, 2019 · 3 comments
Open

Feature: Adding Surface Normals Sensor #24

mathfac opened this issue Apr 3, 2019 · 3 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@mathfac
Copy link
Contributor

mathfac commented Apr 3, 2019

Author @danielgordon10:
I have code to turn depth into surface normals, but ideally it should be something provided by habitat-api directly.

Here is my surface normals code. One nice thing about it is I can batch it and run on GPU, though you should at least be able to do the second part on habitat-sim side if necessary.

import torch
import torch.nn.functional as F

surfnorm_kernel = None
def depth_to_surface_normals(depth, surfnorm_scalar=256):
# depth is torch tensor in N x C x H x W order.
global surfnorm_kernel
if surfnorm_kernel is None:
surfnorm_kernel = torch.from_numpy(
np.array([[[1, 2, 1],
[0, 0, 0],
[-1, -2, -1]],
[[1, 0, -1],
[2, 0, -2],
[1, 0, -1]],
[[0, 0, 0],
[0, 0, 0],
[0, 0, 0]]])
)[:, np.newaxis, ...].to(
dtype=torch.float32, device=depth.device)
with torch.no_grad():
surface_normals = F.conv2d(depth, surfnorm_scalar * surfnorm_kernel, padding=1)
surface_normals[:, 2, ...] = 1
surface_normals = surface_normals / surface_normals.norm(dim=1, keepdim=True)
return surface_normals

@mathfac mathfac added the enhancement New feature or request label Apr 3, 2019
@danielgordon10
Copy link
Contributor

Formatting:
I have code to turn depth into surface normals, but ideally it should be something provided by habitat-api directly.

Here is my surface normals code. One nice thing about it is I can batch it and run on GPU, though you should at least be able to do the second part on habitat-sim side if necessary.

import torch
import torch.nn.functional as F

surfnorm_kernel = None
def depth_to_surface_normals(depth, surfnorm_scalar=256):
    # depth is torch tensor in N x C x H x W order.
    global surfnorm_kernel
    if surfnorm_kernel is None:
    surfnorm_kernel = torch.from_numpy(
        np.array([[
            [1, 2, 1],
            [0, 0, 0],
            [-1, -2, -1]],
           [[1, 0, -1],
            [2, 0, -2],
            [1, 0, -1]],
           [[0, 0, 0],
            [0, 0, 0],
            [0, 0, 0]]])
             )[:, np.newaxis, ...].to(dtype=torch.float32, device=depth.device)
    with torch.no_grad():
        surface_normals = F.conv2d(depth, surfnorm_scalar * surfnorm_kernel, padding=1)
        surface_normals[:, 2, ...] = 1
        surface_normals = surface_normals / surface_normals.norm(dim=1, keepdim=True)
        return surface_normals

@mathfac mathfac added the good first issue Good for newcomers label Jun 14, 2019
mathfac pushed a commit that referenced this issue May 6, 2020
* Update submission pipeline for 2020

* Update Dockerfile

* Update dockerfile

* Pointnav, ObjectNav dockers

* Add dockerignore
@Yash621
Copy link

Yash621 commented Nov 5, 2021

@mathfac can I work on this ?

@mathfac
Copy link
Contributor Author

mathfac commented Nov 10, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants