Skip to content

Commit 25212b2

Browse files
authored
Merge pull request facebookresearch#598 from vauduong/modify-tests-sensor-spec
[Sensor] Fix hab-lab examples to work with Hierarchical SensorSpec changes
2 parents eb5907d + 9148afa commit 25212b2

4 files changed

Lines changed: 93 additions & 73 deletions

File tree

docs/pages/habitat-sim-demo.rst

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,34 +46,31 @@ Habitat Sim Demo
4646
sim_cfg.scene_id = settings["scene"]
4747
4848
# Note: all sensors must have the same resolution
49-
sensors = {
50-
"color_sensor": {
51-
"sensor_type": habitat_sim.SensorType.COLOR,
52-
"resolution": [settings["height"], settings["width"]],
53-
"position": [0.0, settings["sensor_height"], 0.0],
54-
},
55-
"depth_sensor": {
56-
"sensor_type": habitat_sim.SensorType.DEPTH,
57-
"resolution": [settings["height"], settings["width"]],
58-
"position": [0.0, settings["sensor_height"], 0.0],
59-
},
60-
"semantic_sensor": {
61-
"sensor_type": habitat_sim.SensorType.SEMANTIC,
62-
"resolution": [settings["height"], settings["width"]],
63-
"position": [0.0, settings["sensor_height"], 0.0],
64-
},
65-
}
66-
6749
sensor_specs = []
68-
for sensor_uuid, sensor_params in sensors.items():
69-
if settings[sensor_uuid]:
70-
sensor_spec = habitat_sim.SensorSpec()
71-
sensor_spec.uuid = sensor_uuid
72-
sensor_spec.sensor_type = sensor_params["sensor_type"]
73-
sensor_spec.resolution = sensor_params["resolution"]
74-
sensor_spec.position = sensor_params["position"]
75-
76-
sensor_specs.append(sensor_spec)
50+
51+
color_sensor_spec = habitat_sim.CameraSensorSpec()
52+
color_sensor_spec.uuid = "color_sensor"
53+
color_sensor_spec.sensor_type = habitat_sim.SensorType.COLOR
54+
color_sensor_spec.resolution = [settings["height"], settings["width"]]
55+
color_sensor_spec.position = [0.0, settings["sensor_height"], 0.0]
56+
color_sensor_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE
57+
sensor_specs.append(color_sensor_spec)
58+
59+
depth_sensor_spec = habitat_sim.CameraSensorSpec()
60+
depth_sensor_spec.uuid = "depth_sensor"
61+
depth_sensor_spec.sensor_type = habitat_sim.SensorType.DEPTH
62+
depth_sensor_spec.resolution = [settings["height"], settings["width"]]
63+
depth_sensor_spec.position = [0.0, settings["sensor_height"], 0.0]
64+
depth_sensor_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE
65+
sensor_specs.append(depth_sensor_spec)
66+
67+
semantic_sensor_spec = habitat_sim.CameraSensorSpec()
68+
semantic_sensor_spec.uuid = "semantic_sensor"
69+
semantic_sensor_spec.sensor_type = habitat_sim.SensorType.SEMANTIC
70+
semantic_sensor_spec.resolution = [settings["height"], settings["width"]]
71+
semantic_sensor_spec.position = [0.0, settings["sensor_height"], 0.0]
72+
semantic_sensor_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE
73+
sensor_specs.append(semantic_sensor_spec)
7774
7875
# Here you can specify the amount of displacement in a forward action and the turn angle
7976
agent_cfg = habitat_sim.agent.AgentConfiguration()

