Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make_cfg refactoring in examples/tutorial/ #1924

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions examples/demo_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
27 changes: 9 additions & 18 deletions examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
122 changes: 16 additions & 106 deletions examples/tutorials/colabs/ECCV_2020_Advanced_Features.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -413,117 +414,27 @@
"# @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",
" \"sensors\": {\n",
" \"color_sensor_1st_person\": {\n",
" \"position\": [0, 1.5, 0],\n",
" \"orientation\": [-math.pi / 8.0, 0, 0],\n",
" },\n",
" },\n",
" \"seed\": 1,\n",
" \"enable_physics\": True, # enable dynamics simulation\n",
" }\n",
" settings = {**default_sim_settings, **settings}\n",
" return settings\n",
"\n",
"\n",
Expand Down Expand Up @@ -885,9 +796,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)"
]
Expand Down Expand Up @@ -1074,10 +984,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",
Expand Down Expand Up @@ -1177,9 +1088,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",
Expand Down
Loading