habitat-sim
habitat-sim copied to clipboard
Inconsistent depth information
Habitat-Sim version
v0.2.2
Docs and Tutorials
Did you read the docs? https://aihabitat.org/docs/habitat-sim/ Yes Did you check out the tutorials? https://aihabitat.org/tutorial/2020/ Yes Perhaps your question is answered there. If not, carry on!
❓ Questions and Help
I recently did an experiment on Habitat sim. The agent first turned 30 ° to the left, then turned 30 ° to the right (back to the original state). However, the depth is inconsistent after such operation.
Here's my code.
import random
import numpy as np
import habitat_sim
def make_cfg(settings):
sim_cfg = habitat_sim.SimulatorConfiguration()
sim_cfg.gpu_device_id = settings["gpu_device_id"]
sim_cfg.scene_id = settings["scene"]
sim_cfg.enable_physics = settings["enable_physics"]
sim_cfg.scene_dataset_config_file = settings["scene_dataset"]
sensor_specs = []
if settings["rgb_sensor"]:
rgb_sensor_spec = habitat_sim.CameraSensorSpec()
rgb_sensor_spec.uuid = "rgb_sensor"
rgb_sensor_spec.hfov = settings["hfov"]
rgb_sensor_spec.sensor_type = habitat_sim.SensorType.COLOR
rgb_sensor_spec.resolution = [settings["height"], settings["width"]]
rgb_sensor_spec.position = [0.0, settings["sensor_height"], 0.0]
rgb_sensor_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE
sensor_specs.append(rgb_sensor_spec)
if settings["depth_sensor"]:
depth_sensor_spec = habitat_sim.CameraSensorSpec()
depth_sensor_spec.uuid = "depth_sensor"
depth_sensor_spec.hfov = settings["hfov"]
depth_sensor_spec.sensor_type = habitat_sim.SensorType.DEPTH
depth_sensor_spec.resolution = [settings["height"], settings["width"]]
depth_sensor_spec.position = [0.0, settings["sensor_height"], 0.0]
depth_sensor_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE
depth_sensor_spec.noise_model = "None"
sensor_specs.append(depth_sensor_spec)
if settings["semantic_sensor"]:
semantic_sensor_spec = habitat_sim.CameraSensorSpec()
semantic_sensor_spec.uuid = "semantic_sensor"
semantic_sensor_spec.hfov = settings["hfov"]
semantic_sensor_spec.sensor_type = habitat_sim.SensorType.SEMANTIC
semantic_sensor_spec.resolution = [settings["height"], settings["width"]]
semantic_sensor_spec.position = [0.0, settings["sensor_height"], 0.0]
semantic_sensor_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE
sensor_specs.append(semantic_sensor_spec)
agent_cfg = habitat_sim.agent.AgentConfiguration()
agent_cfg.sensor_specifications = sensor_specs
agent_cfg.action_space = {
"move_forward": habitat_sim.agent.ActionSpec(
"move_forward", habitat_sim.agent.ActuationSpec(amount=0.25)
),
"turn_left": habitat_sim.agent.ActionSpec(
"turn_left", habitat_sim.agent.ActuationSpec(amount=30.0)
),
"turn_right": habitat_sim.agent.ActionSpec(
"turn_right", habitat_sim.agent.ActuationSpec(amount=30.0)
),
}
return habitat_sim.Configuration(sim_cfg, [agent_cfg])
def main():
sim_settings = {
"width": 256,
"height": 256,
"hfov": 90,
"scene": "data/scene_datasets/mp3d/17DRP5sb8fy/17DRP5sb8fy.glb",
"scene_dataset": "data/scene_datasets/mp3d/mp3d.scene_dataset_config.json",
"default_agent": 0,
"sensor_height": 1.5,
"rgb_sensor": False,
"depth_sensor": True,
"semantic_sensor": False,
"seed": 1,
"enable_physics": False,
"gpu_device_id": 0
}
cfg = make_cfg(sim_settings)
sim = habitat_sim.Simulator(cfg)
random.seed(sim_settings["seed"])
sim.seed(sim_settings["seed"])
agent = sim.initialize_agent(sim_settings["default_agent"])
agent_state = habitat_sim.AgentState()
agent_state.position = np.array([-0.6, 0.0, 0.0])
agent.set_state(agent_state)
observations = sim.reset(0)
depth_raw = observations["depth_sensor"]
actions_seq = ["turn_left", "turn_right"]
for action in actions_seq:
observations = sim.step(action)
depth_new = observations["depth_sensor"]
if not (depth_raw == depth_new).all():
# Issue: how to ensure consistent observation
not_eq_idx = np.argwhere(depth_new != depth_raw)
print(
"len(not_eq_idx) =",
len(not_eq_idx),
"ratio =",
f"{100 * len(not_eq_idx) / (sim_settings['height'] * sim_settings['width'])}%")
if __name__ == "__main__":
main()
The outputs are as follows:
len(not_eq_idx) = 2139 ratio = 3.26385498046875%
In addition, I printed inconsistent depth information, and the difference between them is very small (similar to the following). I think they may be caused by calculation errors. Can such errors be completely avoided?
depth_new 0.9272244 depth_raw 0.92721933 difference 5.066395e-06