Skip to content

Commit

Permalink
updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mino committed Oct 28, 2022
1 parent 5889712 commit 7a4e545
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 50 deletions.
72 changes: 45 additions & 27 deletions src_python/habitat_sim/utils/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down
11 changes: 5 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions tests/test_gfx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 17 additions & 3 deletions tests/test_physics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion tests/test_semantic_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
28 changes: 20 additions & 8 deletions tests/test_sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion tests/test_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7a4e545

Please sign in to comment.