examples/tutorials/colabs/Habitat_Interactive_Tasks.ipynb

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -261,29 +261,23 @@
261261
" sim_cfg.physics_config_file = settings[\"physics_config_file\"]\n",
262262
"\n",
263263
" # Note: all sensors must have the same resolution\n",
264-
" sensors = {\n",
265-
" \"rgb\": {\n",
266-
" \"sensor_type\": habitat_sim.SensorType.COLOR,\n",
267-
" \"resolution\": [settings[\"height\"], settings[\"width\"]],\n",
268-
" \"position\": [0.0, settings[\"sensor_height\"], 0.0],\n",
269-
" },\n",
270-
" \"depth\": {\n",
271-
" \"sensor_type\": habitat_sim.SensorType.DEPTH,\n",
272-
" \"resolution\": [settings[\"height\"], settings[\"width\"]],\n",
273-
" \"position\": [0.0, settings[\"sensor_height\"], 0.0],\n",
274-
" },\n",
275-
" }\n",
276-
"\n",
277264
" sensor_specs = []\n",
278-
" for sensor_uuid, sensor_params in sensors.items():\n",
279-
" if settings[sensor_uuid]:\n",
280-
" sensor_spec = habitat_sim.SensorSpec()\n",
281-
" sensor_spec.uuid = sensor_uuid\n",
282-
" sensor_spec.sensor_type = sensor_params[\"sensor_type\"]\n",
283-
" sensor_spec.resolution = sensor_params[\"resolution\"]\n",
284-
" sensor_spec.position = sensor_params[\"position\"]\n",
285-
"\n",
286-
" sensor_specs.append(sensor_spec)\n",
265+
"\n",
266+
" rgb_sensor_spec = habitat_sim.CameraSensorSpec()\n",
267+
" rgb_sensor_spec.uuid = \"rgb\"\n",
268+
" rgb_sensor_spec.sensor_type = habitat_sim.SensorType.COLOR\n",
269+
" rgb_sensor_spec.resolution = [settings[\"height\"], settings[\"width\"]]\n",
270+
" rgb_sensor_spec.position = [0.0, settings[\"sensor_height\"], 0.0]\n",
271+
" rgb_sensor_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE\n",
272+
" sensor_specs.append(rgb_sensor_spec)\n",
273+
"\n",
274+
" depth_sensor_spec = habitat_sim.CameraSensorSpec()\n",
275+
" depth_sensor_spec.uuid = \"depth\"\n",
276+
" depth_sensor_spec.sensor_type = habitat_sim.SensorType.DEPTH\n",
277+
" depth_sensor_spec.resolution = [settings[\"height\"], settings[\"width\"]]\n",
278+
" depth_sensor_spec.position = [0.0, settings[\"sensor_height\"], 0.0]\n",
279+
" depth_sensor_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE\n",
280+
" sensor_specs.append(depth_sensor_spec)\n",
287281
"\n",
288282
" # Here you can specify the amount of displacement in a forward action and the turn angle\n",
289283
" agent_cfg = habitat_sim.agent.AgentConfiguration()\n",

examples/tutorials/nb_python/Habitat_Interactive_Tasks.py

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -258,29 +258,23 @@ def make_cfg(settings):
258258
sim_cfg.physics_config_file = settings["physics_config_file"]
259259

260260
# Note: all sensors must have the same resolution
261-
sensors = {
262-
"rgb": {
263-
"sensor_type": habitat_sim.SensorType.COLOR,
264-
"resolution": [settings["height"], settings["width"]],
265-
"position": [0.0, settings["sensor_height"], 0.0],
266-
},
267-
"depth": {
268-
"sensor_type": habitat_sim.SensorType.DEPTH,
269-
"resolution": [settings["height"], settings["width"]],
270-
"position": [0.0, settings["sensor_height"], 0.0],
271-
},
272-
}
273-
274261
sensor_specs = []
275-
for sensor_uuid, sensor_params in sensors.items():
276-
if settings[sensor_uuid]:
277-
sensor_spec = habitat_sim.SensorSpec()
278-
sensor_spec.uuid = sensor_uuid
279-
sensor_spec.sensor_type = sensor_params["sensor_type"]
280-
sensor_spec.resolution = sensor_params["resolution"]
281-
sensor_spec.position = sensor_params["position"]
282-
283-
sensor_specs.append(sensor_spec)
262+
263+
rgb_sensor_spec = habitat_sim.CameraSensorSpec()
264+
rgb_sensor_spec.uuid = "rgb"
265+
rgb_sensor_spec.sensor_type = habitat_sim.SensorType.COLOR
266+
rgb_sensor_spec.resolution = [settings["height"], settings["width"]]
267+
rgb_sensor_spec.position = [0.0, settings["sensor_height"], 0.0]
268+
rgb_sensor_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE
269+
sensor_specs.append(rgb_sensor_spec)
270+
271+
depth_sensor_spec = habitat_sim.CameraSensorSpec()
272+
depth_sensor_spec.uuid = "depth"
273+
depth_sensor_spec.sensor_type = habitat_sim.SensorType.DEPTH
274+
depth_sensor_spec.resolution = [settings["height"], settings["width"]]
275+
depth_sensor_spec.position = [0.0, settings["sensor_height"], 0.0]
276+
depth_sensor_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE
277+
sensor_specs.append(depth_sensor_spec)
284278

285279
# Here you can specify the amount of displacement in a forward action and the turn angle
286280
agent_cfg = habitat_sim.agent.AgentConfiguration()

