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

Redwood noisy depth #189

Merged
merged 47 commits into from
Nov 7, 2019
Merged

Redwood noisy depth #189

merged 47 commits into from
Nov 7, 2019

Conversation

erikwijmans
Copy link
Contributor

@erikwijmans erikwijmans commented Sep 4, 2019

Motivation and Context

Adds the noise model from here: http://redwood-data.org/indoor/dataset.html

There are 2 implementations:

@msavva @bigbike @mosra What are your thoughts on how I am currently providing arguments to the sensor noise models? I just added a py::dict to the python binding of the sensor spec so that people can pass arbitrary arguments in it.

TODO

  • Doc strings
  • License headers
  • Add citations
  • Figure out how to get the args for constructing noise models -- @mosra's suggestion to have a python only property seems to be a nice middle ground between PySensorSpec and just doing py::dynamic_attr()
  • Switch to a proper registry pattern in a different PR and use that here -- Registry #204
  • Remove the tmp.py file. That has just been useful for testing :)

How Has This Been Tested

Via the tests and visually!

redwood_depth

depth

Types of changes

  • New feature (non-breaking change which adds functionality)

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Sep 4, 2019
@dhruvbatra
Copy link
Contributor

A CUDA implementation that runs at ~5k FPS at 256x256 or ~200k FPS at 256x256 when using the GPU->GPU transfer from #114 !

200k?!! Damn.

Are those two images w/ and w/o noise?

Request -- is it easy to show images with varying levels of noise? (Or is that not feasible for this noise type?)

@erikwijmans
Copy link
Contributor Author

Are those two images w/ and w/o noise?

Yes they are :)

Request -- is it easy to show images with varying levels of noise? (Or is that not feasible for this noise type?)

We could make that doable with this noise model. There are two different Gaussian that are sampled from and I could make the variance on those changeable.

@erikwijmans
Copy link
Contributor Author

redwood_depth

redwood_depth
redwood_depth

redwood_depth

I add a simple multiplier parameter which I just multiply both the standard deviations by. Above is 2x, 3x, 4x, 5x. Seems to fairly smoothly make things worse.

@mathfac mathfac added this to the Realistic noise models milestone Sep 5, 2019
@erikwijmans erikwijmans mentioned this pull request Sep 11, 2019
@erikwijmans erikwijmans marked this pull request as ready for review October 4, 2019 21:40
@erikwijmans erikwijmans requested a review from mosra October 4, 2019 21:40
@erikwijmans erikwijmans changed the title [WIP] Redwood noisy depth Redwood noisy depth Oct 5, 2019
@erikwijmans
Copy link
Contributor Author

This is ready for review.

Copy link
Contributor

@mathfac mathfac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's really important step towards sim2real direction. Reviewed all the PR except details of redwood noise model implementations. Noise model registration pattern looks appealing.
Thank you for creating both CPU & GPU versions. Overall looks good to go, some minor comments.

def is_valid_sensor_type(sensor_type):
return True

def apply(self, x):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this Noise Model that is producing copying? maybe we can just miss applying any noise model if it wasn't specified.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had a copy before-hand, so I just rolled the copy into this as it felt cleaner to always apply a noise model and have a no-noise model which just returns a copy.

else:
# Distort
undistorted_d = _undistort(
int(x / xmax * 639.0 + 0.5), int(y / ymax * 479.0 + 0.5), d, model
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is a meaning behind all the constants in this method., let's give them reasonable names. That can help to adopt noise for specific camera type/sim2real setup later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

480x640 is the resolution of the sensor used to create the distortion model originally. This logic just rescales any given observation to 480x640 so that it can query the distortion model.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding a brief comment to this effect in the code would be helpful for readability

habitat_sim/sensors/noise_models/sensor_noise_model.py Outdated Show resolved Hide resolved
pass

@abc.abstractmethod
def apply(self, sensor_observation):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def apply(self, sensor_observation):
def apply(self, sensor_observation) -> Observations:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe we have a generic Observations type currently defined.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we expose to python and flesh out Observation from the C++ side? (Bringing this up here, but it likely makes sense to create a separate issue & PR for that)

@@ -391,7 +398,7 @@ def get_observation(self):
else:
tgt.read_frame_rgba_gpu(self._buffer.data_ptr())

return self._buffer.flip(0).clone()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, you moved copying logic to NoNoise. Still will copying/cloning be valid for all types of sensors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all visual sensors, yes. This current sensor class is really for just visual sensors. When we introduce other sensors, I would imagine those will have their own separate python wrapper.

setup.py Show resolved Hide resolved
src/esp/sensor/RedwoodNoiseModel.cpp Outdated Show resolved Hide resolved
src/esp/sensor/RedwoodNoiseModel.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@msavva msavva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome to see sensor noise models coming in! 👍LGTM in general, left a few minor comments about typos and readability.


.. py:function:: habitat_sim.sensors.noise_models.RedwoodDepthNoiseModel.__init__
:param gpu_device_id: The ID of CUDA device to use (only applicable if habitat-sim was built with ``--with-cuda``)
:param noise_multiplier: Multipler for the Guassian random-variables. This reduces or increase the amount of noise
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo Guassian -> Gaussian; increase -> increases

r"""Retrieve the move_fn register under ``name``

:param name: The name provided to `register_move_fn`
"""
return cls._get_impl("move_fn", name)

@classmethod
def get_noise_model(cls, name: str):
r"""Retrieve the noise_model register under ``name``
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: register -> registered

def apply(self, x):
if isinstance(x, np.ndarray):
return x.copy()
else:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check for cases where x has a type with no clone() defined? e.g. scalar-valued sensors

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a check to see if x is a torch tensor.



@numba.jit(nopython=True)
def _undistort(x, y, z, model):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it would be nice to have a succinct comment describing the undistortion model being used (or at least a pointer to the original description of this in Redwood). This will help others to understand the variable names below.

else:
# Distort
undistorted_d = _undistort(
int(x / xmax * 639.0 + 0.5), int(y / ymax * 479.0 + 0.5), d, model
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding a brief comment to this effect in the code would be helpful for readability

pass

@abc.abstractmethod
def apply(self, sensor_observation):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we expose to python and flesh out Observation from the C++ side? (Bringing this up here, but it likely makes sense to create a separate issue & PR for that)

const int MODEL_N_DIMS = 5;
const int MODEL_N_COLS = 80;

__device__ float undistort(const int _x,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comment as above regarding a quick pointer to aid readability of the implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the link, http://www.alexteichman.com/octo/clams/ but that doesn't really help the implementation read-ability. I just took the code from here: http://redwood-data.org/indoor/data/simdepth.py and made it not slow.

* @brief Constructor
* @param model The distortion model from
* http://redwood-data.org/indoor/data/dist-model.txt
* The 3rd dimensions is assumed to have been
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: dimensions -> dimension


/**
* @brief Simulates noisy depth from clean depth. The input is assumed to be
* on the CPU and the output will be on the CPU
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add: what happens if assumption does not hold?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad things happen. Segfaults happen :)


/**
* @brief Similar to @ref simulateFromCPU() but the input and output are
* assumed to be on the GPU
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add: what happens if assumption does not hold?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad things happen. Segfaults happen :)

@erikwijmans erikwijmans merged commit e4afe2c into master Nov 7, 2019
@erikwijmans erikwijmans deleted the redwood-noisy-depth branch November 7, 2019 18:04
Ram81 pushed a commit to Ram81/habitat-web-sim that referenced this pull request Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants