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

Filter deactivated sensors. #2078

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions habitat-lab/habitat/config/default_structured_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1887,6 +1887,9 @@ class GymConfig(HabitatBaseConfig):
action_keys: Optional[List[str]] = None
achieved_goal_keys: List = field(default_factory=list)
desired_goal_keys: List[str] = field(default_factory=list)
# When `True`, all visual sensors excluded from `obs_keys` are removed from the simulation.
# Beware: Some high-level sensors depend on other sensors, e.g. `humanoid_detector_sensor` depends on a RGB camera. In this case, if the RGB camera is not listed in `obs_keys`, it will be culled, breaking the parent sensor.
cull_unused_visual_sensors: Optional[bool] = False


@dataclass
Expand Down
16 changes: 16 additions & 0 deletions habitat-lab/habitat/core/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,22 @@ def __init__(
else:
self.number_of_episodes = None

# Filter out visual sensors from the habitat-sim config that aren't used by this Gym env.
if config.gym.cull_unused_visual_sensors:
gym_sensors = config.gym.obs_keys
agent_configs = config.simulator.agents
with read_write(agent_configs):
for agent_name, agent_config in agent_configs.items():
gym_sim_sensors = {}
for (
sensor_key,
sensor_config,
) in agent_config.sim_sensors.items():
sensor_uuid = f"{agent_name}_{sensor_config.uuid}"
if sensor_uuid in gym_sensors:
gym_sim_sensors[sensor_key] = sensor_config
agent_config.sim_sensors = gym_sim_sensors

self._sim = make_sim(
id_sim=self._config.simulator.type, config=self._config.simulator
)
Expand Down