habitat/sims/habitat_simulator/habitat_simulator.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,11 @@ def if_config_to_lower(config):
8282
@registry.register_sensor
8383
class HabitatSimRGBSensor(RGBSensor):
8484
sim_sensor_type: habitat_sim.SensorType
85+
sim_sensor_subtype: habitat_sim.SensorSubType
8586

8687
def __init__(self, config: Config) -> None:
8788
self.sim_sensor_type = habitat_sim.SensorType.COLOR
89+
self.sim_sensor_subtype = habitat_sim.SensorSubType.PINHOLE
8890
super().__init__(config=config)
8991

9092
def _get_observation_space(self, *args: Any, **kwargs: Any) -> Box:
@@ -109,11 +111,13 @@ def get_observation(
109111
@registry.register_sensor
110112
class HabitatSimDepthSensor(DepthSensor):
111113
sim_sensor_type: habitat_sim.SensorType
114+
sim_sensor_subtype: habitat_sim.SensorSubType
112115
min_depth_value: float
113116
max_depth_value: float
114117

115118
def __init__(self, config: Config) -> None:
116119
self.sim_sensor_type = habitat_sim.SensorType.DEPTH
120+
self.sim_sensor_subtype = habitat_sim.SensorSubType.PINHOLE
117121

118122
if config.NORMALIZE_DEPTH:
119123
self.min_depth_value = 0
@@ -160,9 +164,11 @@ def get_observation(
160164
@registry.register_sensor
161165
class HabitatSimSemanticSensor(SemanticSensor):
162166
sim_sensor_type: habitat_sim.SensorType
167+
sim_sensor_subtype: habitat_sim.SensorSubType
163168

164169
def __init__(self, config):
165170
self.sim_sensor_type = habitat_sim.SensorType.SEMANTIC
171+
self.sim_sensor_subtype = habitat_sim.SensorSubType.PINHOLE
166172
super().__init__(config=config)
167173

168174
def _get_observation_space(self, *args: Any, **kwargs: Any):
@@ -257,8 +263,37 @@ def create_sim_config(
257263
)
258264

259265
sensor_specifications = []
266+
VisualSensorTypeSet = {
267+
habitat_sim.SensorType.COLOR,
268+
habitat_sim.SensorType.DEPTH,
269+
habitat_sim.SensorType.SEMANTIC,
270+
}
271+
CameraSensorSubTypeSet = {
272+
habitat_sim.SensorSubType.PINHOLE,
273+
habitat_sim.SensorSubType.ORTHOGRAPHIC,
274+
}
260275
for sensor in _sensor_suite.sensors.values():
261-
sim_sensor_cfg = habitat_sim.SensorSpec()
276+
277+
# Check if type VisualSensorSpec, we know that Sensor is one of HabitatSimRGBSensor, HabitatSimDepthSensor, HabitatSimSemanticSensor
278+
if (
279+
getattr(sensor, "sim_sensor_type", [])
280+
not in VisualSensorTypeSet
281+
):
282+
raise ValueError(
283+
f"""{getattr(sensor, "sim_sensor_type", [])} is an illegal sensorType that is not implemented yet"""
284+
)
285+
# Check if type CameraSensorSpec
286+
if (
287+
getattr(sensor, "sim_sensor_subtype", [])
288+
not in CameraSensorSubTypeSet
289+
):
290+
raise ValueError(
291+
f"""{getattr(sensor, "sim_sensor_subtype", [])} is an illegal sensorSubType for a VisualSensor"""
292+
)
293+
294+
# TODO: Implement checks for other types of SensorSpecs
295+
296+
sim_sensor_cfg = habitat_sim.CameraSensorSpec()
262297
# TODO Handle configs for custom VisualSensors that might need
263298
# their own ignore_keys. Maybe with special key / checking
264299
# SensorType
@@ -281,13 +316,13 @@ def create_sim_config(
281316
sim_sensor_cfg.resolution = list(
282317
sensor.observation_space.shape[:2]
283318
)
284-
sim_sensor_cfg.parameters["hfov"] = str(sensor.config.HFOV)
285319

286320
# TODO(maksymets): Add configure method to Sensor API to avoid
287321
# accessing child attributes through parent interface
288322
# We know that the Sensor has to be one of these Sensors
289323
sensor = cast(HabitatSimVizSensors, sensor)
290324
sim_sensor_cfg.sensor_type = sensor.sim_sensor_type
325+
sim_sensor_cfg.sensor_subtype = sensor.sim_sensor_subtype
291326
sim_sensor_cfg.gpu2gpu_transfer = (
292327
self.habitat_config.HABITAT_SIM_V0.GPU_GPU
293328
)

0 commit comments

Comments
 (0)