From 58897122a9dffbf18d0600ee5642d2c948f78731 Mon Sep 17 00:00:00 2001 From: Mino Date: Fri, 28 Oct 2022 12:38:41 -0700 Subject: [PATCH 01/24] camera specs to dictionary --- src_python/habitat_sim/utils/settings.py | 168 +++++++---------------- 1 file changed, 49 insertions(+), 119 deletions(-) diff --git a/src_python/habitat_sim/utils/settings.py b/src_python/habitat_sim/utils/settings.py index 2ddc396007..b7749fab91 100644 --- a/src_python/habitat_sim/utils/settings.py +++ b/src_python/habitat_sim/utils/settings.py @@ -8,27 +8,26 @@ default_sim_settings = { "scene_dataset_config_file": "default", "scene": "NONE", - "width": 640, - "height": 480, "default_agent": 0, - "sensor_height": 1.5, - "hfov": 90, - "color_sensor": True, - "semantic_sensor": False, - "depth_sensor": False, - "ortho_rgba_sensor": False, - "ortho_depth_sensor": False, - "ortho_semantic_sensor": False, - "fisheye_rgba_sensor": False, - "fisheye_depth_sensor": False, - "fisheye_semantic_sensor": False, - "equirect_rgba_sensor": False, - "equirect_depth_sensor": False, - "equirect_semantic_sensor": False, "seed": 1, "physics_config_file": "data/default.physics_config.json", + "sensors": [ + { + "uuid": "color_sensor", + "width": 640, + "height": 480, + "sensor_height": 1.5, + "hfov": 90, + "sensor_subtype": habitat_sim.SensorSubType.PINHOLE, + "sensor_type": habitat_sim.SensorType.COLOR, + "position": [0, 1.5, 0], + "channels": 3, + "camera_type": habitat_sim.CameraSensorSpec, + }, + ], } + # build SimulatorConfiguration def make_cfg(settings): sim_cfg = habitat_sim.SimulatorConfiguration() @@ -53,73 +52,13 @@ def make_cfg(settings): def create_camera_spec(**kw_args): camera_sensor_spec = habitat_sim.CameraSensorSpec() - camera_sensor_spec.sensor_type = habitat_sim.SensorType.COLOR - camera_sensor_spec.resolution = [settings["height"], settings["width"]] - camera_sensor_spec.position = [0, settings["sensor_height"], 0] for k in kw_args: setattr(camera_sensor_spec, k, kw_args[k]) return camera_sensor_spec - if settings["color_sensor"]: - color_sensor_spec = create_camera_spec( - uuid="color_sensor", - hfov=settings["hfov"], - sensor_type=habitat_sim.SensorType.COLOR, - sensor_subtype=habitat_sim.SensorSubType.PINHOLE, - ) - sensor_specs.append(color_sensor_spec) - - if settings["depth_sensor"]: - depth_sensor_spec = create_camera_spec( - uuid="depth_sensor", - hfov=settings["hfov"], - sensor_type=habitat_sim.SensorType.DEPTH, - channels=1, - sensor_subtype=habitat_sim.SensorSubType.PINHOLE, - ) - sensor_specs.append(depth_sensor_spec) - - if settings["semantic_sensor"]: - semantic_sensor_spec = create_camera_spec( - uuid="semantic_sensor", - hfov=settings["hfov"], - sensor_type=habitat_sim.SensorType.SEMANTIC, - channels=1, - sensor_subtype=habitat_sim.SensorSubType.PINHOLE, - ) - sensor_specs.append(semantic_sensor_spec) - - if settings["ortho_rgba_sensor"]: - ortho_rgba_sensor_spec = create_camera_spec( - uuid="ortho_rgba_sensor", - sensor_type=habitat_sim.SensorType.COLOR, - sensor_subtype=habitat_sim.SensorSubType.ORTHOGRAPHIC, - ) - sensor_specs.append(ortho_rgba_sensor_spec) - - if settings["ortho_depth_sensor"]: - ortho_depth_sensor_spec = create_camera_spec( - uuid="ortho_depth_sensor", - sensor_type=habitat_sim.SensorType.DEPTH, - channels=1, - sensor_subtype=habitat_sim.SensorSubType.ORTHOGRAPHIC, - ) - sensor_specs.append(ortho_depth_sensor_spec) - - if settings["ortho_semantic_sensor"]: - ortho_semantic_sensor_spec = create_camera_spec( - uuid="ortho_semantic_sensor", - sensor_type=habitat_sim.SensorType.SEMANTIC, - channels=1, - sensor_subtype=habitat_sim.SensorSubType.ORTHOGRAPHIC, - ) - sensor_specs.append(ortho_semantic_sensor_spec) - # TODO Figure out how to implement copying of specs def create_fisheye_spec(**kw_args): fisheye_sensor_spec = habitat_sim.FisheyeSensorDoubleSphereSpec() - fisheye_sensor_spec.uuid = "fisheye_sensor" - fisheye_sensor_spec.sensor_type = habitat_sim.SensorType.COLOR fisheye_sensor_spec.sensor_model_type = ( habitat_sim.FisheyeSensorModelType.DOUBLE_SPHERE ) @@ -132,62 +71,53 @@ def create_fisheye_spec(**kw_args): fisheye_sensor_spec.alpha = 0.57 fisheye_sensor_spec.focal_length = [364.84, 364.86] - fisheye_sensor_spec.resolution = [settings["height"], settings["width"]] # The default principal_point_offset is the middle of the image fisheye_sensor_spec.principal_point_offset = None # default: fisheye_sensor_spec.principal_point_offset = [i/2 for i in fisheye_sensor_spec.resolution] - fisheye_sensor_spec.position = [0, settings["sensor_height"], 0] for k in kw_args: setattr(fisheye_sensor_spec, k, kw_args[k]) return fisheye_sensor_spec - if settings["fisheye_rgba_sensor"]: - fisheye_rgba_sensor_spec = create_fisheye_spec(uuid="fisheye_rgba_sensor") - sensor_specs.append(fisheye_rgba_sensor_spec) - if settings["fisheye_depth_sensor"]: - fisheye_depth_sensor_spec = create_fisheye_spec( - uuid="fisheye_depth_sensor", - sensor_type=habitat_sim.SensorType.DEPTH, - channels=1, - ) - sensor_specs.append(fisheye_depth_sensor_spec) - if settings["fisheye_semantic_sensor"]: - fisheye_semantic_sensor_spec = create_fisheye_spec( - uuid="fisheye_semantic_sensor", - sensor_type=habitat_sim.SensorType.SEMANTIC, - channels=1, - ) - sensor_specs.append(fisheye_semantic_sensor_spec) - def create_equirect_spec(**kw_args): equirect_sensor_spec = habitat_sim.EquirectangularSensorSpec() - equirect_sensor_spec.uuid = "equirect_rgba_sensor" - equirect_sensor_spec.sensor_type = habitat_sim.SensorType.COLOR - equirect_sensor_spec.resolution = [settings["height"], settings["width"]] - equirect_sensor_spec.position = [0, settings["sensor_height"], 0] for k in kw_args: setattr(equirect_sensor_spec, k, kw_args[k]) return equirect_sensor_spec - if settings["equirect_rgba_sensor"]: - equirect_rgba_sensor_spec = create_equirect_spec(uuid="equirect_rgba_sensor") - sensor_specs.append(equirect_rgba_sensor_spec) - - if settings["equirect_depth_sensor"]: - equirect_depth_sensor_spec = create_equirect_spec( - uuid="equirect_depth_sensor", - sensor_type=habitat_sim.SensorType.DEPTH, - channels=1, - ) - sensor_specs.append(equirect_depth_sensor_spec) - - if settings["equirect_semantic_sensor"]: - equirect_semantic_sensor_spec = create_equirect_spec( - uuid="equirect_semantic_sensor", - sensor_type=habitat_sim.SensorType.SEMANTIC, - channels=1, - ) - sensor_specs.append(equirect_semantic_sensor_spec) + for sensor_cfg in settings["sensors"]: + if sensor_cfg["camera_type"] == habitat_sim.CameraSensorSpec: + camera_spec = create_camera_spec( + uuid=sensor_cfg["uuid"], + hfov=sensor_cfg["hfov"], + sensor_type=sensor_cfg["sensor_type"], + sensor_subtype=sensor_cfg["sensor_subtype"], + position=sensor_cfg["position"], + channels=sensor_cfg["channels"], + resolution=[sensor_cfg["height"], sensor_cfg["width"]], + ) + sensor_specs.append(camera_spec) + elif sensor_cfg["camera_type"] == habitat_sim.FisheyeSensorDoubleSphereSpec: + fisheye_spec = create_fisheye_spec( + uuid=sensor_cfg["uuid"], + hfov=sensor_cfg["hfov"], + sensor_type=sensor_cfg["sensor_type"], + sensor_subtype=sensor_cfg["sensor_subtype"], + position=sensor_cfg["position"], + channels=sensor_cfg["channels"], + resolution=[sensor_cfg["height"], sensor_cfg["width"]], + ) + sensor_specs.append(fisheye_spec) + elif sensor_cfg["camera_type"] == habitat_sim.EquirectangularSensorSpec: + equirect_spec = create_equirect_spec( + uuid=sensor_cfg["uuid"], + hfov=sensor_cfg["hfov"], + sensor_type=sensor_cfg["sensor_type"], + sensor_subtype=sensor_cfg["sensor_subtype"], + position=sensor_cfg["position"], + channels=sensor_cfg["channels"], + resolution=[sensor_cfg["height"], sensor_cfg["width"]], + ) + sensor_specs.append(equirect_spec) # create agent specifications agent_cfg = habitat_sim.agent.AgentConfiguration() From 7a4e5456aa84e380ed857a8e871fd13bd10c88ff Mon Sep 17 00:00:00 2001 From: Mino Date: Fri, 28 Oct 2022 15:29:27 -0700 Subject: [PATCH 02/24] updating tests --- src_python/habitat_sim/utils/settings.py | 72 +++++++++++++++--------- tests/conftest.py | 11 ++-- tests/test_gfx.py | 12 ++-- tests/test_physics.py | 20 ++++++- tests/test_semantic_scene.py | 1 - tests/test_sensors.py | 28 ++++++--- tests/test_simulator.py | 9 ++- 7 files changed, 103 insertions(+), 50 deletions(-) diff --git a/src_python/habitat_sim/utils/settings.py b/src_python/habitat_sim/utils/settings.py index b7749fab91..d7208c6c82 100644 --- a/src_python/habitat_sim/utils/settings.py +++ b/src_python/habitat_sim/utils/settings.py @@ -14,19 +14,18 @@ "sensors": [ { "uuid": "color_sensor", - "width": 640, - "height": 480, - "sensor_height": 1.5, - "hfov": 90, - "sensor_subtype": habitat_sim.SensorSubType.PINHOLE, - "sensor_type": habitat_sim.SensorType.COLOR, - "position": [0, 1.5, 0], - "channels": 3, - "camera_type": habitat_sim.CameraSensorSpec, }, ], } +default_sensor_settings = { + "width": 640, + "height": 480, + "hfov": 90, + "position": [0, 1.5, 0], + "orientation": [0, 0, 0], +} + # build SimulatorConfiguration def make_cfg(settings): @@ -85,39 +84,58 @@ def create_equirect_spec(**kw_args): return equirect_sensor_spec for sensor_cfg in settings["sensors"]: - if sensor_cfg["camera_type"] == habitat_sim.CameraSensorSpec: - camera_spec = create_camera_spec( - uuid=sensor_cfg["uuid"], - hfov=sensor_cfg["hfov"], - sensor_type=sensor_cfg["sensor_type"], - sensor_subtype=sensor_cfg["sensor_subtype"], - position=sensor_cfg["position"], - channels=sensor_cfg["channels"], - resolution=[sensor_cfg["height"], sensor_cfg["width"]], + sensor_cfg = {**default_sensor_settings, **sensor_cfg} + uuid = sensor_cfg["uuid"] + + sensor_type = ( + habitat_sim.SensorType.DEPTH + if "depth" in uuid + else ( + habitat_sim.SensorType.SEMANTIC + if "semantic" in uuid + else habitat_sim.SensorType.COLOR ) - sensor_specs.append(camera_spec) - elif sensor_cfg["camera_type"] == habitat_sim.FisheyeSensorDoubleSphereSpec: + ) + sensor_subtype = ( + habitat_sim.SensorSubType.ORTHOGRAPHI + if "ortho" in uuid + else habitat_sim.SensorSubType.PINHOLE + ) + channels = 3 if sensor_type is habitat_sim.SensorType.COLOR else 1 + + if "fisheye" in uuid: fisheye_spec = create_fisheye_spec( uuid=sensor_cfg["uuid"], hfov=sensor_cfg["hfov"], - sensor_type=sensor_cfg["sensor_type"], - sensor_subtype=sensor_cfg["sensor_subtype"], position=sensor_cfg["position"], - channels=sensor_cfg["channels"], resolution=[sensor_cfg["height"], sensor_cfg["width"]], + sensor_type=sensor_type, + sensor_subtype=sensor_subtype, + channels=channels, ) sensor_specs.append(fisheye_spec) - elif sensor_cfg["camera_type"] == habitat_sim.EquirectangularSensorSpec: + elif "equirect" in uuid: equirect_spec = create_equirect_spec( uuid=sensor_cfg["uuid"], hfov=sensor_cfg["hfov"], - sensor_type=sensor_cfg["sensor_type"], - sensor_subtype=sensor_cfg["sensor_subtype"], position=sensor_cfg["position"], - channels=sensor_cfg["channels"], resolution=[sensor_cfg["height"], sensor_cfg["width"]], + sensor_type=sensor_type, + sensor_subtype=sensor_subtype, + channels=channels, ) sensor_specs.append(equirect_spec) + else: + camera_spec = create_camera_spec( + uuid=sensor_cfg["uuid"], + hfov=sensor_cfg["hfov"], + position=sensor_cfg["position"], + resolution=[sensor_cfg["height"], sensor_cfg["width"]], + sensor_type=sensor_type, + sensor_subtype=sensor_subtype, + channels=channels, + ) + sensor_specs.append(camera_spec) # create agent specifications agent_cfg = habitat_sim.agent.AgentConfiguration() diff --git a/tests/conftest.py b/tests/conftest.py index 03f5b89bd8..e7cba11a45 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -25,12 +25,11 @@ def make_cfg_settings(): import habitat_sim.utils.settings cfg = habitat_sim.utils.settings.default_sim_settings.copy() - cfg["height"] = 480 - cfg["width"] = 640 - cfg["sensor_height"] = 1.5 - cfg["color_sensor"] = True - cfg["semantic_sensor"] = True - cfg["depth_sensor"] = True + cfg["sensors"] = [ + {"uuid": "color_sensor", "height": 480, "width": 640}, + {"uuid": "semantic_sensor", "height": 480, "width": 640}, + {"uuid": "depth_sensor", "height": 480, "width": 640}, + ] cfg["silent"] = True cfg["scene"] = _test_scene cfg["frustum_culling"] = True diff --git a/tests/test_gfx.py b/tests/test_gfx.py index 616dceed83..5f6371a71c 100644 --- a/tests/test_gfx.py +++ b/tests/test_gfx.py @@ -24,10 +24,14 @@ def test_unproject(): # configure some settings in case defaults change cfg_settings["scene"] = "data/scene_datasets/habitat-test-scenes/apartment_1.glb" - cfg_settings["width"] = 101 - cfg_settings["height"] = 101 - cfg_settings["sensor_height"] = 0 - cfg_settings["color_sensor"] = True + cfg_settings["sensors"] = [ + { + "uuid": "color_sensor", + "width": 101, + "height": 101, + "position": [0, 0, 0], + } + ] # loading the scene hab_cfg = habitat_sim.utils.settings.make_cfg(cfg_settings) diff --git a/tests/test_physics.py b/tests/test_physics.py index 05e40c4590..a4f16bf79a 100644 --- a/tests/test_physics.py +++ b/tests/test_physics.py @@ -38,7 +38,7 @@ def test_kinematics(): ] = "data/scene_datasets/habitat-test-scenes/skokloster-castle.glb" # enable the physics simulator: also clears available actions to no-op cfg_settings["enable_physics"] = True - cfg_settings["depth_sensor"] = True + cfg_settings["sensors"] = [{"uuid": "depth_sensor"}, {"uuid": "color_sensor"}] # test loading the physical scene hab_cfg = habitat_sim.utils.settings.make_cfg(cfg_settings) @@ -152,7 +152,14 @@ def test_kinematics_no_physics(): ] = "data/scene_datasets/habitat-test-scenes/skokloster-castle.glb" # enable the physics simulator: also clears available actions to no-op cfg_settings["enable_physics"] = False - cfg_settings["depth_sensor"] = True + cfg_settings["sensors"] = [ + { + "uuid": "depth_sensor", + }, + { + "uuid": "color_sensor", + }, + ] # test loading the physical scene hab_cfg = habitat_sim.utils.settings.make_cfg(cfg_settings) @@ -269,7 +276,14 @@ def test_dynamics(): ] = "data/scene_datasets/habitat-test-scenes/skokloster-castle.glb" # enable the physics simulator: also clears available actions to no-op cfg_settings["enable_physics"] = True - cfg_settings["depth_sensor"] = True + cfg_settings["sensors"] = [ + { + "uuid": "depth_sensor", + }, + { + "uuid": "color_sensor", + }, + ] # test loading the physical scene hab_cfg = habitat_sim.utils.settings.make_cfg(cfg_settings) diff --git a/tests/test_semantic_scene.py b/tests/test_semantic_scene.py index c766ee33b6..0b0b2a3385 100644 --- a/tests/test_semantic_scene.py +++ b/tests/test_semantic_scene.py @@ -39,7 +39,6 @@ def test_semantic_scene(scene, make_cfg_settings): pytest.skip("Skipping {}".format(scene)) make_cfg_settings = {k: v for k, v in make_cfg_settings.items()} - make_cfg_settings["semantic_sensor"] = False make_cfg_settings["scene"] = scene cfg = make_cfg(make_cfg_settings) cfg.agents[0].sensor_specifications = [] diff --git a/tests/test_sensors.py b/tests/test_sensors.py index 8ff2662ac0..27b837273e 100644 --- a/tests/test_sensors.py +++ b/tests/test_sensors.py @@ -199,7 +199,11 @@ def test_sensors( else: make_cfg_settings[sens] = False - make_cfg_settings[sensor_type] = True + make_cfg_settings["sensors"] = [ + { + "uuid": sensor_type, + } + ] make_cfg_settings["scene"] = scene make_cfg_settings["scene_dataset_config_file"] = scene_dataset_config make_cfg_settings["frustum_culling"] = frustum_culling @@ -249,7 +253,11 @@ def test_reconfigure_render( make_cfg_settings["scene"] = _test_scenes[-1][0] make_cfg_settings["scene_dataset_config_file"] = _test_scenes[-1][1] - make_cfg_settings[sensor_type] = True + make_cfg_settings["sensors"] = [ + { + "uuid": sensor_type, + } + ] cfg = make_cfg(make_cfg_settings) @@ -301,9 +309,11 @@ def test_smoke_redwood_noise(scene_and_dataset, gpu2gpu, make_cfg_settings): if gpu2gpu and (not habitat_sim.cuda_enabled or not _HAS_TORCH): pytest.skip("Skipping GPU->GPU test") scene_dataset_config = scene_and_dataset[1] - make_cfg_settings["depth_sensor"] = True - make_cfg_settings["color_sensor"] = False - make_cfg_settings["semantic_sensor"] = False + make_cfg_settings["sensors"] = [ + { + "uuid": "depth_sensor", + } + ] make_cfg_settings["scene"] = scene make_cfg_settings["scene_dataset_config_file"] = scene_dataset_config hsim_cfg = make_cfg(make_cfg_settings) @@ -351,9 +361,11 @@ def test_rgba_noise(scene_and_dataset, model_name, make_cfg_settings): if not osp.exists(scene): pytest.skip("Skipping {}".format(scene)) scene_dataset_config = scene_and_dataset[1] - make_cfg_settings["depth_sensor"] = False - make_cfg_settings["color_sensor"] = True - make_cfg_settings["semantic_sensor"] = False + make_cfg_settings["sensors"] = [ + { + "uuid": "color_sensor", + } + ] make_cfg_settings["scene"] = scene make_cfg_settings["scene_dataset_config_file"] = scene_dataset_config hsim_cfg = make_cfg(make_cfg_settings) diff --git a/tests/test_simulator.py b/tests/test_simulator.py index e38fc7b85e..0f4cb8225b 100644 --- a/tests/test_simulator.py +++ b/tests/test_simulator.py @@ -51,7 +51,14 @@ def test_empty_scene(): # keyword "NONE" initializes a scene with no scene mesh cfg_settings["scene"] = "NONE" # test that depth sensor doesn't mind an empty scene - cfg_settings["depth_sensor"] = True + cfg_settings["sensors"] = [ + { + "uuid": "depth_sensor", + }, + { + "uuid": "color_sensor", + }, + ] hab_cfg = habitat_sim.utils.settings.make_cfg(cfg_settings) hab_cfg_mm = habitat_sim.utils.settings.make_cfg(cfg_settings) From f9ad2ab66242bf950cc89eff2b569fc0725ed812 Mon Sep 17 00:00:00 2001 From: Mino Date: Mon, 31 Oct 2022 10:42:43 -0700 Subject: [PATCH 03/24] updating sensors tests --- examples/demo_runner.py | 10 +++---- examples/example.py | 37 +++++++++++++++++++----- src_python/habitat_sim/utils/settings.py | 2 +- tests/test_sensors.py | 19 +++++++----- 4 files changed, 46 insertions(+), 22 deletions(-) diff --git a/examples/demo_runner.py b/examples/demo_runner.py index 9e862b0acb..14bb729a15 100644 --- a/examples/demo_runner.py +++ b/examples/demo_runner.py @@ -258,12 +258,13 @@ def do_time_steps(self): # get simulation step time without sensor observations total_sim_step_time += self._sim._previous_step_time + sensor_uuids = [sensor["uuid"] for sensor in self._sim_settings["sensors"]] if self._sim_settings["save_png"]: - if self._sim_settings["color_sensor"]: + if "color_sensor" in sensor_uuids: self.save_color_observation(observations, total_frames) - if self._sim_settings["depth_sensor"]: + if "depth_sensor" in sensor_uuids: self.save_depth_observation(observations, total_frames) - if self._sim_settings["semantic_sensor"]: + if "semantic_sensor" in sensor_uuids: self.save_semantic_observation(observations, total_frames) state = self._sim.last_state() @@ -283,7 +284,7 @@ def do_time_steps(self): print("len(action_path)", len(self._action_path)) if ( - self._sim_settings["semantic_sensor"] + "semantic_sensor" in sensor_uuids and self._sim_settings["print_semantic_mask_stats"] ): self.output_semantic_mask_stats(observations, total_frames) @@ -409,7 +410,6 @@ def benchmark(self, settings, group_id=ABTestGroup.CONTROL): def example(self): start_state = self.init_common() - # initialize and compute shortest path to goal if self._sim_settings["compute_shortest_path"]: self._shortest_path = ShortestPath() diff --git a/examples/example.py b/examples/example.py index 3a86ddac71..0d21ea77be 100755 --- a/examples/example.py +++ b/examples/example.py @@ -40,14 +40,8 @@ def make_settings(): settings = dr.default_sim_settings.copy() settings["max_frames"] = args.max_frames - settings["width"] = args.width - settings["height"] = args.height settings["scene"] = args.scene settings["save_png"] = args.save_png - settings["sensor_height"] = args.sensor_height - settings["color_sensor"] = not args.disable_color_sensor - settings["semantic_sensor"] = args.semantic_sensor - settings["depth_sensor"] = args.depth_sensor settings["print_semantic_scene"] = args.print_semantic_scene settings["print_semantic_mask_stats"] = args.print_semantic_mask_stats settings["compute_shortest_path"] = args.compute_shortest_path @@ -59,6 +53,34 @@ def make_settings(): settings["frustum_culling"] = not args.disable_frustum_culling settings["recompute_navmesh"] = args.recompute_navmesh + settings["sensors"] = [] + if not args.disable_color_sensor: + settings["sensors"].append( + { + "uuid": "color_sensor", + "width": args.width, + "height": args.height, + "position": [0, args.sensor_height, 0], + } + ) + if args.semantic_sensor: + settings["sensors"].append( + { + "uuid": "semantic_sensor", + "width": args.width, + "height": args.height, + "position": [0, args.sensor_height, 0], + } + ) + if args.depth_sensor: + settings["sensors"].append( + { + "uuid": "depth_sensor", + "width": args.width, + "height": args.height, + "position": [0, args.sensor_height, 0], + } + ) return settings @@ -72,8 +94,7 @@ def make_settings(): print(" ========================= Performance ======================== ") print( - " %d x %d, total time %0.2f s," - % (settings["width"], settings["height"], perf["total_time"]), + " %d x %d, total time %0.2f s," % (args.width, args.height, perf["total_time"]), "frame time %0.3f ms (%0.1f FPS)" % (perf["frame_time"] * 1000.0, perf["fps"]), ) print(" ============================================================== ") diff --git a/src_python/habitat_sim/utils/settings.py b/src_python/habitat_sim/utils/settings.py index d7208c6c82..bdc64f795d 100644 --- a/src_python/habitat_sim/utils/settings.py +++ b/src_python/habitat_sim/utils/settings.py @@ -101,7 +101,7 @@ def create_equirect_spec(**kw_args): if "ortho" in uuid else habitat_sim.SensorSubType.PINHOLE ) - channels = 3 if sensor_type is habitat_sim.SensorType.COLOR else 1 + channels = 4 if sensor_type is habitat_sim.SensorType.COLOR else 1 if "fisheye" in uuid: fisheye_spec = create_fisheye_spec( diff --git a/tests/test_sensors.py b/tests/test_sensors.py index 27b837273e..90e186adc6 100644 --- a/tests/test_sensors.py +++ b/tests/test_sensors.py @@ -190,20 +190,23 @@ def test_sensors( # We only support adding more RGB Sensors if one is already in a scene # We can add depth sensors whenever add_sensor_lazy = add_sensor_lazy and all_base_sensor_types[1] == sensor_type - for sens in all_base_sensor_types: - if add_sensor_lazy: - make_cfg_settings[sens] = ( - sens in all_base_sensor_types[:2] and sens != sensor_type + if ( + add_sensor_lazy + and sens in all_base_sensor_types[:2] + and sens != sensor_type + ): + make_cfg_settings["sensors"].append( + { + "uuid": sens, + } ) - else: - make_cfg_settings[sens] = False - make_cfg_settings["sensors"] = [ + make_cfg_settings["sensors"].append( { "uuid": sensor_type, } - ] + ) make_cfg_settings["scene"] = scene make_cfg_settings["scene_dataset_config_file"] = scene_dataset_config make_cfg_settings["frustum_culling"] = frustum_culling From 3707be8c96922130ee081eec6f871008e05ec0fa Mon Sep 17 00:00:00 2001 From: Mino Date: Mon, 31 Oct 2022 12:00:05 -0700 Subject: [PATCH 04/24] fixing settings and sensor tests --- src_python/habitat_sim/utils/settings.py | 2 +- tests/test_sensors.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src_python/habitat_sim/utils/settings.py b/src_python/habitat_sim/utils/settings.py index bdc64f795d..f5ef5977b0 100644 --- a/src_python/habitat_sim/utils/settings.py +++ b/src_python/habitat_sim/utils/settings.py @@ -97,7 +97,7 @@ def create_equirect_spec(**kw_args): ) ) sensor_subtype = ( - habitat_sim.SensorSubType.ORTHOGRAPHI + habitat_sim.SensorSubType.ORTHOGRAPHIC if "ortho" in uuid else habitat_sim.SensorSubType.PINHOLE ) diff --git a/tests/test_sensors.py b/tests/test_sensors.py index 90e186adc6..d4ac1ea3e8 100644 --- a/tests/test_sensors.py +++ b/tests/test_sensors.py @@ -189,6 +189,7 @@ def test_sensors( # We only support adding more RGB Sensors if one is already in a scene # We can add depth sensors whenever + make_cfg_settings["sensors"] = [] add_sensor_lazy = add_sensor_lazy and all_base_sensor_types[1] == sensor_type for sens in all_base_sensor_types: if ( @@ -341,7 +342,8 @@ def test_initial_hfov(scene_and_dataset, sensor_type, make_cfg_settings): scene = scene_and_dataset[0] if not osp.exists(scene): pytest.skip("Skipping {}".format(scene)) - make_cfg_settings["hfov"] = 70 + for sens_cfg in make_cfg_settings["sensors"]: + sens_cfg["hfov"] = 70 with habitat_sim.Simulator(make_cfg(make_cfg_settings)) as sim: assert sim.agents[0]._sensors[sensor_type].hfov == mn.Deg( 70 From c6b49474b93f0361a2da85cec332855914e348bc Mon Sep 17 00:00:00 2001 From: Mino Date: Mon, 31 Oct 2022 14:06:23 -0700 Subject: [PATCH 05/24] fixed sensor and hfov errors --- src_python/habitat_sim/utils/settings.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src_python/habitat_sim/utils/settings.py b/src_python/habitat_sim/utils/settings.py index f5ef5977b0..d863396c16 100644 --- a/src_python/habitat_sim/utils/settings.py +++ b/src_python/habitat_sim/utils/settings.py @@ -106,22 +106,18 @@ def create_equirect_spec(**kw_args): if "fisheye" in uuid: fisheye_spec = create_fisheye_spec( uuid=sensor_cfg["uuid"], - hfov=sensor_cfg["hfov"], position=sensor_cfg["position"], resolution=[sensor_cfg["height"], sensor_cfg["width"]], sensor_type=sensor_type, - sensor_subtype=sensor_subtype, channels=channels, ) sensor_specs.append(fisheye_spec) elif "equirect" in uuid: equirect_spec = create_equirect_spec( uuid=sensor_cfg["uuid"], - hfov=sensor_cfg["hfov"], position=sensor_cfg["position"], resolution=[sensor_cfg["height"], sensor_cfg["width"]], sensor_type=sensor_type, - sensor_subtype=sensor_subtype, channels=channels, ) sensor_specs.append(equirect_spec) From b5022e03ffa04626998d9efce6bef3ec895c42ac Mon Sep 17 00:00:00 2001 From: Mino Date: Mon, 31 Oct 2022 16:42:11 -0700 Subject: [PATCH 06/24] width/height putting back to its original place --- examples/example.py | 8 ++------ src_python/habitat_sim/utils/settings.py | 10 +++++----- tests/conftest.py | 6 +++--- tests/test_gfx.py | 4 ++-- tests/test_sensors.py | 1 - 5 files changed, 12 insertions(+), 17 deletions(-) diff --git a/examples/example.py b/examples/example.py index 0d21ea77be..3abd7a6d94 100755 --- a/examples/example.py +++ b/examples/example.py @@ -40,6 +40,8 @@ def make_settings(): settings = dr.default_sim_settings.copy() settings["max_frames"] = args.max_frames + settings["width"] = args.width + settings["height"] = args.height settings["scene"] = args.scene settings["save_png"] = args.save_png settings["print_semantic_scene"] = args.print_semantic_scene @@ -58,8 +60,6 @@ def make_settings(): settings["sensors"].append( { "uuid": "color_sensor", - "width": args.width, - "height": args.height, "position": [0, args.sensor_height, 0], } ) @@ -67,8 +67,6 @@ def make_settings(): settings["sensors"].append( { "uuid": "semantic_sensor", - "width": args.width, - "height": args.height, "position": [0, args.sensor_height, 0], } ) @@ -76,8 +74,6 @@ def make_settings(): settings["sensors"].append( { "uuid": "depth_sensor", - "width": args.width, - "height": args.height, "position": [0, args.sensor_height, 0], } ) diff --git a/src_python/habitat_sim/utils/settings.py b/src_python/habitat_sim/utils/settings.py index d863396c16..2f5f6d1255 100644 --- a/src_python/habitat_sim/utils/settings.py +++ b/src_python/habitat_sim/utils/settings.py @@ -8,6 +8,8 @@ default_sim_settings = { "scene_dataset_config_file": "default", "scene": "NONE", + "width": 640, + "height": 480, "default_agent": 0, "seed": 1, "physics_config_file": "data/default.physics_config.json", @@ -19,8 +21,6 @@ } default_sensor_settings = { - "width": 640, - "height": 480, "hfov": 90, "position": [0, 1.5, 0], "orientation": [0, 0, 0], @@ -107,7 +107,7 @@ def create_equirect_spec(**kw_args): fisheye_spec = create_fisheye_spec( uuid=sensor_cfg["uuid"], position=sensor_cfg["position"], - resolution=[sensor_cfg["height"], sensor_cfg["width"]], + resolution=[settings["height"], settings["width"]], sensor_type=sensor_type, channels=channels, ) @@ -116,7 +116,7 @@ def create_equirect_spec(**kw_args): equirect_spec = create_equirect_spec( uuid=sensor_cfg["uuid"], position=sensor_cfg["position"], - resolution=[sensor_cfg["height"], sensor_cfg["width"]], + resolution=[settings["height"], settings["width"]], sensor_type=sensor_type, channels=channels, ) @@ -126,7 +126,7 @@ def create_equirect_spec(**kw_args): uuid=sensor_cfg["uuid"], hfov=sensor_cfg["hfov"], position=sensor_cfg["position"], - resolution=[sensor_cfg["height"], sensor_cfg["width"]], + resolution=[settings["height"], settings["width"]], sensor_type=sensor_type, sensor_subtype=sensor_subtype, channels=channels, diff --git a/tests/conftest.py b/tests/conftest.py index e7cba11a45..3b004eedc9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -26,9 +26,9 @@ def make_cfg_settings(): cfg = habitat_sim.utils.settings.default_sim_settings.copy() cfg["sensors"] = [ - {"uuid": "color_sensor", "height": 480, "width": 640}, - {"uuid": "semantic_sensor", "height": 480, "width": 640}, - {"uuid": "depth_sensor", "height": 480, "width": 640}, + {"uuid": "color_sensor"}, + {"uuid": "semantic_sensor"}, + {"uuid": "depth_sensor"}, ] cfg["silent"] = True cfg["scene"] = _test_scene diff --git a/tests/test_gfx.py b/tests/test_gfx.py index 5f6371a71c..38adf12116 100644 --- a/tests/test_gfx.py +++ b/tests/test_gfx.py @@ -24,11 +24,11 @@ def test_unproject(): # configure some settings in case defaults change cfg_settings["scene"] = "data/scene_datasets/habitat-test-scenes/apartment_1.glb" + cfg_settings["width"] = 101 + cfg_settings["height"] = 101 cfg_settings["sensors"] = [ { "uuid": "color_sensor", - "width": 101, - "height": 101, "position": [0, 0, 0], } ] diff --git a/tests/test_sensors.py b/tests/test_sensors.py index d4ac1ea3e8..d579403d19 100644 --- a/tests/test_sensors.py +++ b/tests/test_sensors.py @@ -290,7 +290,6 @@ def test_smoke_no_sensors(make_cfg_settings): continue scene_dataset_config = scene_and_dataset[1] make_cfg_settings = {k: v for k, v in make_cfg_settings.items()} - make_cfg_settings["semantic_sensor"] = False make_cfg_settings["scene"] = scene make_cfg_settings["scene_dataset_config_file"] = scene_dataset_config cfg = make_cfg(make_cfg_settings) From b5dd8806c3828132093ba8f7036db7e54b0eac1f Mon Sep 17 00:00:00 2001 From: Mino Date: Wed, 2 Nov 2022 16:14:43 -0700 Subject: [PATCH 07/24] i forgot orientation --- src_python/habitat_sim/utils/settings.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src_python/habitat_sim/utils/settings.py b/src_python/habitat_sim/utils/settings.py index 2f5f6d1255..c0f4f98513 100644 --- a/src_python/habitat_sim/utils/settings.py +++ b/src_python/habitat_sim/utils/settings.py @@ -107,6 +107,7 @@ def create_equirect_spec(**kw_args): fisheye_spec = create_fisheye_spec( uuid=sensor_cfg["uuid"], position=sensor_cfg["position"], + orientation=sensor_cfg["orientation"], resolution=[settings["height"], settings["width"]], sensor_type=sensor_type, channels=channels, @@ -116,6 +117,7 @@ def create_equirect_spec(**kw_args): equirect_spec = create_equirect_spec( uuid=sensor_cfg["uuid"], position=sensor_cfg["position"], + orientation=sensor_cfg["orientation"], resolution=[settings["height"], settings["width"]], sensor_type=sensor_type, channels=channels, @@ -126,6 +128,7 @@ def create_equirect_spec(**kw_args): uuid=sensor_cfg["uuid"], hfov=sensor_cfg["hfov"], position=sensor_cfg["position"], + orientation=sensor_cfg["orientation"], resolution=[settings["height"], settings["width"]], sensor_type=sensor_type, sensor_subtype=sensor_subtype, From 49d9fb8f49c3a3ff04d5be4b75328a71cbaeb61b Mon Sep 17 00:00:00 2001 From: Mino Date: Mon, 7 Nov 2022 16:08:16 -0800 Subject: [PATCH 08/24] dict of dicts --- examples/demo_runner.py | 10 ++--- examples/example.py | 27 ++++-------- src_python/habitat_sim/utils/settings.py | 43 ++++++++------------ tests/conftest.py | 10 ++--- tests/test_physics.py | 20 ++------- tests/test_sensors.py | 52 ++++++++++++++---------- tests/test_simulator.py | 10 +---- 7 files changed, 71 insertions(+), 101 deletions(-) diff --git a/examples/demo_runner.py b/examples/demo_runner.py index 14bb729a15..d3d62501ab 100644 --- a/examples/demo_runner.py +++ b/examples/demo_runner.py @@ -258,13 +258,12 @@ def do_time_steps(self): # get simulation step time without sensor observations total_sim_step_time += self._sim._previous_step_time - sensor_uuids = [sensor["uuid"] for sensor in self._sim_settings["sensors"]] if self._sim_settings["save_png"]: - if "color_sensor" in sensor_uuids: + if "color_sensor" in self._sim_settings["sensors"]: self.save_color_observation(observations, total_frames) - if "depth_sensor" in sensor_uuids: + if "depth_sensor" in self._sim_settings["sensors"]: self.save_depth_observation(observations, total_frames) - if "semantic_sensor" in sensor_uuids: + if "semantic_sensor" in self._sim_settings["sensors"]: self.save_semantic_observation(observations, total_frames) state = self._sim.last_state() @@ -284,7 +283,7 @@ def do_time_steps(self): print("len(action_path)", len(self._action_path)) if ( - "semantic_sensor" in sensor_uuids + "semantic_sensor" in self._sim_settings["sensors"] and self._sim_settings["print_semantic_mask_stats"] ): self.output_semantic_mask_stats(observations, total_frames) @@ -410,6 +409,7 @@ def benchmark(self, settings, group_id=ABTestGroup.CONTROL): def example(self): start_state = self.init_common() + # initialize and compute shortest path to goal if self._sim_settings["compute_shortest_path"]: self._shortest_path = ShortestPath() diff --git a/examples/example.py b/examples/example.py index 3abd7a6d94..49175ad3d9 100755 --- a/examples/example.py +++ b/examples/example.py @@ -57,26 +57,17 @@ def make_settings(): settings["sensors"] = [] if not args.disable_color_sensor: - settings["sensors"].append( - { - "uuid": "color_sensor", - "position": [0, args.sensor_height, 0], - } - ) + settings["sensors"]["color_sensor"] = { + "position": [0, args.sensor_height, 0], + } if args.semantic_sensor: - settings["sensors"].append( - { - "uuid": "semantic_sensor", - "position": [0, args.sensor_height, 0], - } - ) + settings["sensors"]["semantic_sensor"] = { + "position": [0, args.sensor_height, 0], + } if args.depth_sensor: - settings["sensors"].append( - { - "uuid": "depth_sensor", - "position": [0, args.sensor_height, 0], - } - ) + settings["sensors"]["depth_sensor"] = { + "position": [0, args.sensor_height, 0], + } return settings diff --git a/src_python/habitat_sim/utils/settings.py b/src_python/habitat_sim/utils/settings.py index c0f4f98513..a61c3729f8 100644 --- a/src_python/habitat_sim/utils/settings.py +++ b/src_python/habitat_sim/utils/settings.py @@ -2,10 +2,12 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. +from typing import Any, Dict + import habitat_sim import habitat_sim.agent -default_sim_settings = { +default_sim_settings: Dict[str, Any] = { "scene_dataset_config_file": "default", "scene": "NONE", "width": 640, @@ -13,17 +15,17 @@ "default_agent": 0, "seed": 1, "physics_config_file": "data/default.physics_config.json", - "sensors": [ - { - "uuid": "color_sensor", - }, - ], + "sensors": { + "color_sensor": {}, + }, } -default_sensor_settings = { +default_sensor_settings: Dict[str, Any] = { "hfov": 90, "position": [0, 1.5, 0], "orientation": [0, 0, 0], + # "sensor_type": habitat_sim.SensorType.COLOR, + # "sensor_subtype": habitat_sim.SensorSubType.PINHOLE, } @@ -83,29 +85,18 @@ def create_equirect_spec(**kw_args): setattr(equirect_sensor_spec, k, kw_args[k]) return equirect_sensor_spec - for sensor_cfg in settings["sensors"]: + for uuid, sensor_cfg in settings["sensors"].items(): + sensor_cfg = {**default_sensor_settings, **sensor_cfg} - uuid = sensor_cfg["uuid"] - - sensor_type = ( - habitat_sim.SensorType.DEPTH - if "depth" in uuid - else ( - habitat_sim.SensorType.SEMANTIC - if "semantic" in uuid - else habitat_sim.SensorType.COLOR - ) - ) - sensor_subtype = ( - habitat_sim.SensorSubType.ORTHOGRAPHIC - if "ortho" in uuid - else habitat_sim.SensorSubType.PINHOLE + sensor_type = sensor_cfg.get("sensor_type", habitat_sim.SensorType.COLOR) + sensor_subtype = sensor_cfg.get( + "sensor_subtype", habitat_sim.SensorSubType.PINHOLE ) channels = 4 if sensor_type is habitat_sim.SensorType.COLOR else 1 if "fisheye" in uuid: fisheye_spec = create_fisheye_spec( - uuid=sensor_cfg["uuid"], + uuid=uuid, position=sensor_cfg["position"], orientation=sensor_cfg["orientation"], resolution=[settings["height"], settings["width"]], @@ -115,7 +106,7 @@ def create_equirect_spec(**kw_args): sensor_specs.append(fisheye_spec) elif "equirect" in uuid: equirect_spec = create_equirect_spec( - uuid=sensor_cfg["uuid"], + uuid=uuid, position=sensor_cfg["position"], orientation=sensor_cfg["orientation"], resolution=[settings["height"], settings["width"]], @@ -125,7 +116,7 @@ def create_equirect_spec(**kw_args): sensor_specs.append(equirect_spec) else: camera_spec = create_camera_spec( - uuid=sensor_cfg["uuid"], + uuid=uuid, hfov=sensor_cfg["hfov"], position=sensor_cfg["position"], orientation=sensor_cfg["orientation"], diff --git a/tests/conftest.py b/tests/conftest.py index 3b004eedc9..8c5e9fcb1d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -25,11 +25,11 @@ def make_cfg_settings(): import habitat_sim.utils.settings cfg = habitat_sim.utils.settings.default_sim_settings.copy() - cfg["sensors"] = [ - {"uuid": "color_sensor"}, - {"uuid": "semantic_sensor"}, - {"uuid": "depth_sensor"}, - ] + cfg["sensors"] = { + "color_sensor": {}, + "semantic_sensor": {}, + "depth_sensor": {}, + } cfg["silent"] = True cfg["scene"] = _test_scene cfg["frustum_culling"] = True diff --git a/tests/test_physics.py b/tests/test_physics.py index a4f16bf79a..7502d97ba6 100644 --- a/tests/test_physics.py +++ b/tests/test_physics.py @@ -38,7 +38,7 @@ def test_kinematics(): ] = "data/scene_datasets/habitat-test-scenes/skokloster-castle.glb" # enable the physics simulator: also clears available actions to no-op cfg_settings["enable_physics"] = True - cfg_settings["sensors"] = [{"uuid": "depth_sensor"}, {"uuid": "color_sensor"}] + cfg_settings["sensors"] = {"depth_sensor": {}, "color_sensor": {}} # test loading the physical scene hab_cfg = habitat_sim.utils.settings.make_cfg(cfg_settings) @@ -152,14 +152,7 @@ def test_kinematics_no_physics(): ] = "data/scene_datasets/habitat-test-scenes/skokloster-castle.glb" # enable the physics simulator: also clears available actions to no-op cfg_settings["enable_physics"] = False - cfg_settings["sensors"] = [ - { - "uuid": "depth_sensor", - }, - { - "uuid": "color_sensor", - }, - ] + cfg_settings["sensors"] = {"depth_sensor": {}, "color_sensor": {}} # test loading the physical scene hab_cfg = habitat_sim.utils.settings.make_cfg(cfg_settings) @@ -276,14 +269,7 @@ def test_dynamics(): ] = "data/scene_datasets/habitat-test-scenes/skokloster-castle.glb" # enable the physics simulator: also clears available actions to no-op cfg_settings["enable_physics"] = True - cfg_settings["sensors"] = [ - { - "uuid": "depth_sensor", - }, - { - "uuid": "color_sensor", - }, - ] + cfg_settings["sensors"] = {"depth_sensor": {}, "color_sensor": {}} # test loading the physical scene hab_cfg = habitat_sim.utils.settings.make_cfg(cfg_settings) diff --git a/tests/test_sensors.py b/tests/test_sensors.py index d579403d19..2e5f5e9625 100644 --- a/tests/test_sensors.py +++ b/tests/test_sensors.py @@ -187,9 +187,24 @@ def test_sensors( pytest.skip("Skipping GPU->GPU test") scene_dataset_config = scene_and_dataset[1] + sensor = ( + habitat_sim.SensorType.DEPTH + if "depth" in sensor_type + else ( + habitat_sim.SensorType.SEMANTIC + if "semantic" in sensor_type + else habitat_sim.SensorType.COLOR + ) + ) + + sensor_subtype = ( + habitat_sim.SensorSubType.ORTHOGRAPHIC + if "ortho" in sensor_type + else habitat_sim.SensorSubType.PINHOLE + ) + # We only support adding more RGB Sensors if one is already in a scene # We can add depth sensors whenever - make_cfg_settings["sensors"] = [] add_sensor_lazy = add_sensor_lazy and all_base_sensor_types[1] == sensor_type for sens in all_base_sensor_types: if ( @@ -197,17 +212,16 @@ def test_sensors( and sens in all_base_sensor_types[:2] and sens != sensor_type ): - make_cfg_settings["sensors"].append( - { - "uuid": sens, - } - ) + make_cfg_settings["sensors"][sensor_type] = { + "sensor_type": sensor, + "sensor_subtype": sensor_subtype, + } + + make_cfg_settings["sensors"][sensor_type] = { + "sensor_type": sensor, + "sensor_subtype": sensor_subtype, + } - make_cfg_settings["sensors"].append( - { - "uuid": sensor_type, - } - ) make_cfg_settings["scene"] = scene make_cfg_settings["scene_dataset_config_file"] = scene_dataset_config make_cfg_settings["frustum_culling"] = frustum_culling @@ -312,11 +326,9 @@ def test_smoke_redwood_noise(scene_and_dataset, gpu2gpu, make_cfg_settings): if gpu2gpu and (not habitat_sim.cuda_enabled or not _HAS_TORCH): pytest.skip("Skipping GPU->GPU test") scene_dataset_config = scene_and_dataset[1] - make_cfg_settings["sensors"] = [ - { - "uuid": "depth_sensor", - } - ] + make_cfg_settings["sensors"]["depth_sensor"] = { + "sensor_type": habitat_sim.SensorType.DEPTH + } make_cfg_settings["scene"] = scene make_cfg_settings["scene_dataset_config_file"] = scene_dataset_config hsim_cfg = make_cfg(make_cfg_settings) @@ -341,7 +353,7 @@ def test_initial_hfov(scene_and_dataset, sensor_type, make_cfg_settings): scene = scene_and_dataset[0] if not osp.exists(scene): pytest.skip("Skipping {}".format(scene)) - for sens_cfg in make_cfg_settings["sensors"]: + for _, sens_cfg in make_cfg_settings["sensors"].items(): sens_cfg["hfov"] = 70 with habitat_sim.Simulator(make_cfg(make_cfg_settings)) as sim: assert sim.agents[0]._sensors[sensor_type].hfov == mn.Deg( @@ -365,11 +377,7 @@ def test_rgba_noise(scene_and_dataset, model_name, make_cfg_settings): if not osp.exists(scene): pytest.skip("Skipping {}".format(scene)) scene_dataset_config = scene_and_dataset[1] - make_cfg_settings["sensors"] = [ - { - "uuid": "color_sensor", - } - ] + make_cfg_settings["sensors"]["color_sensor"] = {} make_cfg_settings["scene"] = scene make_cfg_settings["scene_dataset_config_file"] = scene_dataset_config hsim_cfg = make_cfg(make_cfg_settings) diff --git a/tests/test_simulator.py b/tests/test_simulator.py index 0f4cb8225b..c94ebca87a 100644 --- a/tests/test_simulator.py +++ b/tests/test_simulator.py @@ -51,14 +51,8 @@ def test_empty_scene(): # keyword "NONE" initializes a scene with no scene mesh cfg_settings["scene"] = "NONE" # test that depth sensor doesn't mind an empty scene - cfg_settings["sensors"] = [ - { - "uuid": "depth_sensor", - }, - { - "uuid": "color_sensor", - }, - ] + cfg_settings["sensors"]["depth_sensor"] = {} + cfg_settings["sensors"]["color_sensor"] = {} hab_cfg = habitat_sim.utils.settings.make_cfg(cfg_settings) hab_cfg_mm = habitat_sim.utils.settings.make_cfg(cfg_settings) From 1c1e9e896fe62524f647a22cbd476f6b78b47552 Mon Sep 17 00:00:00 2001 From: Mino Date: Mon, 7 Nov 2022 16:27:14 -0800 Subject: [PATCH 09/24] dict of dicts --- tests/test_gfx.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/test_gfx.py b/tests/test_gfx.py index 38adf12116..f6bd76d624 100644 --- a/tests/test_gfx.py +++ b/tests/test_gfx.py @@ -26,12 +26,7 @@ def test_unproject(): cfg_settings["scene"] = "data/scene_datasets/habitat-test-scenes/apartment_1.glb" cfg_settings["width"] = 101 cfg_settings["height"] = 101 - cfg_settings["sensors"] = [ - { - "uuid": "color_sensor", - "position": [0, 0, 0], - } - ] + cfg_settings["sensors"]["color_sensor"] = {"position": [0, 0, 0]} # loading the scene hab_cfg = habitat_sim.utils.settings.make_cfg(cfg_settings) From ced12803a919e140e258a85501de05ba90256f6c Mon Sep 17 00:00:00 2001 From: Mino Date: Mon, 7 Nov 2022 16:47:22 -0800 Subject: [PATCH 10/24] dict of dicts --- tests/test_sensors.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/test_sensors.py b/tests/test_sensors.py index 2e5f5e9625..69777a5c94 100644 --- a/tests/test_sensors.py +++ b/tests/test_sensors.py @@ -271,11 +271,7 @@ def test_reconfigure_render( make_cfg_settings["scene"] = _test_scenes[-1][0] make_cfg_settings["scene_dataset_config_file"] = _test_scenes[-1][1] - make_cfg_settings["sensors"] = [ - { - "uuid": sensor_type, - } - ] + make_cfg_settings["sensors"] = {sensor_type: {}} cfg = make_cfg(make_cfg_settings) @@ -377,7 +373,6 @@ def test_rgba_noise(scene_and_dataset, model_name, make_cfg_settings): if not osp.exists(scene): pytest.skip("Skipping {}".format(scene)) scene_dataset_config = scene_and_dataset[1] - make_cfg_settings["sensors"]["color_sensor"] = {} make_cfg_settings["scene"] = scene make_cfg_settings["scene_dataset_config_file"] = scene_dataset_config hsim_cfg = make_cfg(make_cfg_settings) From 71280a7b910c1411dc452cb5cd2c82c3628730ca Mon Sep 17 00:00:00 2001 From: Mino Date: Mon, 7 Nov 2022 17:15:46 -0800 Subject: [PATCH 11/24] fix failing tests --- tests/test_sensors.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/tests/test_sensors.py b/tests/test_sensors.py index 69777a5c94..f05fdba0b7 100644 --- a/tests/test_sensors.py +++ b/tests/test_sensors.py @@ -265,13 +265,29 @@ def test_reconfigure_render( if not osp.exists(scene): pytest.skip("Skipping {}".format(scene)) - for sens in all_base_sensor_types: - make_cfg_settings[sens] = False scene_dataset_config = scene_and_dataset[1] make_cfg_settings["scene"] = _test_scenes[-1][0] make_cfg_settings["scene_dataset_config_file"] = _test_scenes[-1][1] - make_cfg_settings["sensors"] = {sensor_type: {}} + sensor = ( + habitat_sim.SensorType.DEPTH + if "depth" in sensor_type + else ( + habitat_sim.SensorType.SEMANTIC + if "semantic" in sensor_type + else habitat_sim.SensorType.COLOR + ) + ) + + sensor_subtype = ( + habitat_sim.SensorSubType.ORTHOGRAPHIC + if "ortho" in sensor_type + else habitat_sim.SensorSubType.PINHOLE + ) + + make_cfg_settings["sensors"] = { + sensor_type: {"sensor_type": sensor, "sensor_subtype": sensor_subtype} + } cfg = make_cfg(make_cfg_settings) @@ -322,6 +338,8 @@ def test_smoke_redwood_noise(scene_and_dataset, gpu2gpu, make_cfg_settings): if gpu2gpu and (not habitat_sim.cuda_enabled or not _HAS_TORCH): pytest.skip("Skipping GPU->GPU test") scene_dataset_config = scene_and_dataset[1] + del make_cfg_settings["sensors"]["color_sensor"] + del make_cfg_settings["sensors"]["semantic_sensor"] make_cfg_settings["sensors"]["depth_sensor"] = { "sensor_type": habitat_sim.SensorType.DEPTH } From 68e61df26dd0f6f7994abc96154b413eb4e2fd34 Mon Sep 17 00:00:00 2001 From: Mino Date: Mon, 7 Nov 2022 17:49:50 -0800 Subject: [PATCH 12/24] fix example --- examples/example.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/example.py b/examples/example.py index 49175ad3d9..60528afd70 100755 --- a/examples/example.py +++ b/examples/example.py @@ -55,18 +55,17 @@ def make_settings(): settings["frustum_culling"] = not args.disable_frustum_culling settings["recompute_navmesh"] = args.recompute_navmesh - settings["sensors"] = [] if not args.disable_color_sensor: settings["sensors"]["color_sensor"] = { - "position": [0, args.sensor_height, 0], + "position": [0.0, args.sensor_height, 0.0], } if args.semantic_sensor: settings["sensors"]["semantic_sensor"] = { - "position": [0, args.sensor_height, 0], + "position": [0.0, args.sensor_height, 0.0], } if args.depth_sensor: settings["sensors"]["depth_sensor"] = { - "position": [0, args.sensor_height, 0], + "position": [0.0, args.sensor_height, 0.0], } return settings From 88758665408eae7f7ef6cc7fc1109c1bd5205330 Mon Sep 17 00:00:00 2001 From: Mino Date: Tue, 8 Nov 2022 13:06:03 -0800 Subject: [PATCH 13/24] update depth sensor stuff --- examples/example.py | 4 ++++ tests/conftest.py | 4 ++-- tests/test_physics.py | 15 ++++++++++++--- tests/test_sensors.py | 6 ++---- tests/test_simulator.py | 4 +++- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/examples/example.py b/examples/example.py index 60528afd70..688c0d17b3 100755 --- a/examples/example.py +++ b/examples/example.py @@ -9,6 +9,8 @@ import demo_runner as dr +import habitat_sim + parser = argparse.ArgumentParser() parser.add_argument("--scene", type=str, default=dr.default_sim_settings["scene"]) parser.add_argument("--width", type=int, default=640) @@ -62,10 +64,12 @@ def make_settings(): if args.semantic_sensor: settings["sensors"]["semantic_sensor"] = { "position": [0.0, args.sensor_height, 0.0], + "sensor_type": habitat_sim.SensorType.SEMANTIC, } if args.depth_sensor: settings["sensors"]["depth_sensor"] = { "position": [0.0, args.sensor_height, 0.0], + "sensor_type": habitat_sim.SensorType.DEPTH, } return settings diff --git a/tests/conftest.py b/tests/conftest.py index 8c5e9fcb1d..6deb12e3aa 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -27,8 +27,8 @@ def make_cfg_settings(): cfg = habitat_sim.utils.settings.default_sim_settings.copy() cfg["sensors"] = { "color_sensor": {}, - "semantic_sensor": {}, - "depth_sensor": {}, + "semantic_sensor": {"sensor_type": habitat_sim.SensorType.SEMANTIC}, + "depth_sensor": {"sensor_type": habitat_sim.SensorType.DEPTH}, } cfg["silent"] = True cfg["scene"] = _test_scene diff --git a/tests/test_physics.py b/tests/test_physics.py index 7502d97ba6..d8482739bd 100644 --- a/tests/test_physics.py +++ b/tests/test_physics.py @@ -38,7 +38,10 @@ def test_kinematics(): ] = "data/scene_datasets/habitat-test-scenes/skokloster-castle.glb" # enable the physics simulator: also clears available actions to no-op cfg_settings["enable_physics"] = True - cfg_settings["sensors"] = {"depth_sensor": {}, "color_sensor": {}} + cfg_settings["sensors"] = { + "depth_sensor": {"sensor_type": habitat_sim.SensorType.DEPTH}, + "color_sensor": {}, + } # test loading the physical scene hab_cfg = habitat_sim.utils.settings.make_cfg(cfg_settings) @@ -152,7 +155,10 @@ def test_kinematics_no_physics(): ] = "data/scene_datasets/habitat-test-scenes/skokloster-castle.glb" # enable the physics simulator: also clears available actions to no-op cfg_settings["enable_physics"] = False - cfg_settings["sensors"] = {"depth_sensor": {}, "color_sensor": {}} + cfg_settings["sensors"] = { + "depth_sensor": {"sensor_type": habitat_sim.SensorType.DEPTH}, + "color_sensor": {}, + } # test loading the physical scene hab_cfg = habitat_sim.utils.settings.make_cfg(cfg_settings) @@ -269,7 +275,10 @@ def test_dynamics(): ] = "data/scene_datasets/habitat-test-scenes/skokloster-castle.glb" # enable the physics simulator: also clears available actions to no-op cfg_settings["enable_physics"] = True - cfg_settings["sensors"] = {"depth_sensor": {}, "color_sensor": {}} + cfg_settings["sensors"] = { + "depth_sensor": {"sensor_type": habitat_sim.SensorType.DEPTH}, + "color_sensor": {}, + } # test loading the physical scene hab_cfg = habitat_sim.utils.settings.make_cfg(cfg_settings) diff --git a/tests/test_sensors.py b/tests/test_sensors.py index f05fdba0b7..6a56fb80eb 100644 --- a/tests/test_sensors.py +++ b/tests/test_sensors.py @@ -338,10 +338,8 @@ def test_smoke_redwood_noise(scene_and_dataset, gpu2gpu, make_cfg_settings): if gpu2gpu and (not habitat_sim.cuda_enabled or not _HAS_TORCH): pytest.skip("Skipping GPU->GPU test") scene_dataset_config = scene_and_dataset[1] - del make_cfg_settings["sensors"]["color_sensor"] - del make_cfg_settings["sensors"]["semantic_sensor"] - make_cfg_settings["sensors"]["depth_sensor"] = { - "sensor_type": habitat_sim.SensorType.DEPTH + make_cfg_settings["sensors"] = { + "depth_sensor": {"sensor_type": habitat_sim.SensorType.DEPTH} } make_cfg_settings["scene"] = scene make_cfg_settings["scene_dataset_config_file"] = scene_dataset_config diff --git a/tests/test_simulator.py b/tests/test_simulator.py index c94ebca87a..c7aba0d836 100644 --- a/tests/test_simulator.py +++ b/tests/test_simulator.py @@ -51,7 +51,9 @@ def test_empty_scene(): # keyword "NONE" initializes a scene with no scene mesh cfg_settings["scene"] = "NONE" # test that depth sensor doesn't mind an empty scene - cfg_settings["sensors"]["depth_sensor"] = {} + cfg_settings["sensors"]["depth_sensor"] = { + {"sensor_type": habitat_sim.SensorType.DEPTH}, + } cfg_settings["sensors"]["color_sensor"] = {} hab_cfg = habitat_sim.utils.settings.make_cfg(cfg_settings) From b236eacf80d7bb39ab8766e79821e9130f1409c2 Mon Sep 17 00:00:00 2001 From: Mino Date: Tue, 8 Nov 2022 14:14:54 -0800 Subject: [PATCH 14/24] simulator test --- tests/test_simulator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_simulator.py b/tests/test_simulator.py index c7aba0d836..e7d340fd40 100644 --- a/tests/test_simulator.py +++ b/tests/test_simulator.py @@ -52,7 +52,7 @@ def test_empty_scene(): cfg_settings["scene"] = "NONE" # test that depth sensor doesn't mind an empty scene cfg_settings["sensors"]["depth_sensor"] = { - {"sensor_type": habitat_sim.SensorType.DEPTH}, + "sensor_type": habitat_sim.SensorType.DEPTH } cfg_settings["sensors"]["color_sensor"] = {} From 85efe2c4b2eb03f87bae9596b3df525b4606b8ca Mon Sep 17 00:00:00 2001 From: Mino Date: Tue, 8 Nov 2022 15:53:54 -0800 Subject: [PATCH 15/24] test_sensors tests failing --- tests/test_sensors.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_sensors.py b/tests/test_sensors.py index 6a56fb80eb..2d48812dd9 100644 --- a/tests/test_sensors.py +++ b/tests/test_sensors.py @@ -187,7 +187,7 @@ def test_sensors( pytest.skip("Skipping GPU->GPU test") scene_dataset_config = scene_and_dataset[1] - sensor = ( + sim_sensor_type = ( habitat_sim.SensorType.DEPTH if "depth" in sensor_type else ( @@ -202,7 +202,7 @@ def test_sensors( if "ortho" in sensor_type else habitat_sim.SensorSubType.PINHOLE ) - + make_cfg_settings["sensors"] = {} # We only support adding more RGB Sensors if one is already in a scene # We can add depth sensors whenever add_sensor_lazy = add_sensor_lazy and all_base_sensor_types[1] == sensor_type @@ -213,12 +213,12 @@ def test_sensors( and sens != sensor_type ): make_cfg_settings["sensors"][sensor_type] = { - "sensor_type": sensor, + "sensor_type": sim_sensor_type, "sensor_subtype": sensor_subtype, } make_cfg_settings["sensors"][sensor_type] = { - "sensor_type": sensor, + "sensor_type": sim_sensor_type, "sensor_subtype": sensor_subtype, } From 7dc8edb957d85c036a926f3377e8b4cfb51c109c Mon Sep 17 00:00:00 2001 From: John Reyna Date: Thu, 1 Dec 2022 05:19:07 -0800 Subject: [PATCH 16/24] added agent_id to default sensor settings. --- src_python/habitat_sim/utils/settings.py | 49 +++++++++++++----------- tests/test_sensors.py | 23 +++++++++-- 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/src_python/habitat_sim/utils/settings.py b/src_python/habitat_sim/utils/settings.py index 89da2d2508..7768c27ce8 100644 --- a/src_python/habitat_sim/utils/settings.py +++ b/src_python/habitat_sim/utils/settings.py @@ -26,8 +26,11 @@ "hfov": 90, "position": [0, 1.5, 0], "orientation": [0, 0, 0], - # "sensor_type": habitat_sim.SensorType.COLOR, - # "sensor_subtype": habitat_sim.SensorSubType.PINHOLE, + "sensor_type": habitat_sim.sensor.SensorType.COLOR, + "sensor_subtype": habitat_sim.sensor.SensorSubType.PINHOLE, + # can be agent ID or "None". + # TODO: If the value is "None", then make it a global sensor attached to root scene node + "agent_id": default_sim_settings["default_agent"], } @@ -36,14 +39,14 @@ def make_cfg(settings: Dict[str, Any]): r"""Isolates the boilerplate code to create a habitat_sim.Configuration from a settings dictionary. :param settings: A dict with pre-defined keys, each a basic simulator initialization parameter. - Allows configuration of dataset and scene, visual sensor parameters, and basic agent parameters. - Optionally creates up to one of each of a variety of aligned visual sensors under Agent 0. - - The output can be passed directly into habitat_sim.simulator.Simulator constructor or reconfigure to initialize a Simulator instance. + The output can be passed directly into habitat_sim.simulator.Simulator constructor or reconfigure + to initialize a Simulator instance. """ sim_cfg = habitat_sim.SimulatorConfiguration() + + # define scene and gpu device parameters if "scene_dataset_config_file" in settings: sim_cfg.scene_dataset_config_file = settings["scene_dataset_config_file"] sim_cfg.frustum_culling = settings.get("frustum_culling", False) @@ -97,44 +100,44 @@ def create_equirect_spec(**kw_args): setattr(equirect_sensor_spec, k, kw_args[k]) return equirect_sensor_spec - for uuid, sensor_cfg in settings["sensors"].items(): + for uuid, sensor_settings in settings["sensors"].items(): - sensor_cfg = {**default_sensor_settings, **sensor_cfg} - sensor_type = sensor_cfg.get("sensor_type", habitat_sim.SensorType.COLOR) - sensor_subtype = sensor_cfg.get( - "sensor_subtype", habitat_sim.SensorSubType.PINHOLE + sensor_settings = {**default_sensor_settings, **sensor_settings} + channels = ( + 4 + if sensor_settings["sensor_type"] is habitat_sim.sensor.SensorType.COLOR + else 1 ) - channels = 4 if sensor_type is habitat_sim.SensorType.COLOR else 1 if "fisheye" in uuid: fisheye_spec = create_fisheye_spec( uuid=uuid, - position=sensor_cfg["position"], - orientation=sensor_cfg["orientation"], + position=sensor_settings["position"], + orientation=sensor_settings["orientation"], resolution=[settings["height"], settings["width"]], - sensor_type=sensor_type, + sensor_type=sensor_settings["sensor_type"], channels=channels, ) sensor_specs.append(fisheye_spec) elif "equirect" in uuid: equirect_spec = create_equirect_spec( uuid=uuid, - position=sensor_cfg["position"], - orientation=sensor_cfg["orientation"], + position=sensor_settings["position"], + orientation=sensor_settings["orientation"], resolution=[settings["height"], settings["width"]], - sensor_type=sensor_type, + sensor_type=sensor_settings["sensor_type"], channels=channels, ) sensor_specs.append(equirect_spec) else: camera_spec = create_camera_spec( uuid=uuid, - hfov=sensor_cfg["hfov"], - position=sensor_cfg["position"], - orientation=sensor_cfg["orientation"], + hfov=sensor_settings["hfov"], + position=sensor_settings["position"], + orientation=sensor_settings["orientation"], resolution=[settings["height"], settings["width"]], - sensor_type=sensor_type, - sensor_subtype=sensor_subtype, + sensor_type=sensor_settings["sensor_type"], + sensor_subtype=sensor_settings["sensor_subtype"], channels=channels, ) sensor_specs.append(camera_spec) diff --git a/tests/test_sensors.py b/tests/test_sensors.py index 2d48812dd9..c1072bec98 100644 --- a/tests/test_sensors.py +++ b/tests/test_sensors.py @@ -206,11 +206,11 @@ def test_sensors( # We only support adding more RGB Sensors if one is already in a scene # We can add depth sensors whenever add_sensor_lazy = add_sensor_lazy and all_base_sensor_types[1] == sensor_type - for sens in all_base_sensor_types: + for base_sensor_type in all_base_sensor_types: if ( add_sensor_lazy - and sens in all_base_sensor_types[:2] - and sens != sensor_type + and base_sensor_type in all_base_sensor_types[:2] + and base_sensor_type != sensor_type ): make_cfg_settings["sensors"][sensor_type] = { "sensor_type": sim_sensor_type, @@ -238,7 +238,22 @@ def test_sensors( obs: Dict[str, Any] = sim.reset() assert len(obs) == 1, "Other sensors were not removed" for sensor_spec in additional_sensors: - sim.add_sensor(sensor_spec) + # TODO: unnecessary for now, as additional_sensors all come from + # agent 0, but eventually we may have more than one agent + if sensor_spec.uuid in make_cfg_settings["sensors"]: + agent_id = make_cfg_settings["sensors"][sensor_spec.uuid].get( + "agent_id" + ) + # TODO: after sensor refactor, not specifying an agent will attach + # sensor as global sensor to root scene node + if sensor_spec.agent_id == "None": + sim.add_sensor(sensor_spec) + else: + sim.add_sensor(sensor_spec, agent_id) + else: + agent_id = 0 + sim.add_sensor(sensor_spec, agent_id) + if sensor_type not in all_base_sensor_types: obs = _render_scene(sim, scene, sensor_type, gpu2gpu) # Smoke Test. From e5a5e6c981820fc38ffa22482c9213af9f3d1f1a Mon Sep 17 00:00:00 2001 From: John Reyna Date: Thu, 1 Dec 2022 11:45:56 -0800 Subject: [PATCH 17/24] update tests/test_sensors.py to reflect sensor settings now having an agent_id --- src_python/habitat_sim/utils/settings.py | 21 +++++++++++++++++---- tests/test_sensors.py | 11 ++++++++--- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src_python/habitat_sim/utils/settings.py b/src_python/habitat_sim/utils/settings.py index 7768c27ce8..0d835b409d 100644 --- a/src_python/habitat_sim/utils/settings.py +++ b/src_python/habitat_sim/utils/settings.py @@ -18,6 +18,9 @@ "physics_config_file": "data/default.physics_config.json", "sensors": { "color_sensor": {}, + # Other example sensor entries: + # "depth_sensor": {}, + # "semantic_sensor": {}, }, } # [/default_sim_settings] @@ -49,14 +52,20 @@ def make_cfg(settings: Dict[str, Any]): # define scene and gpu device parameters if "scene_dataset_config_file" in settings: sim_cfg.scene_dataset_config_file = settings["scene_dataset_config_file"] - sim_cfg.frustum_culling = settings.get("frustum_culling", False) + if "enable_physics" in settings: sim_cfg.enable_physics = settings["enable_physics"] + if "physics_config_file" in settings: sim_cfg.physics_config_file = settings["physics_config_file"] + if "scene_light_setup" in settings: sim_cfg.scene_light_setup = settings["scene_light_setup"] + + sim_cfg.frustum_culling = settings.get("frustum_culling", False) + sim_cfg.gpu_device_id = 0 + if not hasattr(sim_cfg, "scene_id"): raise RuntimeError( "Error: Please upgrade habitat-sim. SimulatorConfig API version mismatch" @@ -109,7 +118,9 @@ def create_equirect_spec(**kw_args): else 1 ) - if "fisheye" in uuid: + if ( + "fisheye" in uuid + ): # fisheye_rgba_sensor, fisheye_depth_sensor, fisheye_semantic_sensor fisheye_spec = create_fisheye_spec( uuid=uuid, position=sensor_settings["position"], @@ -119,7 +130,9 @@ def create_equirect_spec(**kw_args): channels=channels, ) sensor_specs.append(fisheye_spec) - elif "equirect" in uuid: + elif ( + "equirect" in uuid + ): # equirect_rgba_sensor, equirect_depth_sensor, equirect_semantic_sensor equirect_spec = create_equirect_spec( uuid=uuid, position=sensor_settings["position"], @@ -129,7 +142,7 @@ def create_equirect_spec(**kw_args): channels=channels, ) sensor_specs.append(equirect_spec) - else: + else: # color_sensor, depth_sensor, semantic_sensor, ortho_rgba_sensor, ortho_depth_sensor, ortho_semantic_sensor camera_spec = create_camera_spec( uuid=uuid, hfov=sensor_settings["hfov"], diff --git a/tests/test_sensors.py b/tests/test_sensors.py index c1072bec98..c7357f2148 100644 --- a/tests/test_sensors.py +++ b/tests/test_sensors.py @@ -203,6 +203,7 @@ def test_sensors( else habitat_sim.SensorSubType.PINHOLE ) make_cfg_settings["sensors"] = {} + agent_id = 0 # We only support adding more RGB Sensors if one is already in a scene # We can add depth sensors whenever add_sensor_lazy = add_sensor_lazy and all_base_sensor_types[1] == sensor_type @@ -215,11 +216,13 @@ def test_sensors( make_cfg_settings["sensors"][sensor_type] = { "sensor_type": sim_sensor_type, "sensor_subtype": sensor_subtype, + "agent_id": agent_id, } make_cfg_settings["sensors"][sensor_type] = { "sensor_type": sim_sensor_type, "sensor_subtype": sensor_subtype, + "agent_id": agent_id, } make_cfg_settings["scene"] = scene @@ -228,9 +231,11 @@ def test_sensors( cfg = make_cfg(make_cfg_settings) if add_sensor_lazy: - additional_sensors = cfg.agents[0].sensor_specifications[1:] - cfg.agents[0].sensor_specifications = cfg.agents[0].sensor_specifications[:1] - for sensor_spec in cfg.agents[0].sensor_specifications: + additional_sensors = cfg.agents[agent_id].sensor_specifications[1:] + cfg.agents[agent_id].sensor_specifications = cfg.agents[ + agent_id + ].sensor_specifications[:1] + for sensor_spec in cfg.agents[agent_id].sensor_specifications: sensor_spec.gpu2gpu_transfer = gpu2gpu with habitat_sim.Simulator(cfg) as sim: From 091a2a789dbed5c834130ad9ec4777a77ed788d0 Mon Sep 17 00:00:00 2001 From: John Reyna Date: Thu, 1 Dec 2022 12:13:59 -0800 Subject: [PATCH 18/24] update ECCV_2020_Interactivity.py tutorial to use updated settings file --- .../colabs/ECCV_2020_Interactivity.ipynb | 147 +++++------------- .../nb_python/ECCV_2020_Interactivity.py | 147 +++++------------- 2 files changed, 70 insertions(+), 224 deletions(-) diff --git a/examples/tutorials/colabs/ECCV_2020_Interactivity.ipynb b/examples/tutorials/colabs/ECCV_2020_Interactivity.ipynb index f0884fcecb..04d2034374 100644 --- a/examples/tutorials/colabs/ECCV_2020_Interactivity.ipynb +++ b/examples/tutorials/colabs/ECCV_2020_Interactivity.ipynb @@ -63,6 +63,7 @@ "import habitat_sim\n", "from habitat_sim.utils import common as ut\n", "from habitat_sim.utils import viz_utils as vut\n", + "from habitat_sim.utils.settings import default_sim_settings, make_cfg\n", "\n", "try:\n", " import ipywidgets as widgets\n", @@ -113,116 +114,24 @@ "# @markdown (double click to show code)\n", "\n", "# @markdown This cell defines a number of utility functions used throughout the tutorial to make simulator reconstruction easy:\n", - "# @markdown - make_cfg\n", - "# @markdown - make_default_settings\n", + "# @markdown - make_custom_settings\n", "# @markdown - make_simulator_from_settings\n", "\n", "\n", - "def make_cfg(settings):\n", - " sim_cfg = habitat_sim.SimulatorConfiguration()\n", - " sim_cfg.gpu_device_id = 0\n", - " sim_cfg.scene_id = settings[\"scene\"]\n", - " sim_cfg.enable_physics = settings[\"enable_physics\"]\n", - " # Optional; Specify the location of an existing scene dataset configuration\n", - " # that describes the locations and configurations of all the assets to be used\n", - " if \"scene_dataset_config\" in settings:\n", - " sim_cfg.scene_dataset_config_file = settings[\"scene_dataset_config\"]\n", - "\n", - " # Note: all sensors must have the same resolution\n", - " sensor_specs = []\n", - " if settings[\"color_sensor_1st_person\"]:\n", - " color_sensor_1st_person_spec = habitat_sim.CameraSensorSpec()\n", - " color_sensor_1st_person_spec.uuid = \"color_sensor_1st_person\"\n", - " color_sensor_1st_person_spec.sensor_type = habitat_sim.SensorType.COLOR\n", - " color_sensor_1st_person_spec.resolution = [\n", - " settings[\"height\"],\n", - " settings[\"width\"],\n", - " ]\n", - " color_sensor_1st_person_spec.position = [0.0, settings[\"sensor_height\"], 0.0]\n", - " color_sensor_1st_person_spec.orientation = [\n", - " settings[\"sensor_pitch\"],\n", - " 0.0,\n", - " 0.0,\n", - " ]\n", - " color_sensor_1st_person_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE\n", - " sensor_specs.append(color_sensor_1st_person_spec)\n", - " if settings[\"depth_sensor_1st_person\"]:\n", - " depth_sensor_1st_person_spec = habitat_sim.CameraSensorSpec()\n", - " depth_sensor_1st_person_spec.uuid = \"depth_sensor_1st_person\"\n", - " depth_sensor_1st_person_spec.sensor_type = habitat_sim.SensorType.DEPTH\n", - " depth_sensor_1st_person_spec.resolution = [\n", - " settings[\"height\"],\n", - " settings[\"width\"],\n", - " ]\n", - " depth_sensor_1st_person_spec.position = [0.0, settings[\"sensor_height\"], 0.0]\n", - " depth_sensor_1st_person_spec.orientation = [\n", - " settings[\"sensor_pitch\"],\n", - " 0.0,\n", - " 0.0,\n", - " ]\n", - " depth_sensor_1st_person_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE\n", - " sensor_specs.append(depth_sensor_1st_person_spec)\n", - " if settings[\"semantic_sensor_1st_person\"]:\n", - " semantic_sensor_1st_person_spec = habitat_sim.CameraSensorSpec()\n", - " semantic_sensor_1st_person_spec.uuid = \"semantic_sensor_1st_person\"\n", - " semantic_sensor_1st_person_spec.sensor_type = habitat_sim.SensorType.SEMANTIC\n", - " semantic_sensor_1st_person_spec.resolution = [\n", - " settings[\"height\"],\n", - " settings[\"width\"],\n", - " ]\n", - " semantic_sensor_1st_person_spec.position = [\n", - " 0.0,\n", - " settings[\"sensor_height\"],\n", - " 0.0,\n", - " ]\n", - " semantic_sensor_1st_person_spec.orientation = [\n", - " settings[\"sensor_pitch\"],\n", - " 0.0,\n", - " 0.0,\n", - " ]\n", - " semantic_sensor_1st_person_spec.sensor_subtype = (\n", - " habitat_sim.SensorSubType.PINHOLE\n", - " )\n", - " sensor_specs.append(semantic_sensor_1st_person_spec)\n", - " if settings[\"color_sensor_3rd_person\"]:\n", - " color_sensor_3rd_person_spec = habitat_sim.CameraSensorSpec()\n", - " color_sensor_3rd_person_spec.uuid = \"color_sensor_3rd_person\"\n", - " color_sensor_3rd_person_spec.sensor_type = habitat_sim.SensorType.COLOR\n", - " color_sensor_3rd_person_spec.resolution = [\n", - " settings[\"height\"],\n", - " settings[\"width\"],\n", - " ]\n", - " color_sensor_3rd_person_spec.position = [\n", - " 0.0,\n", - " settings[\"sensor_height\"] + 0.2,\n", - " 0.2,\n", - " ]\n", - " color_sensor_3rd_person_spec.orientation = [-math.pi / 4, 0, 0]\n", - " color_sensor_3rd_person_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE\n", - " sensor_specs.append(color_sensor_3rd_person_spec)\n", - "\n", - " # Here you can specify the amount of displacement in a forward action and the turn angle\n", - " agent_cfg = habitat_sim.agent.AgentConfiguration()\n", - " agent_cfg.sensor_specifications = sensor_specs\n", - " return habitat_sim.Configuration(sim_cfg, [agent_cfg])\n", - "\n", - "\n", - "def make_default_settings():\n", + "def make_custom_settings():\n", " settings = {\n", " \"width\": 720, # Spatial resolution of the observations\n", " \"height\": 544,\n", " \"scene\": \"./data/scene_datasets/mp3d_example/17DRP5sb8fy/17DRP5sb8fy.glb\", # Scene path\n", - " \"scene_dataset_config\": \"./data/scene_datasets/mp3d_example/mp3d.scene_dataset_config.json\", # MP3D scene dataset\n", - " \"default_agent\": 0,\n", - " \"sensor_height\": 1.5, # Height of sensors in meters\n", - " \"sensor_pitch\": -math.pi / 8.0, # sensor pitch (x rotation in rads)\n", - " \"color_sensor_1st_person\": True, # RGB sensor\n", - " \"color_sensor_3rd_person\": False, # RGB sensor 3rd person\n", - " \"depth_sensor_1st_person\": False, # Depth sensor\n", - " \"semantic_sensor_1st_person\": False, # Semantic sensor\n", - " \"seed\": 1,\n", + " \"scene_dataset_config_file\": \"./data/scene_datasets/mp3d_example/mp3d.scene_dataset_config.json\", # MP3D scene dataset\n", + " \"sensors\": {\n", + " \"color_sensor_1st_person\": {\n", + " \"orientation\": [-math.pi / 8.0, 0.0, 0.0],\n", + " },\n", + " },\n", " \"enable_physics\": True, # enable dynamics simulation\n", " }\n", + " settings = {**default_sim_settings, **settings}\n", " return settings\n", "\n", "\n", @@ -551,7 +460,7 @@ "# @title Initialize Simulator and Load Scene { display-mode: \"form\" }\n", "\n", "# convienience functions defined in Utility cell manage global variables\n", - "sim_settings = make_default_settings()\n", + "sim_settings = make_custom_settings()\n", "# set globals: sim,\n", "make_simulator_from_settings(sim_settings)" ] @@ -655,7 +564,7 @@ "\n", "# display a still frame of the scene after the object is added if RGB sensor is enabled\n", "observations = sim.get_sensor_observations()\n", - "if display and sim_settings[\"color_sensor_1st_person\"]:\n", + "if display and \"color_sensor_1st_person\" in sim_settings[\"sensors\"]:\n", " display_sample(observations[\"color_sensor_1st_person\"])\n", "\n", "example_type = \"adding objects test\"\n", @@ -986,9 +895,10 @@ "source": [ "# @title Initialize Simulator and Load Scene { display-mode: \"form\" }\n", "# @markdown (load the apartment_1 scene for clutter generation in an open space)\n", - "sim_settings = make_default_settings()\n", + "sim_settings = make_custom_settings()\n", "sim_settings[\"scene\"] = \"./data/scene_datasets/habitat-test-scenes/apartment_1.glb\"\n", - "sim_settings[\"sensor_pitch\"] = 0\n", + "for sensor_settings in sim_settings[\"sensors\"]:\n", + " sensor_settings[\"orientation\"] = [0.0, 0.0, 0.0]\n", "\n", "make_simulator_from_settings(sim_settings)" ] @@ -1314,17 +1224,30 @@ "# @markdown This example cell runs the object retrieval task.\n", "\n", "# @markdown First the Simulator is re-initialized with:\n", - "# @markdown - a 3rd person camera view\n", "# @markdown - modified 1st person sensor placement\n", - "sim_settings = make_default_settings()\n", + "# @markdown - a 3rd person camera view\n", + "# @markdown - a 1st person depth sensor view\n", + "# @markdown - a 1st person semantic sensor view\n", + "sim_settings = make_custom_settings()\n", "# fmt: off\n", "sim_settings[\"scene\"] = \"./data/scene_datasets/mp3d_example/17DRP5sb8fy/17DRP5sb8fy.glb\" # @param{type:\"string\"}\n", "# fmt: on\n", - "sim_settings[\"sensor_pitch\"] = 0\n", - "sim_settings[\"sensor_height\"] = 0.6\n", - "sim_settings[\"color_sensor_3rd_person\"] = True\n", - "sim_settings[\"depth_sensor_1st_person\"] = True\n", - "sim_settings[\"semantic_sensor_1st_person\"] = True\n", + "sim_settings[\"sensors\"] = {\n", + " \"color_sensor_1st_person\": {\n", + " \"position\": [0.0, 0.6, 0.0],\n", + " },\n", + " \"color_sensor_3rd_person\": {\n", + " \"position\": [0.0, 0.8, 0.2],\n", + " },\n", + " \"depth_sensor_1st_person\": {\n", + " \"position\": [0.0, 0.6, 0.0],\n", + " \"sensor_type\": habitat_sim.SensorType.DEPTH,\n", + " },\n", + " \"semantic_sensor_1st_person\": {\n", + " \"position\": [0.0, 0.6, 0.0],\n", + " \"sensor_type\": habitat_sim.SensorType.SEMANTIC,\n", + " },\n", + "}\n", "\n", "make_simulator_from_settings(sim_settings)\n", "\n", diff --git a/examples/tutorials/nb_python/ECCV_2020_Interactivity.py b/examples/tutorials/nb_python/ECCV_2020_Interactivity.py index afcc485c4a..cfb06aa061 100644 --- a/examples/tutorials/nb_python/ECCV_2020_Interactivity.py +++ b/examples/tutorials/nb_python/ECCV_2020_Interactivity.py @@ -61,6 +61,7 @@ import habitat_sim from habitat_sim.utils import common as ut from habitat_sim.utils import viz_utils as vut +from habitat_sim.utils.settings import default_sim_settings, make_cfg try: import ipywidgets as widgets @@ -104,116 +105,24 @@ # @markdown (double click to show code) # @markdown This cell defines a number of utility functions used throughout the tutorial to make simulator reconstruction easy: -# @markdown - make_cfg -# @markdown - make_default_settings +# @markdown - make_custom_settings # @markdown - make_simulator_from_settings -def make_cfg(settings): - sim_cfg = habitat_sim.SimulatorConfiguration() - sim_cfg.gpu_device_id = 0 - sim_cfg.scene_id = settings["scene"] - sim_cfg.enable_physics = settings["enable_physics"] - # Optional; Specify the location of an existing scene dataset configuration - # that describes the locations and configurations of all the assets to be used - if "scene_dataset_config" in settings: - sim_cfg.scene_dataset_config_file = settings["scene_dataset_config"] - - # Note: all sensors must have the same resolution - sensor_specs = [] - if settings["color_sensor_1st_person"]: - color_sensor_1st_person_spec = habitat_sim.CameraSensorSpec() - color_sensor_1st_person_spec.uuid = "color_sensor_1st_person" - color_sensor_1st_person_spec.sensor_type = habitat_sim.SensorType.COLOR - color_sensor_1st_person_spec.resolution = [ - settings["height"], - settings["width"], - ] - color_sensor_1st_person_spec.position = [0.0, settings["sensor_height"], 0.0] - color_sensor_1st_person_spec.orientation = [ - settings["sensor_pitch"], - 0.0, - 0.0, - ] - color_sensor_1st_person_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE - sensor_specs.append(color_sensor_1st_person_spec) - if settings["depth_sensor_1st_person"]: - depth_sensor_1st_person_spec = habitat_sim.CameraSensorSpec() - depth_sensor_1st_person_spec.uuid = "depth_sensor_1st_person" - depth_sensor_1st_person_spec.sensor_type = habitat_sim.SensorType.DEPTH - depth_sensor_1st_person_spec.resolution = [ - settings["height"], - settings["width"], - ] - depth_sensor_1st_person_spec.position = [0.0, settings["sensor_height"], 0.0] - depth_sensor_1st_person_spec.orientation = [ - settings["sensor_pitch"], - 0.0, - 0.0, - ] - depth_sensor_1st_person_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE - sensor_specs.append(depth_sensor_1st_person_spec) - if settings["semantic_sensor_1st_person"]: - semantic_sensor_1st_person_spec = habitat_sim.CameraSensorSpec() - semantic_sensor_1st_person_spec.uuid = "semantic_sensor_1st_person" - semantic_sensor_1st_person_spec.sensor_type = habitat_sim.SensorType.SEMANTIC - semantic_sensor_1st_person_spec.resolution = [ - settings["height"], - settings["width"], - ] - semantic_sensor_1st_person_spec.position = [ - 0.0, - settings["sensor_height"], - 0.0, - ] - semantic_sensor_1st_person_spec.orientation = [ - settings["sensor_pitch"], - 0.0, - 0.0, - ] - semantic_sensor_1st_person_spec.sensor_subtype = ( - habitat_sim.SensorSubType.PINHOLE - ) - sensor_specs.append(semantic_sensor_1st_person_spec) - if settings["color_sensor_3rd_person"]: - color_sensor_3rd_person_spec = habitat_sim.CameraSensorSpec() - color_sensor_3rd_person_spec.uuid = "color_sensor_3rd_person" - color_sensor_3rd_person_spec.sensor_type = habitat_sim.SensorType.COLOR - color_sensor_3rd_person_spec.resolution = [ - settings["height"], - settings["width"], - ] - color_sensor_3rd_person_spec.position = [ - 0.0, - settings["sensor_height"] + 0.2, - 0.2, - ] - color_sensor_3rd_person_spec.orientation = [-math.pi / 4, 0, 0] - color_sensor_3rd_person_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE - sensor_specs.append(color_sensor_3rd_person_spec) - - # Here you can specify the amount of displacement in a forward action and the turn angle - agent_cfg = habitat_sim.agent.AgentConfiguration() - agent_cfg.sensor_specifications = sensor_specs - return habitat_sim.Configuration(sim_cfg, [agent_cfg]) - - -def make_default_settings(): +def make_custom_settings(): settings = { "width": 720, # Spatial resolution of the observations "height": 544, "scene": "./data/scene_datasets/mp3d_example/17DRP5sb8fy/17DRP5sb8fy.glb", # Scene path - "scene_dataset_config": "./data/scene_datasets/mp3d_example/mp3d.scene_dataset_config.json", # MP3D scene dataset - "default_agent": 0, - "sensor_height": 1.5, # Height of sensors in meters - "sensor_pitch": -math.pi / 8.0, # sensor pitch (x rotation in rads) - "color_sensor_1st_person": True, # RGB sensor - "color_sensor_3rd_person": False, # RGB sensor 3rd person - "depth_sensor_1st_person": False, # Depth sensor - "semantic_sensor_1st_person": False, # Semantic sensor - "seed": 1, + "scene_dataset_config_file": "./data/scene_datasets/mp3d_example/mp3d.scene_dataset_config.json", # MP3D scene dataset + "sensors": { + "color_sensor_1st_person": { + "orientation": [-math.pi / 8.0, 0.0, 0.0], + }, + }, "enable_physics": True, # enable dynamics simulation } + settings = {**default_sim_settings, **settings} return settings @@ -522,7 +431,7 @@ def build_widget_ui(obj_attr_mgr, prim_attr_mgr): # @title Initialize Simulator and Load Scene { display-mode: "form" } # convienience functions defined in Utility cell manage global variables -sim_settings = make_default_settings() +sim_settings = make_custom_settings() # set globals: sim, make_simulator_from_settings(sim_settings) @@ -606,7 +515,7 @@ def build_widget_ui(obj_attr_mgr, prim_attr_mgr): # display a still frame of the scene after the object is added if RGB sensor is enabled observations = sim.get_sensor_observations() -if display and sim_settings["color_sensor_1st_person"]: +if display and "color_sensor_1st_person" in sim_settings["sensors"]: display_sample(observations["color_sensor_1st_person"]) example_type = "adding objects test" @@ -887,9 +796,10 @@ def build_widget_ui(obj_attr_mgr, prim_attr_mgr): # %% # @title Initialize Simulator and Load Scene { display-mode: "form" } # @markdown (load the apartment_1 scene for clutter generation in an open space) -sim_settings = make_default_settings() +sim_settings = make_custom_settings() sim_settings["scene"] = "./data/scene_datasets/habitat-test-scenes/apartment_1.glb" -sim_settings["sensor_pitch"] = 0 +for sensor_settings in sim_settings["sensors"]: + sensor_settings["orientation"] = [0.0, 0.0, 0.0] make_simulator_from_settings(sim_settings) @@ -1177,17 +1087,30 @@ def release(self): # @markdown This example cell runs the object retrieval task. # @markdown First the Simulator is re-initialized with: -# @markdown - a 3rd person camera view # @markdown - modified 1st person sensor placement -sim_settings = make_default_settings() +# @markdown - a 3rd person camera view +# @markdown - a 1st person depth sensor view +# @markdown - a 1st person semantic sensor view +sim_settings = make_custom_settings() # fmt: off sim_settings["scene"] = "./data/scene_datasets/mp3d_example/17DRP5sb8fy/17DRP5sb8fy.glb" # @param{type:"string"} # fmt: on -sim_settings["sensor_pitch"] = 0 -sim_settings["sensor_height"] = 0.6 -sim_settings["color_sensor_3rd_person"] = True -sim_settings["depth_sensor_1st_person"] = True -sim_settings["semantic_sensor_1st_person"] = True +sim_settings["sensors"] = { + "color_sensor_1st_person": { + "position": [0.0, 0.6, 0.0], + }, + "color_sensor_3rd_person": { + "position": [0.0, 0.8, 0.2], + }, + "depth_sensor_1st_person": { + "position": [0.0, 0.6, 0.0], + "sensor_type": habitat_sim.SensorType.DEPTH, + }, + "semantic_sensor_1st_person": { + "position": [0.0, 0.6, 0.0], + "sensor_type": habitat_sim.SensorType.SEMANTIC, + }, +} make_simulator_from_settings(sim_settings) From b4bccac4fa2e4a8840e71a37ace7269b79172e54 Mon Sep 17 00:00:00 2001 From: John Reyna Date: Thu, 1 Dec 2022 12:42:47 -0800 Subject: [PATCH 19/24] updated ECCV_2020_Advanced_Features.py to use new settings update --- .../colabs/ECCV_2020_Advanced_Features.ipynb | 123 +++--------------- .../nb_python/ECCV_2020_Advanced_Features.py | 123 +++--------------- 2 files changed, 32 insertions(+), 214 deletions(-) diff --git a/examples/tutorials/colabs/ECCV_2020_Advanced_Features.ipynb b/examples/tutorials/colabs/ECCV_2020_Advanced_Features.ipynb index dae4c84cc2..a4227a50f0 100644 --- a/examples/tutorials/colabs/ECCV_2020_Advanced_Features.ipynb +++ b/examples/tutorials/colabs/ECCV_2020_Advanced_Features.ipynb @@ -60,6 +60,7 @@ "import habitat_sim\n", "from habitat_sim.utils import common as ut\n", "from habitat_sim.utils import viz_utils as vut\n", + "from habitat_sim.utils.settings import default_sim_settings, make_cfg\n", "\n", "try:\n", " import ipywidgets as widgets\n", @@ -413,117 +414,26 @@ "# @markdown (double click to show code)\n", "\n", "# @markdown This cell defines a number of utility functions used throughout the tutorial to make simulator reconstruction easy:\n", - "# @markdown - make_cfg\n", - "# @markdown - make_default_settings\n", + "# @markdown - make_custom_settings\n", "# @markdown - make_simulator_from_settings\n", "\n", "\n", - "def make_cfg(settings):\n", - " sim_cfg = habitat_sim.SimulatorConfiguration()\n", - " sim_cfg.gpu_device_id = 0\n", - " sim_cfg.scene_id = settings[\"scene\"]\n", - " sim_cfg.enable_physics = settings[\"enable_physics\"]\n", - " # Optional; Specify the location of an existing scene dataset configuration\n", - " # that describes the locations and configurations of all the assets to be used\n", - " if \"scene_dataset_config\" in settings:\n", - " sim_cfg.scene_dataset_config_file = settings[\"scene_dataset_config\"]\n", - "\n", - " # Note: all sensors must have the same resolution\n", - " sensor_specs = []\n", - " if settings[\"color_sensor_1st_person\"]:\n", - " color_sensor_1st_person_spec = habitat_sim.CameraSensorSpec()\n", - " color_sensor_1st_person_spec.uuid = \"color_sensor_1st_person\"\n", - " color_sensor_1st_person_spec.sensor_type = habitat_sim.SensorType.COLOR\n", - " color_sensor_1st_person_spec.resolution = [\n", - " settings[\"height\"],\n", - " settings[\"width\"],\n", - " ]\n", - " color_sensor_1st_person_spec.position = [0.0, settings[\"sensor_height\"], 0.0]\n", - " color_sensor_1st_person_spec.orientation = [\n", - " settings[\"sensor_pitch\"],\n", - " 0.0,\n", - " 0.0,\n", - " ]\n", - " color_sensor_1st_person_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE\n", - " sensor_specs.append(color_sensor_1st_person_spec)\n", - " if settings[\"depth_sensor_1st_person\"]:\n", - " depth_sensor_1st_person_spec = habitat_sim.CameraSensorSpec()\n", - " depth_sensor_1st_person_spec.uuid = \"depth_sensor_1st_person\"\n", - " depth_sensor_1st_person_spec.sensor_type = habitat_sim.SensorType.DEPTH\n", - " depth_sensor_1st_person_spec.resolution = [\n", - " settings[\"height\"],\n", - " settings[\"width\"],\n", - " ]\n", - " depth_sensor_1st_person_spec.position = [0.0, settings[\"sensor_height\"], 0.0]\n", - " depth_sensor_1st_person_spec.orientation = [\n", - " settings[\"sensor_pitch\"],\n", - " 0.0,\n", - " 0.0,\n", - " ]\n", - " depth_sensor_1st_person_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE\n", - " sensor_specs.append(depth_sensor_1st_person_spec)\n", - " if settings[\"semantic_sensor_1st_person\"]:\n", - " semantic_sensor_1st_person_spec = habitat_sim.CameraSensorSpec()\n", - " semantic_sensor_1st_person_spec.uuid = \"semantic_sensor_1st_person\"\n", - " semantic_sensor_1st_person_spec.sensor_type = habitat_sim.SensorType.SEMANTIC\n", - " semantic_sensor_1st_person_spec.resolution = [\n", - " settings[\"height\"],\n", - " settings[\"width\"],\n", - " ]\n", - " semantic_sensor_1st_person_spec.position = [\n", - " 0.0,\n", - " settings[\"sensor_height\"],\n", - " 0.0,\n", - " ]\n", - " semantic_sensor_1st_person_spec.orientation = [\n", - " settings[\"sensor_pitch\"],\n", - " 0.0,\n", - " 0.0,\n", - " ]\n", - " semantic_sensor_1st_person_spec.sensor_subtype = (\n", - " habitat_sim.SensorSubType.PINHOLE\n", - " )\n", - " sensor_specs.append(semantic_sensor_1st_person_spec)\n", - " if settings[\"color_sensor_3rd_person\"]:\n", - " color_sensor_3rd_person_spec = habitat_sim.CameraSensorSpec()\n", - " color_sensor_3rd_person_spec.uuid = \"color_sensor_3rd_person\"\n", - " color_sensor_3rd_person_spec.sensor_type = habitat_sim.SensorType.COLOR\n", - " color_sensor_3rd_person_spec.resolution = [\n", - " settings[\"height\"],\n", - " settings[\"width\"],\n", - " ]\n", - " color_sensor_3rd_person_spec.position = [\n", - " 0.0,\n", - " settings[\"sensor_height\"] + 0.2,\n", - " 0.2,\n", - " ]\n", - " color_sensor_3rd_person_spec.orientation = [-math.pi / 4, 0, 0]\n", - " color_sensor_3rd_person_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE\n", - " sensor_specs.append(color_sensor_3rd_person_spec)\n", - "\n", - " # Here you can specify the amount of displacement in a forward action and the turn angle\n", - " agent_cfg = habitat_sim.agent.AgentConfiguration()\n", - " agent_cfg.sensor_specifications = sensor_specs\n", - "\n", - " return habitat_sim.Configuration(sim_cfg, [agent_cfg])\n", - "\n", - "\n", - "def make_default_settings():\n", + "def make_custom_settings():\n", " settings = {\n", " \"width\": 720, # Spatial resolution of the observations\n", " \"height\": 544,\n", " \"scene\": \"./data/scene_datasets/mp3d_example/17DRP5sb8fy/17DRP5sb8fy.glb\", # Scene path\n", " \"scene_dataset\": \"./data/scene_datasets/mp3d_example/mp3d.scene_dataset_config.json\", # mp3d scene dataset\n", " \"default_agent\": 0,\n", - " \"sensor_height\": 1.5, # Height of sensors in meters\n", - " \"sensor_pitch\": -math.pi / 8.0, # sensor pitch (x rotation in rads)\n", - " \"color_sensor_1st_person\": True, # RGB sensor\n", - " \"color_sensor_3rd_person\": False, # RGB sensor 3rd person\n", - " \"depth_sensor_1st_person\": False, # Depth sensor\n", - " \"semantic_sensor_1st_person\": False, # Semantic sensor\n", - " \"seed\": 1,\n", + " \"sensors\": {\n", + " \"color_sensor_1st_person\": {\n", + " \"position\": [0, 1.5, 0],\n", + " \"orientation\": [-math.pi / 8.0, 0, 0],\n", + " },\n", + " },\n", " \"enable_physics\": True, # enable dynamics simulation\n", " }\n", + " settings = {**default_sim_settings, **settings}\n", " return settings\n", "\n", "\n", @@ -885,9 +795,8 @@ "outputs": [], "source": [ "# @title Initialize Simulator and Load Scene { display-mode: \"form\" }\n", - "sim_settings = make_default_settings()\n", + "sim_settings = make_custom_settings()\n", "sim_settings[\"scene\"] = \"./data/scene_datasets/mp3d_example/17DRP5sb8fy/17DRP5sb8fy.glb\"\n", - "sim_settings[\"sensor_pitch\"] = 0\n", "\n", "make_simulator_from_settings(sim_settings)" ] @@ -1074,10 +983,11 @@ "source": [ "# @markdown ###Configuring Object Semantic IDs:\n", "\n", - "sim_settings = make_default_settings()\n", + "sim_settings = make_custom_settings()\n", "sim_settings[\"scene\"] = \"./data/scene_datasets/mp3d_example/17DRP5sb8fy/17DRP5sb8fy.glb\"\n", - "sim_settings[\"sensor_pitch\"] = 0\n", - "sim_settings[\"semantic_sensor_1st_person\"] = True\n", + "sim_settings[\"sensors\"][\"semantic_sensor_1st_person\"] = {\n", + " \"sensor_type\": habitat_sim.SensorType.SEMANTIC\n", + "}\n", "\n", "make_simulator_from_settings(sim_settings)\n", "\n", @@ -1177,9 +1087,8 @@ "source": [ "# @title Initialize Simulator and Load Scene { display-mode: \"form\" }\n", "# @markdown (load the apartment_1 scene for object and primitive asset customization in an open space)\n", - "sim_settings = make_default_settings()\n", + "sim_settings = make_custom_settings()\n", "sim_settings[\"scene\"] = \"./data/scene_datasets/habitat-test-scenes/apartment_1.glb\"\n", - "sim_settings[\"sensor_pitch\"] = 0\n", "\n", "make_simulator_from_settings(sim_settings)\n", "\n", diff --git a/examples/tutorials/nb_python/ECCV_2020_Advanced_Features.py b/examples/tutorials/nb_python/ECCV_2020_Advanced_Features.py index c9f5d03ae4..0f3eea3566 100644 --- a/examples/tutorials/nb_python/ECCV_2020_Advanced_Features.py +++ b/examples/tutorials/nb_python/ECCV_2020_Advanced_Features.py @@ -65,6 +65,7 @@ import habitat_sim from habitat_sim.utils import common as ut from habitat_sim.utils import viz_utils as vut +from habitat_sim.utils.settings import default_sim_settings, make_cfg try: import ipywidgets as widgets @@ -404,117 +405,26 @@ def show_template_properties(template): # @markdown (double click to show code) # @markdown This cell defines a number of utility functions used throughout the tutorial to make simulator reconstruction easy: -# @markdown - make_cfg -# @markdown - make_default_settings +# @markdown - make_custom_settings # @markdown - make_simulator_from_settings -def make_cfg(settings): - sim_cfg = habitat_sim.SimulatorConfiguration() - sim_cfg.gpu_device_id = 0 - sim_cfg.scene_id = settings["scene"] - sim_cfg.enable_physics = settings["enable_physics"] - # Optional; Specify the location of an existing scene dataset configuration - # that describes the locations and configurations of all the assets to be used - if "scene_dataset_config" in settings: - sim_cfg.scene_dataset_config_file = settings["scene_dataset_config"] - - # Note: all sensors must have the same resolution - sensor_specs = [] - if settings["color_sensor_1st_person"]: - color_sensor_1st_person_spec = habitat_sim.CameraSensorSpec() - color_sensor_1st_person_spec.uuid = "color_sensor_1st_person" - color_sensor_1st_person_spec.sensor_type = habitat_sim.SensorType.COLOR - color_sensor_1st_person_spec.resolution = [ - settings["height"], - settings["width"], - ] - color_sensor_1st_person_spec.position = [0.0, settings["sensor_height"], 0.0] - color_sensor_1st_person_spec.orientation = [ - settings["sensor_pitch"], - 0.0, - 0.0, - ] - color_sensor_1st_person_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE - sensor_specs.append(color_sensor_1st_person_spec) - if settings["depth_sensor_1st_person"]: - depth_sensor_1st_person_spec = habitat_sim.CameraSensorSpec() - depth_sensor_1st_person_spec.uuid = "depth_sensor_1st_person" - depth_sensor_1st_person_spec.sensor_type = habitat_sim.SensorType.DEPTH - depth_sensor_1st_person_spec.resolution = [ - settings["height"], - settings["width"], - ] - depth_sensor_1st_person_spec.position = [0.0, settings["sensor_height"], 0.0] - depth_sensor_1st_person_spec.orientation = [ - settings["sensor_pitch"], - 0.0, - 0.0, - ] - depth_sensor_1st_person_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE - sensor_specs.append(depth_sensor_1st_person_spec) - if settings["semantic_sensor_1st_person"]: - semantic_sensor_1st_person_spec = habitat_sim.CameraSensorSpec() - semantic_sensor_1st_person_spec.uuid = "semantic_sensor_1st_person" - semantic_sensor_1st_person_spec.sensor_type = habitat_sim.SensorType.SEMANTIC - semantic_sensor_1st_person_spec.resolution = [ - settings["height"], - settings["width"], - ] - semantic_sensor_1st_person_spec.position = [ - 0.0, - settings["sensor_height"], - 0.0, - ] - semantic_sensor_1st_person_spec.orientation = [ - settings["sensor_pitch"], - 0.0, - 0.0, - ] - semantic_sensor_1st_person_spec.sensor_subtype = ( - habitat_sim.SensorSubType.PINHOLE - ) - sensor_specs.append(semantic_sensor_1st_person_spec) - if settings["color_sensor_3rd_person"]: - color_sensor_3rd_person_spec = habitat_sim.CameraSensorSpec() - color_sensor_3rd_person_spec.uuid = "color_sensor_3rd_person" - color_sensor_3rd_person_spec.sensor_type = habitat_sim.SensorType.COLOR - color_sensor_3rd_person_spec.resolution = [ - settings["height"], - settings["width"], - ] - color_sensor_3rd_person_spec.position = [ - 0.0, - settings["sensor_height"] + 0.2, - 0.2, - ] - color_sensor_3rd_person_spec.orientation = [-math.pi / 4, 0, 0] - color_sensor_3rd_person_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE - sensor_specs.append(color_sensor_3rd_person_spec) - - # Here you can specify the amount of displacement in a forward action and the turn angle - agent_cfg = habitat_sim.agent.AgentConfiguration() - agent_cfg.sensor_specifications = sensor_specs - - return habitat_sim.Configuration(sim_cfg, [agent_cfg]) - - -def make_default_settings(): +def make_custom_settings(): settings = { "width": 720, # Spatial resolution of the observations "height": 544, "scene": "./data/scene_datasets/mp3d_example/17DRP5sb8fy/17DRP5sb8fy.glb", # Scene path "scene_dataset": "./data/scene_datasets/mp3d_example/mp3d.scene_dataset_config.json", # mp3d scene dataset "default_agent": 0, - "sensor_height": 1.5, # Height of sensors in meters - "sensor_pitch": -math.pi / 8.0, # sensor pitch (x rotation in rads) - "color_sensor_1st_person": True, # RGB sensor - "color_sensor_3rd_person": False, # RGB sensor 3rd person - "depth_sensor_1st_person": False, # Depth sensor - "semantic_sensor_1st_person": False, # Semantic sensor - "seed": 1, + "sensors": { + "color_sensor_1st_person": { + "position": [0, 1.5, 0], + "orientation": [-math.pi / 8.0, 0, 0], + }, + }, "enable_physics": True, # enable dynamics simulation } + settings = {**default_sim_settings, **settings} return settings @@ -852,9 +762,8 @@ def build_widget_ui(obj_attr_mgr, prim_attr_mgr): # %% # @title Initialize Simulator and Load Scene { display-mode: "form" } -sim_settings = make_default_settings() +sim_settings = make_custom_settings() sim_settings["scene"] = "./data/scene_datasets/mp3d_example/17DRP5sb8fy/17DRP5sb8fy.glb" -sim_settings["sensor_pitch"] = 0 make_simulator_from_settings(sim_settings) @@ -1007,10 +916,11 @@ def get_2d_point(sim, sensor_name, point_3d): # %% # @markdown ###Configuring Object Semantic IDs: -sim_settings = make_default_settings() +sim_settings = make_custom_settings() sim_settings["scene"] = "./data/scene_datasets/mp3d_example/17DRP5sb8fy/17DRP5sb8fy.glb" -sim_settings["sensor_pitch"] = 0 -sim_settings["semantic_sensor_1st_person"] = True +sim_settings["sensors"]["semantic_sensor_1st_person"] = { + "sensor_type": habitat_sim.SensorType.SEMANTIC +} make_simulator_from_settings(sim_settings) @@ -1096,9 +1006,8 @@ def get_2d_point(sim, sensor_name, point_3d): # %% # @title Initialize Simulator and Load Scene { display-mode: "form" } # @markdown (load the apartment_1 scene for object and primitive asset customization in an open space) -sim_settings = make_default_settings() +sim_settings = make_custom_settings() sim_settings["scene"] = "./data/scene_datasets/habitat-test-scenes/apartment_1.glb" -sim_settings["sensor_pitch"] = 0 make_simulator_from_settings(sim_settings) From 35601b68572779e98551149aac3c0deed2cf2553 Mon Sep 17 00:00:00 2001 From: John Reyna Date: Fri, 2 Dec 2022 07:16:22 -0800 Subject: [PATCH 20/24] made new function in settings.py to add or update sensor settings in sim_settings, as well as updating all the ECCV tutorials accordingly --- .../colabs/ECCV_2020_Advanced_Features.ipynb | 37 ++++-- .../colabs/ECCV_2020_Interactivity.ipynb | 64 +++++---- .../colabs/ECCV_2020_Navigation.ipynb | 122 +++++------------- .../nb_python/ECCV_2020_Advanced_Features.py | 37 ++++-- .../nb_python/ECCV_2020_Interactivity.py | 64 +++++---- .../nb_python/ECCV_2020_Navigation.py | 101 +++------------ src_python/habitat_sim/utils/settings.py | 56 ++++++-- 7 files changed, 231 insertions(+), 250 deletions(-) diff --git a/examples/tutorials/colabs/ECCV_2020_Advanced_Features.ipynb b/examples/tutorials/colabs/ECCV_2020_Advanced_Features.ipynb index a4227a50f0..12531892ff 100644 --- a/examples/tutorials/colabs/ECCV_2020_Advanced_Features.ipynb +++ b/examples/tutorials/colabs/ECCV_2020_Advanced_Features.ipynb @@ -60,7 +60,11 @@ "import habitat_sim\n", "from habitat_sim.utils import common as ut\n", "from habitat_sim.utils import viz_utils as vut\n", - "from habitat_sim.utils.settings import default_sim_settings, make_cfg\n", + "from habitat_sim.utils.settings import (\n", + " default_sim_settings,\n", + " make_cfg,\n", + " update_sensor_settings,\n", + ")\n", "\n", "try:\n", " import ipywidgets as widgets\n", @@ -419,21 +423,28 @@ "\n", "\n", "def make_custom_settings():\n", + " \"\"\"\n", + " create custom simulator settings. All sim settings not explicitly assigned are given default values\n", + " \"\"\"\n", " settings = {\n", " \"width\": 720, # Spatial resolution of the observations\n", " \"height\": 544,\n", " \"scene\": \"./data/scene_datasets/mp3d_example/17DRP5sb8fy/17DRP5sb8fy.glb\", # Scene path\n", - " \"scene_dataset\": \"./data/scene_datasets/mp3d_example/mp3d.scene_dataset_config.json\", # mp3d scene dataset\n", - " \"default_agent\": 0,\n", - " \"sensors\": {\n", - " \"color_sensor_1st_person\": {\n", - " \"position\": [0, 1.5, 0],\n", - " \"orientation\": [-math.pi / 8.0, 0, 0],\n", - " },\n", - " },\n", + " \"scene_dataset_config_file\": \"./data/scene_datasets/mp3d_example/mp3d.scene_dataset_config.json\", # mp3d scene dataset\n", " \"enable_physics\": True, # enable dynamics simulation\n", " }\n", + "\n", + " # Instantiate all non-assigned elements of simulator settings to the default values\n", " settings = {**default_sim_settings, **settings}\n", + "\n", + " # add settings for a new sensor to the simulator settings. All sensor settings not\n", + " # explicitly assigned are given default values\n", + " update_sensor_settings(\n", + " settings,\n", + " \"color_sensor_1st_person\",\n", + " position=[0, 1.5, 0],\n", + " orientation=[-math.pi / 8.0, 0.0, 0.0],\n", + " )\n", " return settings\n", "\n", "\n", @@ -985,9 +996,11 @@ "\n", "sim_settings = make_custom_settings()\n", "sim_settings[\"scene\"] = \"./data/scene_datasets/mp3d_example/17DRP5sb8fy/17DRP5sb8fy.glb\"\n", - "sim_settings[\"sensors\"][\"semantic_sensor_1st_person\"] = {\n", - " \"sensor_type\": habitat_sim.SensorType.SEMANTIC\n", - "}\n", + "update_sensor_settings(\n", + " sim_settings,\n", + " uuid=\"semantic_sensor_1st_person\",\n", + " sensor_type=habitat_sim.SensorType.SEMANTIC,\n", + ")\n", "\n", "make_simulator_from_settings(sim_settings)\n", "\n", diff --git a/examples/tutorials/colabs/ECCV_2020_Interactivity.ipynb b/examples/tutorials/colabs/ECCV_2020_Interactivity.ipynb index 04d2034374..0244e773a9 100644 --- a/examples/tutorials/colabs/ECCV_2020_Interactivity.ipynb +++ b/examples/tutorials/colabs/ECCV_2020_Interactivity.ipynb @@ -63,7 +63,11 @@ "import habitat_sim\n", "from habitat_sim.utils import common as ut\n", "from habitat_sim.utils import viz_utils as vut\n", - "from habitat_sim.utils.settings import default_sim_settings, make_cfg\n", + "from habitat_sim.utils.settings import (\n", + " default_sim_settings,\n", + " make_cfg,\n", + " update_sensor_settings,\n", + ")\n", "\n", "try:\n", " import ipywidgets as widgets\n", @@ -119,19 +123,28 @@ "\n", "\n", "def make_custom_settings():\n", + " \"\"\"\n", + " create custom simulator settings. All sim settings not explicitly assigned are given default values\n", + " \"\"\"\n", " settings = {\n", " \"width\": 720, # Spatial resolution of the observations\n", " \"height\": 544,\n", " \"scene\": \"./data/scene_datasets/mp3d_example/17DRP5sb8fy/17DRP5sb8fy.glb\", # Scene path\n", " \"scene_dataset_config_file\": \"./data/scene_datasets/mp3d_example/mp3d.scene_dataset_config.json\", # MP3D scene dataset\n", - " \"sensors\": {\n", - " \"color_sensor_1st_person\": {\n", - " \"orientation\": [-math.pi / 8.0, 0.0, 0.0],\n", - " },\n", - " },\n", " \"enable_physics\": True, # enable dynamics simulation\n", " }\n", + "\n", + " # Instantiate all non-assigned elements of simulator settings to the default values\n", " settings = {**default_sim_settings, **settings}\n", + "\n", + " # add settings for a new sensor to the simulator settings. All sensor settings not\n", + " # explicitly assigned are given default values\n", + " update_sensor_settings(\n", + " settings,\n", + " \"color_sensor_1st_person\",\n", + " position=[0, 1.5, 0],\n", + " orientation=[-math.pi / 8.0, 0.0, 0.0],\n", + " )\n", " return settings\n", "\n", "\n", @@ -897,7 +910,8 @@ "# @markdown (load the apartment_1 scene for clutter generation in an open space)\n", "sim_settings = make_custom_settings()\n", "sim_settings[\"scene\"] = \"./data/scene_datasets/habitat-test-scenes/apartment_1.glb\"\n", - "for sensor_settings in sim_settings[\"sensors\"]:\n", + "\n", + "for sensor_settings in sim_settings[\"sensors\"].values():\n", " sensor_settings[\"orientation\"] = [0.0, 0.0, 0.0]\n", "\n", "make_simulator_from_settings(sim_settings)" @@ -1232,22 +1246,26 @@ "# fmt: off\n", "sim_settings[\"scene\"] = \"./data/scene_datasets/mp3d_example/17DRP5sb8fy/17DRP5sb8fy.glb\" # @param{type:\"string\"}\n", "# fmt: on\n", - "sim_settings[\"sensors\"] = {\n", - " \"color_sensor_1st_person\": {\n", - " \"position\": [0.0, 0.6, 0.0],\n", - " },\n", - " \"color_sensor_3rd_person\": {\n", - " \"position\": [0.0, 0.8, 0.2],\n", - " },\n", - " \"depth_sensor_1st_person\": {\n", - " \"position\": [0.0, 0.6, 0.0],\n", - " \"sensor_type\": habitat_sim.SensorType.DEPTH,\n", - " },\n", - " \"semantic_sensor_1st_person\": {\n", - " \"position\": [0.0, 0.6, 0.0],\n", - " \"sensor_type\": habitat_sim.SensorType.SEMANTIC,\n", - " },\n", - "}\n", + "\n", + "# add sensor settings to simulator settings\n", + "update_sensor_settings(\n", + " sim_settings, uuid=\"color_sensor_1st_person\", position=[0.0, 0.6, 0.0]\n", + ")\n", + "update_sensor_settings(\n", + " sim_settings, uuid=\"color_sensor_3rd_person\", position=[0.0, 0.8, 0.2]\n", + ")\n", + "update_sensor_settings(\n", + " sim_settings,\n", + " uuid=\"depth_sensor_1st_person\",\n", + " position=[0.0, 0.6, 0.0],\n", + " sensor_type=habitat_sim.SensorType.DEPTH,\n", + ")\n", + "update_sensor_settings(\n", + " sim_settings,\n", + " uuid=\"semantic_sensor_1st_person\",\n", + " position=[0.0, 0.6, 0.0],\n", + " sensor_type=habitat_sim.SensorType.SEMANTIC,\n", + ")\n", "\n", "make_simulator_from_settings(sim_settings)\n", "\n", diff --git a/examples/tutorials/colabs/ECCV_2020_Navigation.ipynb b/examples/tutorials/colabs/ECCV_2020_Navigation.ipynb index 8d8ae1e6ef..b30c8d9a7f 100644 --- a/examples/tutorials/colabs/ECCV_2020_Navigation.ipynb +++ b/examples/tutorials/colabs/ECCV_2020_Navigation.ipynb @@ -61,6 +61,11 @@ "import habitat_sim\n", "from habitat_sim.utils import common as utils\n", "from habitat_sim.utils import viz_utils as vut\n", + "from habitat_sim.utils.settings import (\n", + " default_sim_settings,\n", + " make_cfg,\n", + " update_sensor_settings,\n", + ")\n", "\n", "%cd /content/habitat-sim\n", "\n", @@ -169,7 +174,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "lines_to_next_cell": 2 + }, "outputs": [], "source": [ "# This is the scene we are going to load.\n", @@ -179,10 +186,10 @@ "sim_settings = {\n", " \"scene\": test_scene, # Scene path\n", " \"default_agent\": 0, # Index of the default agent\n", - " \"sensor_height\": 1.5, # Height of sensors in meters, relative to the agent\n", " \"width\": 256, # Spatial resolution of the observations\n", " \"height\": 256,\n", - "}" + "}\n", + "sim_settings = {**default_sim_settings, **sim_settings}" ] }, { @@ -208,28 +215,7 @@ "# It contains two parts:\n", "# one for the simulator backend\n", "# one for the agent, where you can attach a bunch of sensors\n", - "def make_simple_cfg(settings):\n", - " # simulator backend\n", - " sim_cfg = habitat_sim.SimulatorConfiguration()\n", - " sim_cfg.scene_id = settings[\"scene\"]\n", - "\n", - " # agent\n", - " agent_cfg = habitat_sim.agent.AgentConfiguration()\n", - "\n", - " # In the 1st example, we attach only one sensor,\n", - " # a RGB visual sensor, to the agent\n", - " rgb_sensor_spec = habitat_sim.CameraSensorSpec()\n", - " rgb_sensor_spec.uuid = \"color_sensor\"\n", - " rgb_sensor_spec.sensor_type = habitat_sim.SensorType.COLOR\n", - " rgb_sensor_spec.resolution = [settings[\"height\"], settings[\"width\"]]\n", - " rgb_sensor_spec.position = [0.0, settings[\"sensor_height\"], 0.0]\n", - "\n", - " agent_cfg.sensor_specifications = [rgb_sensor_spec]\n", - "\n", - " return habitat_sim.Configuration(sim_cfg, [agent_cfg])\n", - "\n", - "\n", - "cfg = make_simple_cfg(sim_settings)" + "cfg = make_cfg(sim_settings)" ] }, { @@ -346,7 +332,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "lines_to_next_cell": 2 + }, "outputs": [], "source": [ "# @title Configure Sim Settings\n", @@ -362,73 +350,25 @@ " \"width\": 256, # Spatial resolution of the observations\n", " \"height\": 256,\n", " \"scene\": test_scene, # Scene path\n", - " \"scene_dataset\": mp3d_scene_dataset, # the scene dataset configuration files\n", + " \"scene_dataset_config_file\": mp3d_scene_dataset, # the scene dataset configuration files\n", " \"default_agent\": 0,\n", - " \"sensor_height\": 1.5, # Height of sensors in meters\n", - " \"color_sensor\": rgb_sensor, # RGB sensor\n", - " \"depth_sensor\": depth_sensor, # Depth sensor\n", - " \"semantic_sensor\": semantic_sensor, # Semantic sensor\n", - " \"seed\": 1, # used in the random navigation\n", " \"enable_physics\": False, # kinematics only\n", - "}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def make_cfg(settings):\n", - " sim_cfg = habitat_sim.SimulatorConfiguration()\n", - " sim_cfg.gpu_device_id = 0\n", - " sim_cfg.scene_id = settings[\"scene\"]\n", - " sim_cfg.scene_dataset_config_file = settings[\"scene_dataset\"]\n", - " sim_cfg.enable_physics = settings[\"enable_physics\"]\n", - "\n", - " # Note: all sensors must have the same resolution\n", - " sensor_specs = []\n", - "\n", - " color_sensor_spec = habitat_sim.CameraSensorSpec()\n", - " color_sensor_spec.uuid = \"color_sensor\"\n", - " color_sensor_spec.sensor_type = habitat_sim.SensorType.COLOR\n", - " color_sensor_spec.resolution = [settings[\"height\"], settings[\"width\"]]\n", - " color_sensor_spec.position = [0.0, settings[\"sensor_height\"], 0.0]\n", - " color_sensor_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE\n", - " sensor_specs.append(color_sensor_spec)\n", - "\n", - " depth_sensor_spec = habitat_sim.CameraSensorSpec()\n", - " depth_sensor_spec.uuid = \"depth_sensor\"\n", - " depth_sensor_spec.sensor_type = habitat_sim.SensorType.DEPTH\n", - " depth_sensor_spec.resolution = [settings[\"height\"], settings[\"width\"]]\n", - " depth_sensor_spec.position = [0.0, settings[\"sensor_height\"], 0.0]\n", - " depth_sensor_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE\n", - " sensor_specs.append(depth_sensor_spec)\n", - "\n", - " semantic_sensor_spec = habitat_sim.CameraSensorSpec()\n", - " semantic_sensor_spec.uuid = \"semantic_sensor\"\n", - " semantic_sensor_spec.sensor_type = habitat_sim.SensorType.SEMANTIC\n", - " semantic_sensor_spec.resolution = [settings[\"height\"], settings[\"width\"]]\n", - " semantic_sensor_spec.position = [0.0, settings[\"sensor_height\"], 0.0]\n", - " semantic_sensor_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE\n", - " sensor_specs.append(semantic_sensor_spec)\n", - "\n", - " # Here you can specify the amount of displacement in a forward action and the turn angle\n", - " agent_cfg = habitat_sim.agent.AgentConfiguration()\n", - " agent_cfg.sensor_specifications = sensor_specs\n", - " agent_cfg.action_space = {\n", - " \"move_forward\": habitat_sim.agent.ActionSpec(\n", - " \"move_forward\", habitat_sim.agent.ActuationSpec(amount=0.25)\n", - " ),\n", - " \"turn_left\": habitat_sim.agent.ActionSpec(\n", - " \"turn_left\", habitat_sim.agent.ActuationSpec(amount=30.0)\n", - " ),\n", - " \"turn_right\": habitat_sim.agent.ActionSpec(\n", - " \"turn_right\", habitat_sim.agent.ActuationSpec(amount=30.0)\n", - " ),\n", - " }\n", - "\n", - " return habitat_sim.Configuration(sim_cfg, [agent_cfg])" + "}\n", + "\n", + "# Instantiate all non-assigned elements of simulator settings to the default values\n", + "sim_settings = {**default_sim_settings, **sim_settings}\n", + "\n", + "# Add sensor settings to simulator settings\n", + "if rgb_sensor:\n", + " update_sensor_settings(sim_settings, \"color_sensor\")\n", + "if depth_sensor:\n", + " update_sensor_settings(\n", + " sim_settings, \"depth_sensor\", sensor_type=habitat_sim.SensorType.DEPTH\n", + " )\n", + "if semantic_sensor:\n", + " update_sensor_settings(\n", + " sim_settings, \"semantic_sensor\", sensor_type=habitat_sim.SensorType.SEMANTIC\n", + " )" ] }, { diff --git a/examples/tutorials/nb_python/ECCV_2020_Advanced_Features.py b/examples/tutorials/nb_python/ECCV_2020_Advanced_Features.py index 0f3eea3566..fcc6b86d8d 100644 --- a/examples/tutorials/nb_python/ECCV_2020_Advanced_Features.py +++ b/examples/tutorials/nb_python/ECCV_2020_Advanced_Features.py @@ -65,7 +65,11 @@ import habitat_sim from habitat_sim.utils import common as ut from habitat_sim.utils import viz_utils as vut -from habitat_sim.utils.settings import default_sim_settings, make_cfg +from habitat_sim.utils.settings import ( + default_sim_settings, + make_cfg, + update_sensor_settings, +) try: import ipywidgets as widgets @@ -410,21 +414,28 @@ def show_template_properties(template): def make_custom_settings(): + """ + create custom simulator settings. All sim settings not explicitly assigned are given default values + """ settings = { "width": 720, # Spatial resolution of the observations "height": 544, "scene": "./data/scene_datasets/mp3d_example/17DRP5sb8fy/17DRP5sb8fy.glb", # Scene path - "scene_dataset": "./data/scene_datasets/mp3d_example/mp3d.scene_dataset_config.json", # mp3d scene dataset - "default_agent": 0, - "sensors": { - "color_sensor_1st_person": { - "position": [0, 1.5, 0], - "orientation": [-math.pi / 8.0, 0, 0], - }, - }, + "scene_dataset_config_file": "./data/scene_datasets/mp3d_example/mp3d.scene_dataset_config.json", # mp3d scene dataset "enable_physics": True, # enable dynamics simulation } + + # Instantiate all non-assigned elements of simulator settings to the default values settings = {**default_sim_settings, **settings} + + # add settings for a new sensor to the simulator settings. All sensor settings not + # explicitly assigned are given default values + update_sensor_settings( + settings, + "color_sensor_1st_person", + position=[0, 1.5, 0], + orientation=[-math.pi / 8.0, 0.0, 0.0], + ) return settings @@ -918,9 +929,11 @@ def get_2d_point(sim, sensor_name, point_3d): sim_settings = make_custom_settings() sim_settings["scene"] = "./data/scene_datasets/mp3d_example/17DRP5sb8fy/17DRP5sb8fy.glb" -sim_settings["sensors"]["semantic_sensor_1st_person"] = { - "sensor_type": habitat_sim.SensorType.SEMANTIC -} +update_sensor_settings( + sim_settings, + uuid="semantic_sensor_1st_person", + sensor_type=habitat_sim.SensorType.SEMANTIC, +) make_simulator_from_settings(sim_settings) diff --git a/examples/tutorials/nb_python/ECCV_2020_Interactivity.py b/examples/tutorials/nb_python/ECCV_2020_Interactivity.py index cfb06aa061..b914c1527a 100644 --- a/examples/tutorials/nb_python/ECCV_2020_Interactivity.py +++ b/examples/tutorials/nb_python/ECCV_2020_Interactivity.py @@ -61,7 +61,11 @@ import habitat_sim from habitat_sim.utils import common as ut from habitat_sim.utils import viz_utils as vut -from habitat_sim.utils.settings import default_sim_settings, make_cfg +from habitat_sim.utils.settings import ( + default_sim_settings, + make_cfg, + update_sensor_settings, +) try: import ipywidgets as widgets @@ -110,19 +114,28 @@ def make_custom_settings(): + """ + create custom simulator settings. All sim settings not explicitly assigned are given default values + """ settings = { "width": 720, # Spatial resolution of the observations "height": 544, "scene": "./data/scene_datasets/mp3d_example/17DRP5sb8fy/17DRP5sb8fy.glb", # Scene path "scene_dataset_config_file": "./data/scene_datasets/mp3d_example/mp3d.scene_dataset_config.json", # MP3D scene dataset - "sensors": { - "color_sensor_1st_person": { - "orientation": [-math.pi / 8.0, 0.0, 0.0], - }, - }, "enable_physics": True, # enable dynamics simulation } + + # Instantiate all non-assigned elements of simulator settings to the default values settings = {**default_sim_settings, **settings} + + # add settings for a new sensor to the simulator settings. All sensor settings not + # explicitly assigned are given default values + update_sensor_settings( + settings, + "color_sensor_1st_person", + position=[0, 1.5, 0], + orientation=[-math.pi / 8.0, 0.0, 0.0], + ) return settings @@ -798,7 +811,8 @@ def build_widget_ui(obj_attr_mgr, prim_attr_mgr): # @markdown (load the apartment_1 scene for clutter generation in an open space) sim_settings = make_custom_settings() sim_settings["scene"] = "./data/scene_datasets/habitat-test-scenes/apartment_1.glb" -for sensor_settings in sim_settings["sensors"]: + +for sensor_settings in sim_settings["sensors"].values(): sensor_settings["orientation"] = [0.0, 0.0, 0.0] make_simulator_from_settings(sim_settings) @@ -1095,22 +1109,26 @@ def release(self): # fmt: off sim_settings["scene"] = "./data/scene_datasets/mp3d_example/17DRP5sb8fy/17DRP5sb8fy.glb" # @param{type:"string"} # fmt: on -sim_settings["sensors"] = { - "color_sensor_1st_person": { - "position": [0.0, 0.6, 0.0], - }, - "color_sensor_3rd_person": { - "position": [0.0, 0.8, 0.2], - }, - "depth_sensor_1st_person": { - "position": [0.0, 0.6, 0.0], - "sensor_type": habitat_sim.SensorType.DEPTH, - }, - "semantic_sensor_1st_person": { - "position": [0.0, 0.6, 0.0], - "sensor_type": habitat_sim.SensorType.SEMANTIC, - }, -} + +# add sensor settings to simulator settings +update_sensor_settings( + sim_settings, uuid="color_sensor_1st_person", position=[0.0, 0.6, 0.0] +) +update_sensor_settings( + sim_settings, uuid="color_sensor_3rd_person", position=[0.0, 0.8, 0.2] +) +update_sensor_settings( + sim_settings, + uuid="depth_sensor_1st_person", + position=[0.0, 0.6, 0.0], + sensor_type=habitat_sim.SensorType.DEPTH, +) +update_sensor_settings( + sim_settings, + uuid="semantic_sensor_1st_person", + position=[0.0, 0.6, 0.0], + sensor_type=habitat_sim.SensorType.SEMANTIC, +) make_simulator_from_settings(sim_settings) diff --git a/examples/tutorials/nb_python/ECCV_2020_Navigation.py b/examples/tutorials/nb_python/ECCV_2020_Navigation.py index c85054621d..344099e721 100644 --- a/examples/tutorials/nb_python/ECCV_2020_Navigation.py +++ b/examples/tutorials/nb_python/ECCV_2020_Navigation.py @@ -63,6 +63,11 @@ import habitat_sim from habitat_sim.utils import common as utils from habitat_sim.utils import viz_utils as vut +from habitat_sim.utils.settings import ( + default_sim_settings, + make_cfg, + update_sensor_settings, +) # %cd /content/habitat-sim @@ -162,10 +167,10 @@ def display_sample(rgb_obs, semantic_obs=np.array([]), depth_obs=np.array([])): sim_settings = { "scene": test_scene, # Scene path "default_agent": 0, # Index of the default agent - "sensor_height": 1.5, # Height of sensors in meters, relative to the agent "width": 256, # Spatial resolution of the observations "height": 256, } +sim_settings = {**default_sim_settings, **sim_settings} # %% [markdown] @@ -182,28 +187,7 @@ def display_sample(rgb_obs, semantic_obs=np.array([]), depth_obs=np.array([])): # It contains two parts: # one for the simulator backend # one for the agent, where you can attach a bunch of sensors -def make_simple_cfg(settings): - # simulator backend - sim_cfg = habitat_sim.SimulatorConfiguration() - sim_cfg.scene_id = settings["scene"] - - # agent - agent_cfg = habitat_sim.agent.AgentConfiguration() - - # In the 1st example, we attach only one sensor, - # a RGB visual sensor, to the agent - rgb_sensor_spec = habitat_sim.CameraSensorSpec() - rgb_sensor_spec.uuid = "color_sensor" - 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] - - agent_cfg.sensor_specifications = [rgb_sensor_spec] - - return habitat_sim.Configuration(sim_cfg, [agent_cfg]) - - -cfg = make_simple_cfg(sim_settings) +cfg = make_cfg(sim_settings) # %% [markdown] # ### Create a simulator instance @@ -292,68 +276,25 @@ def navigateAndSee(action=""): "width": 256, # Spatial resolution of the observations "height": 256, "scene": test_scene, # Scene path - "scene_dataset": mp3d_scene_dataset, # the scene dataset configuration files + "scene_dataset_config_file": mp3d_scene_dataset, # the scene dataset configuration files "default_agent": 0, - "sensor_height": 1.5, # Height of sensors in meters - "color_sensor": rgb_sensor, # RGB sensor - "depth_sensor": depth_sensor, # Depth sensor - "semantic_sensor": semantic_sensor, # Semantic sensor - "seed": 1, # used in the random navigation "enable_physics": False, # kinematics only } +# Instantiate all non-assigned elements of simulator settings to the default values +sim_settings = {**default_sim_settings, **sim_settings} -# %% -def make_cfg(settings): - sim_cfg = habitat_sim.SimulatorConfiguration() - sim_cfg.gpu_device_id = 0 - sim_cfg.scene_id = settings["scene"] - sim_cfg.scene_dataset_config_file = settings["scene_dataset"] - sim_cfg.enable_physics = settings["enable_physics"] - - # Note: all sensors must have the same resolution - sensor_specs = [] - - color_sensor_spec = habitat_sim.CameraSensorSpec() - color_sensor_spec.uuid = "color_sensor" - color_sensor_spec.sensor_type = habitat_sim.SensorType.COLOR - color_sensor_spec.resolution = [settings["height"], settings["width"]] - color_sensor_spec.position = [0.0, settings["sensor_height"], 0.0] - color_sensor_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE - sensor_specs.append(color_sensor_spec) - - depth_sensor_spec = habitat_sim.CameraSensorSpec() - depth_sensor_spec.uuid = "depth_sensor" - 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 - sensor_specs.append(depth_sensor_spec) - - semantic_sensor_spec = habitat_sim.CameraSensorSpec() - semantic_sensor_spec.uuid = "semantic_sensor" - 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) - - # Here you can specify the amount of displacement in a forward action and the turn angle - 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]) +# Add sensor settings to simulator settings +if rgb_sensor: + update_sensor_settings(sim_settings, "color_sensor") +if depth_sensor: + update_sensor_settings( + sim_settings, "depth_sensor", sensor_type=habitat_sim.SensorType.DEPTH + ) +if semantic_sensor: + update_sensor_settings( + sim_settings, "semantic_sensor", sensor_type=habitat_sim.SensorType.SEMANTIC + ) # %% diff --git a/src_python/habitat_sim/utils/settings.py b/src_python/habitat_sim/utils/settings.py index 0d835b409d..24eeac54af 100644 --- a/src_python/habitat_sim/utils/settings.py +++ b/src_python/habitat_sim/utils/settings.py @@ -2,7 +2,7 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. -from typing import Any, Dict +from typing import Any, Dict, Optional import habitat_sim import habitat_sim.agent @@ -17,10 +17,11 @@ "seed": 1, "physics_config_file": "data/default.physics_config.json", "sensors": { - "color_sensor": {}, - # Other example sensor entries: + # Examples: + # "color_sensor": {}, # "depth_sensor": {}, - # "semantic_sensor": {}, + # If left empty, a default sensor called "color_sensor" will be created. + # Any unassigned sensor settings are populated with the default values below }, } # [/default_sim_settings] @@ -31,12 +32,34 @@ "orientation": [0, 0, 0], "sensor_type": habitat_sim.sensor.SensorType.COLOR, "sensor_subtype": habitat_sim.sensor.SensorSubType.PINHOLE, - # can be agent ID or "None". + # can be an int agent ID or "None". # TODO: If the value is "None", then make it a global sensor attached to root scene node "agent_id": default_sim_settings["default_agent"], } +# TODO: possibly remove, useful for debugging and testing +def print_settings(settings: Dict[str, Any], nest_level: Optional[int] = 0): + for k, v in settings.items(): + if isinstance(v, Dict): + print(" " * nest_level + f"{k}:") + print_settings(v, nest_level + 1) + else: + print(" " * nest_level + f"{k}: {v}") + + +def update_sensor_settings(settings: Dict[str, Any], uuid: str, **kw_args) -> None: + if uuid not in settings["sensors"]: + # if there is no Dict of sensor settings for a sensor with this uuid, create a new + # Dict of sensor settings with this uuid and initiate all sensor setting fields + # to their default values + settings["sensors"][uuid] = default_sensor_settings.copy() + + # update all Dict fields in the given sensor settings with the new values + for k in kw_args: + settings["sensors"][uuid][k] = kw_args[k] + + # build SimulatorConfiguration def make_cfg(settings: Dict[str, Any]): r"""Isolates the boilerplate code to create a habitat_sim.Configuration from a settings dictionary. @@ -98,6 +121,7 @@ def create_fisheye_spec(**kw_args): # The default principal_point_offset is the middle of the image fisheye_sensor_spec.principal_point_offset = None + # default: fisheye_sensor_spec.principal_point_offset = [i/2 for i in fisheye_sensor_spec.resolution] for k in kw_args: setattr(fisheye_sensor_spec, k, kw_args[k]) @@ -109,18 +133,25 @@ def create_equirect_spec(**kw_args): setattr(equirect_sensor_spec, k, kw_args[k]) return equirect_sensor_spec + # if user has not specified any sensors of their own, + # use default sensor with uuid of "color_sensor" + if len(settings.get("sensors")) == 0: + settings["sensors"]["color_sensor"] = {} + for uuid, sensor_settings in settings["sensors"].items(): + # update all non assigned sensor setting fields to their default values sensor_settings = {**default_sensor_settings, **sensor_settings} + channels = ( 4 if sensor_settings["sensor_type"] is habitat_sim.sensor.SensorType.COLOR else 1 ) - if ( + if ( # fisheye_rgba_sensor, fisheye_depth_sensor, fisheye_semantic_sensor "fisheye" in uuid - ): # fisheye_rgba_sensor, fisheye_depth_sensor, fisheye_semantic_sensor + ): fisheye_spec = create_fisheye_spec( uuid=uuid, position=sensor_settings["position"], @@ -130,9 +161,9 @@ def create_equirect_spec(**kw_args): channels=channels, ) sensor_specs.append(fisheye_spec) - elif ( + elif ( # equirect_rgba_sensor, equirect_depth_sensor, equirect_semantic_sensor "equirect" in uuid - ): # equirect_rgba_sensor, equirect_depth_sensor, equirect_semantic_sensor + ): equirect_spec = create_equirect_spec( uuid=uuid, position=sensor_settings["position"], @@ -155,6 +186,13 @@ def create_equirect_spec(**kw_args): ) sensor_specs.append(camera_spec) + # TODO: remove + print( + "in make_cfg, done making sensor specs --------------------------------------" + ) + print_settings(settings) + print() + # create agent specifications agent_cfg = habitat_sim.agent.AgentConfiguration() agent_cfg.sensor_specifications = sensor_specs From 42e118190a123aca4b9a6e87f1169b7b92a10ec5 Mon Sep 17 00:00:00 2001 From: John Reyna Date: Fri, 2 Dec 2022 07:17:21 -0800 Subject: [PATCH 21/24] removed debug print statement --- src_python/habitat_sim/utils/settings.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src_python/habitat_sim/utils/settings.py b/src_python/habitat_sim/utils/settings.py index 24eeac54af..94fd1c4957 100644 --- a/src_python/habitat_sim/utils/settings.py +++ b/src_python/habitat_sim/utils/settings.py @@ -186,13 +186,6 @@ def create_equirect_spec(**kw_args): ) sensor_specs.append(camera_spec) - # TODO: remove - print( - "in make_cfg, done making sensor specs --------------------------------------" - ) - print_settings(settings) - print() - # create agent specifications agent_cfg = habitat_sim.agent.AgentConfiguration() agent_cfg.sensor_specifications = sensor_specs From 815b39b55784467cd5a56ff815aa9edc8befd50d Mon Sep 17 00:00:00 2001 From: John Reyna Date: Fri, 2 Dec 2022 07:33:38 -0800 Subject: [PATCH 22/24] updated example.py to use new 'update_sensor_settings' function --- examples/example.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/examples/example.py b/examples/example.py index 688c0d17b3..ca8011dcca 100755 --- a/examples/example.py +++ b/examples/example.py @@ -10,6 +10,7 @@ import demo_runner as dr import habitat_sim +from habitat_sim.utils.settings import update_sensor_settings parser = argparse.ArgumentParser() parser.add_argument("--scene", type=str, default=dr.default_sim_settings["scene"]) @@ -57,20 +58,25 @@ def make_settings(): settings["frustum_culling"] = not args.disable_frustum_culling settings["recompute_navmesh"] = args.recompute_navmesh + # add sensor settings to simulator settings if not args.disable_color_sensor: - settings["sensors"]["color_sensor"] = { - "position": [0.0, args.sensor_height, 0.0], - } + update_sensor_settings( + settings, uuid="color_sensor", position=[0.0, args.sensor_height, 0.0] + ) if args.semantic_sensor: - settings["sensors"]["semantic_sensor"] = { - "position": [0.0, args.sensor_height, 0.0], - "sensor_type": habitat_sim.SensorType.SEMANTIC, - } + update_sensor_settings( + settings, + uuid="semantic_sensor", + position=[0.0, args.sensor_height, 0.0], + sensor_type=habitat_sim.SensorType.SEMANTIC, + ) if args.depth_sensor: - settings["sensors"]["depth_sensor"] = { - "position": [0.0, args.sensor_height, 0.0], - "sensor_type": habitat_sim.SensorType.DEPTH, - } + update_sensor_settings( + settings, + uuid="depth_sensor", + position=[0.0, args.sensor_height, 0.0], + sensor_type=habitat_sim.SensorType.DEPTH, + ) return settings From 9a7a9de55f80ddaf214758f1508df88ae2dad2eb Mon Sep 17 00:00:00 2001 From: John Reyna Date: Fri, 2 Dec 2022 07:58:26 -0800 Subject: [PATCH 23/24] update ReplicaCAD_quickstart.py to use new update_sensor_settings function and refactored settings.py file --- .../colabs/ECCV_2020_Interactivity.ipynb | 4 +- .../colabs/ECCV_2020_Navigation.ipynb | 8 +-- .../colabs/ReplicaCAD_quickstart.ipynb | 62 ++++--------------- .../nb_python/ECCV_2020_Interactivity.py | 4 +- .../nb_python/ECCV_2020_Navigation.py | 6 +- .../nb_python/ReplicaCAD_quickstart.py | 62 ++++--------------- 6 files changed, 31 insertions(+), 115 deletions(-) diff --git a/examples/tutorials/colabs/ECCV_2020_Interactivity.ipynb b/examples/tutorials/colabs/ECCV_2020_Interactivity.ipynb index 0244e773a9..86278f7c0b 100644 --- a/examples/tutorials/colabs/ECCV_2020_Interactivity.ipynb +++ b/examples/tutorials/colabs/ECCV_2020_Interactivity.ipynb @@ -126,6 +126,7 @@ " \"\"\"\n", " create custom simulator settings. All sim settings not explicitly assigned are given default values\n", " \"\"\"\n", + " settings = default_sim_settings.copy()\n", " settings = {\n", " \"width\": 720, # Spatial resolution of the observations\n", " \"height\": 544,\n", @@ -134,9 +135,6 @@ " \"enable_physics\": True, # enable dynamics simulation\n", " }\n", "\n", - " # Instantiate all non-assigned elements of simulator settings to the default values\n", - " settings = {**default_sim_settings, **settings}\n", - "\n", " # add settings for a new sensor to the simulator settings. All sensor settings not\n", " # explicitly assigned are given default values\n", " update_sensor_settings(\n", diff --git a/examples/tutorials/colabs/ECCV_2020_Navigation.ipynb b/examples/tutorials/colabs/ECCV_2020_Navigation.ipynb index b30c8d9a7f..c60fc5a8ec 100644 --- a/examples/tutorials/colabs/ECCV_2020_Navigation.ipynb +++ b/examples/tutorials/colabs/ECCV_2020_Navigation.ipynb @@ -183,13 +183,13 @@ "# we support a variety of mesh formats, such as .glb, .gltf, .obj, .ply\n", "test_scene = \"./data/scene_datasets/mp3d_example/17DRP5sb8fy/17DRP5sb8fy.glb\"\n", "\n", + "sim_settings = default_sim_settings.copy()\n", "sim_settings = {\n", " \"scene\": test_scene, # Scene path\n", " \"default_agent\": 0, # Index of the default agent\n", " \"width\": 256, # Spatial resolution of the observations\n", " \"height\": 256,\n", - "}\n", - "sim_settings = {**default_sim_settings, **sim_settings}" + "}" ] }, { @@ -346,6 +346,7 @@ "depth_sensor = True # @param {type:\"boolean\"}\n", "semantic_sensor = True # @param {type:\"boolean\"}\n", "\n", + "sim_settings = default_sim_settings.copy()\n", "sim_settings = {\n", " \"width\": 256, # Spatial resolution of the observations\n", " \"height\": 256,\n", @@ -355,9 +356,6 @@ " \"enable_physics\": False, # kinematics only\n", "}\n", "\n", - "# Instantiate all non-assigned elements of simulator settings to the default values\n", - "sim_settings = {**default_sim_settings, **sim_settings}\n", - "\n", "# Add sensor settings to simulator settings\n", "if rgb_sensor:\n", " update_sensor_settings(sim_settings, \"color_sensor\")\n", diff --git a/examples/tutorials/colabs/ReplicaCAD_quickstart.ipynb b/examples/tutorials/colabs/ReplicaCAD_quickstart.ipynb index 2854194343..5b3b39d0b0 100644 --- a/examples/tutorials/colabs/ReplicaCAD_quickstart.ipynb +++ b/examples/tutorials/colabs/ReplicaCAD_quickstart.ipynb @@ -49,6 +49,11 @@ "\n", "import habitat_sim\n", "from habitat_sim.utils import viz_utils as vut\n", + "from habitat_sim.utils.settings import (\n", + " default_sim_settings,\n", + " make_cfg,\n", + " update_sensor_settings,\n", + ")\n", "\n", "try:\n", " import ipywidgets as widgets\n", @@ -99,64 +104,21 @@ "# @markdown (double click to show code)\n", "\n", "# @markdown This cell defines a number of utility functions used throughout the tutorial to make simulator reconstruction easy:\n", - "# @markdown - make_cfg\n", - "# @markdown - make_default_settings\n", + "# @markdown - make_custom_settings\n", "# @markdown - make_simulator_from_settings\n", "\n", "\n", - "def make_cfg(settings):\n", - " sim_cfg = habitat_sim.SimulatorConfiguration()\n", - " sim_cfg.gpu_device_id = 0\n", - " sim_cfg.scene_dataset_config_file = settings[\"scene_dataset\"]\n", - " sim_cfg.scene_id = settings[\"scene\"]\n", - " sim_cfg.enable_physics = settings[\"enable_physics\"]\n", - " # Specify the location of the scene dataset\n", - " if \"scene_dataset_config\" in settings:\n", - " sim_cfg.scene_dataset_config_file = settings[\"scene_dataset_config\"]\n", - " if \"override_scene_light_defaults\" in settings:\n", - " sim_cfg.override_scene_light_defaults = settings[\n", - " \"override_scene_light_defaults\"\n", - " ]\n", - " if \"scene_light_setup\" in settings:\n", - " sim_cfg.scene_light_setup = settings[\"scene_light_setup\"]\n", - "\n", - " # Note: all sensors must have the same resolution\n", - " sensor_specs = []\n", - " color_sensor_1st_person_spec = habitat_sim.CameraSensorSpec()\n", - " color_sensor_1st_person_spec.uuid = \"color_sensor_1st_person\"\n", - " color_sensor_1st_person_spec.sensor_type = habitat_sim.SensorType.COLOR\n", - " color_sensor_1st_person_spec.resolution = [\n", - " settings[\"height\"],\n", - " settings[\"width\"],\n", - " ]\n", - " color_sensor_1st_person_spec.position = [0.0, settings[\"sensor_height\"], 0.0]\n", - " color_sensor_1st_person_spec.orientation = [\n", - " settings[\"sensor_pitch\"],\n", - " 0.0,\n", - " 0.0,\n", - " ]\n", - " color_sensor_1st_person_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE\n", - " sensor_specs.append(color_sensor_1st_person_spec)\n", - "\n", - " # Here you can specify the amount of displacement in a forward action and the turn angle\n", - " agent_cfg = habitat_sim.agent.AgentConfiguration()\n", - " agent_cfg.sensor_specifications = sensor_specs\n", - "\n", - " return habitat_sim.Configuration(sim_cfg, [agent_cfg])\n", - "\n", - "\n", - "def make_default_settings():\n", + "def make_custom_settings():\n", + " settings = default_sim_settings.copy()\n", " settings = {\n", " \"width\": 1280, # Spatial resolution of the observations\n", " \"height\": 720,\n", - " \"scene_dataset\": \"data/replica_cad/replicaCAD.scene_dataset_config.json\", # dataset path\n", + " \"scene_dataset_config_file\": \"data/replica_cad/replicaCAD.scene_dataset_config.json\", # dataset path\n", " \"scene\": \"NONE\", # Scene path\n", - " \"default_agent\": 0,\n", - " \"sensor_height\": 1.5, # Height of sensors in meters\n", - " \"sensor_pitch\": 0, # sensor pitch (x rotation in rads)\n", - " \"seed\": 1,\n", " \"enable_physics\": True, # enable dynamics simulation\n", " }\n", + " # add sensor settings to sim settings\n", + " update_sensor_settings(settings, uuid=\"color_sensor_1st_person\")\n", " return settings\n", "\n", "\n", @@ -324,7 +286,7 @@ "# [initialize]\n", "# @title Initialize Simulator{ display-mode: \"form\" }\n", "\n", - "sim_settings = make_default_settings()\n", + "sim_settings = make_custom_settings()\n", "make_simulator_from_settings(sim_settings)\n", "# [/initialize]" ] diff --git a/examples/tutorials/nb_python/ECCV_2020_Interactivity.py b/examples/tutorials/nb_python/ECCV_2020_Interactivity.py index b914c1527a..27a2cb2ad6 100644 --- a/examples/tutorials/nb_python/ECCV_2020_Interactivity.py +++ b/examples/tutorials/nb_python/ECCV_2020_Interactivity.py @@ -117,6 +117,7 @@ def make_custom_settings(): """ create custom simulator settings. All sim settings not explicitly assigned are given default values """ + settings = default_sim_settings.copy() settings = { "width": 720, # Spatial resolution of the observations "height": 544, @@ -125,9 +126,6 @@ def make_custom_settings(): "enable_physics": True, # enable dynamics simulation } - # Instantiate all non-assigned elements of simulator settings to the default values - settings = {**default_sim_settings, **settings} - # add settings for a new sensor to the simulator settings. All sensor settings not # explicitly assigned are given default values update_sensor_settings( diff --git a/examples/tutorials/nb_python/ECCV_2020_Navigation.py b/examples/tutorials/nb_python/ECCV_2020_Navigation.py index 344099e721..6b7a9900cd 100644 --- a/examples/tutorials/nb_python/ECCV_2020_Navigation.py +++ b/examples/tutorials/nb_python/ECCV_2020_Navigation.py @@ -164,13 +164,13 @@ def display_sample(rgb_obs, semantic_obs=np.array([]), depth_obs=np.array([])): # we support a variety of mesh formats, such as .glb, .gltf, .obj, .ply test_scene = "./data/scene_datasets/mp3d_example/17DRP5sb8fy/17DRP5sb8fy.glb" +sim_settings = default_sim_settings.copy() sim_settings = { "scene": test_scene, # Scene path "default_agent": 0, # Index of the default agent "width": 256, # Spatial resolution of the observations "height": 256, } -sim_settings = {**default_sim_settings, **sim_settings} # %% [markdown] @@ -272,6 +272,7 @@ def navigateAndSee(action=""): depth_sensor = True # @param {type:"boolean"} semantic_sensor = True # @param {type:"boolean"} +sim_settings = default_sim_settings.copy() sim_settings = { "width": 256, # Spatial resolution of the observations "height": 256, @@ -281,9 +282,6 @@ def navigateAndSee(action=""): "enable_physics": False, # kinematics only } -# Instantiate all non-assigned elements of simulator settings to the default values -sim_settings = {**default_sim_settings, **sim_settings} - # Add sensor settings to simulator settings if rgb_sensor: update_sensor_settings(sim_settings, "color_sensor") diff --git a/examples/tutorials/nb_python/ReplicaCAD_quickstart.py b/examples/tutorials/nb_python/ReplicaCAD_quickstart.py index 73fd931dc2..e5fc96d4d1 100644 --- a/examples/tutorials/nb_python/ReplicaCAD_quickstart.py +++ b/examples/tutorials/nb_python/ReplicaCAD_quickstart.py @@ -49,6 +49,11 @@ import habitat_sim from habitat_sim.utils import viz_utils as vut +from habitat_sim.utils.settings import ( + default_sim_settings, + make_cfg, + update_sensor_settings, +) try: import ipywidgets as widgets @@ -92,64 +97,21 @@ # @markdown (double click to show code) # @markdown This cell defines a number of utility functions used throughout the tutorial to make simulator reconstruction easy: -# @markdown - make_cfg -# @markdown - make_default_settings +# @markdown - make_custom_settings # @markdown - make_simulator_from_settings -def make_cfg(settings): - sim_cfg = habitat_sim.SimulatorConfiguration() - sim_cfg.gpu_device_id = 0 - sim_cfg.scene_dataset_config_file = settings["scene_dataset"] - sim_cfg.scene_id = settings["scene"] - sim_cfg.enable_physics = settings["enable_physics"] - # Specify the location of the scene dataset - if "scene_dataset_config" in settings: - sim_cfg.scene_dataset_config_file = settings["scene_dataset_config"] - if "override_scene_light_defaults" in settings: - sim_cfg.override_scene_light_defaults = settings[ - "override_scene_light_defaults" - ] - if "scene_light_setup" in settings: - sim_cfg.scene_light_setup = settings["scene_light_setup"] - - # Note: all sensors must have the same resolution - sensor_specs = [] - color_sensor_1st_person_spec = habitat_sim.CameraSensorSpec() - color_sensor_1st_person_spec.uuid = "color_sensor_1st_person" - color_sensor_1st_person_spec.sensor_type = habitat_sim.SensorType.COLOR - color_sensor_1st_person_spec.resolution = [ - settings["height"], - settings["width"], - ] - color_sensor_1st_person_spec.position = [0.0, settings["sensor_height"], 0.0] - color_sensor_1st_person_spec.orientation = [ - settings["sensor_pitch"], - 0.0, - 0.0, - ] - color_sensor_1st_person_spec.sensor_subtype = habitat_sim.SensorSubType.PINHOLE - sensor_specs.append(color_sensor_1st_person_spec) - - # Here you can specify the amount of displacement in a forward action and the turn angle - agent_cfg = habitat_sim.agent.AgentConfiguration() - agent_cfg.sensor_specifications = sensor_specs - - return habitat_sim.Configuration(sim_cfg, [agent_cfg]) - - -def make_default_settings(): +def make_custom_settings(): + settings = default_sim_settings.copy() settings = { "width": 1280, # Spatial resolution of the observations "height": 720, - "scene_dataset": "data/replica_cad/replicaCAD.scene_dataset_config.json", # dataset path + "scene_dataset_config_file": "data/replica_cad/replicaCAD.scene_dataset_config.json", # dataset path "scene": "NONE", # Scene path - "default_agent": 0, - "sensor_height": 1.5, # Height of sensors in meters - "sensor_pitch": 0, # sensor pitch (x rotation in rads) - "seed": 1, "enable_physics": True, # enable dynamics simulation } + # add sensor settings to sim settings + update_sensor_settings(settings, uuid="color_sensor_1st_person") return settings @@ -297,7 +259,7 @@ def build_widget_ui(metadata_mediator): # [initialize] # @title Initialize Simulator{ display-mode: "form" } -sim_settings = make_default_settings() +sim_settings = make_custom_settings() make_simulator_from_settings(sim_settings) # [/initialize] From caaaa129a71ea0e01be3a1da54a629f654dbd932 Mon Sep 17 00:00:00 2001 From: John Reyna Date: Fri, 2 Dec 2022 08:19:37 -0800 Subject: [PATCH 24/24] update ReplicaCAD_quickstart.py to use new settings.py refactor and update_sensor_settings function. Also fixed an error I made setting the default sim settings in the ECCV scripts --- .../tutorials/colabs/ECCV_2020_Advanced_Features.ipynb | 1 - examples/tutorials/colabs/ECCV_2020_Interactivity.ipynb | 3 ++- examples/tutorials/colabs/ECCV_2020_Navigation.ipynb | 8 +++++--- examples/tutorials/colabs/ReplicaCAD_quickstart.ipynb | 7 ++++++- .../tutorials/nb_python/ECCV_2020_Advanced_Features.py | 1 - examples/tutorials/nb_python/ECCV_2020_Interactivity.py | 3 ++- examples/tutorials/nb_python/ECCV_2020_Navigation.py | 6 ++++-- examples/tutorials/nb_python/ReplicaCAD_quickstart.py | 7 ++++++- 8 files changed, 25 insertions(+), 11 deletions(-) diff --git a/examples/tutorials/colabs/ECCV_2020_Advanced_Features.ipynb b/examples/tutorials/colabs/ECCV_2020_Advanced_Features.ipynb index 12531892ff..1621a658f2 100644 --- a/examples/tutorials/colabs/ECCV_2020_Advanced_Features.ipynb +++ b/examples/tutorials/colabs/ECCV_2020_Advanced_Features.ipynb @@ -433,7 +433,6 @@ " \"scene_dataset_config_file\": \"./data/scene_datasets/mp3d_example/mp3d.scene_dataset_config.json\", # mp3d scene dataset\n", " \"enable_physics\": True, # enable dynamics simulation\n", " }\n", - "\n", " # Instantiate all non-assigned elements of simulator settings to the default values\n", " settings = {**default_sim_settings, **settings}\n", "\n", diff --git a/examples/tutorials/colabs/ECCV_2020_Interactivity.ipynb b/examples/tutorials/colabs/ECCV_2020_Interactivity.ipynb index 86278f7c0b..5c3a1e6154 100644 --- a/examples/tutorials/colabs/ECCV_2020_Interactivity.ipynb +++ b/examples/tutorials/colabs/ECCV_2020_Interactivity.ipynb @@ -126,7 +126,6 @@ " \"\"\"\n", " create custom simulator settings. All sim settings not explicitly assigned are given default values\n", " \"\"\"\n", - " settings = default_sim_settings.copy()\n", " settings = {\n", " \"width\": 720, # Spatial resolution of the observations\n", " \"height\": 544,\n", @@ -134,6 +133,8 @@ " \"scene_dataset_config_file\": \"./data/scene_datasets/mp3d_example/mp3d.scene_dataset_config.json\", # MP3D scene dataset\n", " \"enable_physics\": True, # enable dynamics simulation\n", " }\n", + " # Instantiate all non-assigned elements of simulator settings to the default values\n", + " settings = {**default_sim_settings, **settings}\n", "\n", " # add settings for a new sensor to the simulator settings. All sensor settings not\n", " # explicitly assigned are given default values\n", diff --git a/examples/tutorials/colabs/ECCV_2020_Navigation.ipynb b/examples/tutorials/colabs/ECCV_2020_Navigation.ipynb index c60fc5a8ec..d00bed5ad5 100644 --- a/examples/tutorials/colabs/ECCV_2020_Navigation.ipynb +++ b/examples/tutorials/colabs/ECCV_2020_Navigation.ipynb @@ -183,13 +183,14 @@ "# we support a variety of mesh formats, such as .glb, .gltf, .obj, .ply\n", "test_scene = \"./data/scene_datasets/mp3d_example/17DRP5sb8fy/17DRP5sb8fy.glb\"\n", "\n", - "sim_settings = default_sim_settings.copy()\n", "sim_settings = {\n", " \"scene\": test_scene, # Scene path\n", " \"default_agent\": 0, # Index of the default agent\n", " \"width\": 256, # Spatial resolution of the observations\n", " \"height\": 256,\n", - "}" + "}\n", + "# Instantiate all non-assigned elements of simulator settings to the default values\n", + "sim_settings = {**default_sim_settings, **sim_settings}" ] }, { @@ -346,7 +347,6 @@ "depth_sensor = True # @param {type:\"boolean\"}\n", "semantic_sensor = True # @param {type:\"boolean\"}\n", "\n", - "sim_settings = default_sim_settings.copy()\n", "sim_settings = {\n", " \"width\": 256, # Spatial resolution of the observations\n", " \"height\": 256,\n", @@ -355,6 +355,8 @@ " \"default_agent\": 0,\n", " \"enable_physics\": False, # kinematics only\n", "}\n", + "# Instantiate all non-assigned elements of simulator settings to the default values\n", + "sim_settings = {**default_sim_settings, **sim_settings}\n", "\n", "# Add sensor settings to simulator settings\n", "if rgb_sensor:\n", diff --git a/examples/tutorials/colabs/ReplicaCAD_quickstart.ipynb b/examples/tutorials/colabs/ReplicaCAD_quickstart.ipynb index 5b3b39d0b0..024397c616 100644 --- a/examples/tutorials/colabs/ReplicaCAD_quickstart.ipynb +++ b/examples/tutorials/colabs/ReplicaCAD_quickstart.ipynb @@ -109,7 +109,9 @@ "\n", "\n", "def make_custom_settings():\n", - " settings = default_sim_settings.copy()\n", + " \"\"\"\n", + " create custom simulator settings. All sim settings not explicitly assigned are given default values\n", + " \"\"\"\n", " settings = {\n", " \"width\": 1280, # Spatial resolution of the observations\n", " \"height\": 720,\n", @@ -117,6 +119,9 @@ " \"scene\": \"NONE\", # Scene path\n", " \"enable_physics\": True, # enable dynamics simulation\n", " }\n", + " # Instantiate all non-assigned elements of simulator settings to the default values\n", + " settings = {**default_sim_settings, **settings}\n", + "\n", " # add sensor settings to sim settings\n", " update_sensor_settings(settings, uuid=\"color_sensor_1st_person\")\n", " return settings\n", diff --git a/examples/tutorials/nb_python/ECCV_2020_Advanced_Features.py b/examples/tutorials/nb_python/ECCV_2020_Advanced_Features.py index fcc6b86d8d..5599cd2bca 100644 --- a/examples/tutorials/nb_python/ECCV_2020_Advanced_Features.py +++ b/examples/tutorials/nb_python/ECCV_2020_Advanced_Features.py @@ -424,7 +424,6 @@ def make_custom_settings(): "scene_dataset_config_file": "./data/scene_datasets/mp3d_example/mp3d.scene_dataset_config.json", # mp3d scene dataset "enable_physics": True, # enable dynamics simulation } - # Instantiate all non-assigned elements of simulator settings to the default values settings = {**default_sim_settings, **settings} diff --git a/examples/tutorials/nb_python/ECCV_2020_Interactivity.py b/examples/tutorials/nb_python/ECCV_2020_Interactivity.py index 27a2cb2ad6..b3a0712c60 100644 --- a/examples/tutorials/nb_python/ECCV_2020_Interactivity.py +++ b/examples/tutorials/nb_python/ECCV_2020_Interactivity.py @@ -117,7 +117,6 @@ def make_custom_settings(): """ create custom simulator settings. All sim settings not explicitly assigned are given default values """ - settings = default_sim_settings.copy() settings = { "width": 720, # Spatial resolution of the observations "height": 544, @@ -125,6 +124,8 @@ def make_custom_settings(): "scene_dataset_config_file": "./data/scene_datasets/mp3d_example/mp3d.scene_dataset_config.json", # MP3D scene dataset "enable_physics": True, # enable dynamics simulation } + # Instantiate all non-assigned elements of simulator settings to the default values + settings = {**default_sim_settings, **settings} # add settings for a new sensor to the simulator settings. All sensor settings not # explicitly assigned are given default values diff --git a/examples/tutorials/nb_python/ECCV_2020_Navigation.py b/examples/tutorials/nb_python/ECCV_2020_Navigation.py index 6b7a9900cd..2d0e003f4a 100644 --- a/examples/tutorials/nb_python/ECCV_2020_Navigation.py +++ b/examples/tutorials/nb_python/ECCV_2020_Navigation.py @@ -164,13 +164,14 @@ def display_sample(rgb_obs, semantic_obs=np.array([]), depth_obs=np.array([])): # we support a variety of mesh formats, such as .glb, .gltf, .obj, .ply test_scene = "./data/scene_datasets/mp3d_example/17DRP5sb8fy/17DRP5sb8fy.glb" -sim_settings = default_sim_settings.copy() sim_settings = { "scene": test_scene, # Scene path "default_agent": 0, # Index of the default agent "width": 256, # Spatial resolution of the observations "height": 256, } +# Instantiate all non-assigned elements of simulator settings to the default values +sim_settings = {**default_sim_settings, **sim_settings} # %% [markdown] @@ -272,7 +273,6 @@ def navigateAndSee(action=""): depth_sensor = True # @param {type:"boolean"} semantic_sensor = True # @param {type:"boolean"} -sim_settings = default_sim_settings.copy() sim_settings = { "width": 256, # Spatial resolution of the observations "height": 256, @@ -281,6 +281,8 @@ def navigateAndSee(action=""): "default_agent": 0, "enable_physics": False, # kinematics only } +# Instantiate all non-assigned elements of simulator settings to the default values +sim_settings = {**default_sim_settings, **sim_settings} # Add sensor settings to simulator settings if rgb_sensor: diff --git a/examples/tutorials/nb_python/ReplicaCAD_quickstart.py b/examples/tutorials/nb_python/ReplicaCAD_quickstart.py index e5fc96d4d1..d75b9f24a2 100644 --- a/examples/tutorials/nb_python/ReplicaCAD_quickstart.py +++ b/examples/tutorials/nb_python/ReplicaCAD_quickstart.py @@ -102,7 +102,9 @@ def make_custom_settings(): - settings = default_sim_settings.copy() + """ + create custom simulator settings. All sim settings not explicitly assigned are given default values + """ settings = { "width": 1280, # Spatial resolution of the observations "height": 720, @@ -110,6 +112,9 @@ def make_custom_settings(): "scene": "NONE", # Scene path "enable_physics": True, # enable dynamics simulation } + # Instantiate all non-assigned elements of simulator settings to the default values + settings = {**default_sim_settings, **settings} + # add sensor settings to sim settings update_sensor_settings(settings, uuid="color_sensor_1st_person") return settings