habitat.core.dataset.EpisodeIterator class

Episode Iterator class that gives options for how a list of episodes should be iterated.

Some options are desirable for better internal simulator performance.

More context: simulator suffers overhead when switching between scenes, therefore episodes of the same scene should be consecutively loaded. However, if too many consecutive episodes from same scene are feed into RL model, the model will risk overfitting that scene. Therefore it’s better to load same scene consecutively and switch once a number threshold is reached.

Currently supports the following features:

  • Cycling: when all episodes are iterated, cycle back to start instead of throwing StopIteration.
  • Cycling with shuffle: when cycling back, shuffle episodes groups grouped by scene.
  • Group by scene: episodes of same scene will be grouped and loaded consecutively.
  • Set max scene repeat: set a number threshold on how many episodes from the same scene can be loaded consecutively.
  • Sample episodes: sample the specified number of episodes.

Static methods

def _randomize_value(value: int, value_range: float) -> int
Generates a random int from a uniform distribution centered at value within the provided range of variance.

Methods

def _forced_scene_switch(self) -> None
Internal method to switch the scene. Moves remaining episodes from current scene to the end and switch to next scene episodes.
def _forced_scene_switch_if(self) -> None
Triggers switching scenes and re-organizes the Episode queue if the maximum number of repetitions or steps per-scene has been reached.
def _group_scenes(self, episodes: typing.Union[typing.Sequence[Episode], typing.List[Episode], numpy.ndarray]) -> typing.List[T]
Internal method that groups episodes by scene Groups will be ordered by the order their first episode’s appearance in the list of episodes.
def _set_shuffle_intervals(self) -> None
Sets or samples the maximum number of repeated episodes for a scene before shuffling.
def _shuffle(self) -> None
Internal method that shuffles the remaining episodes. If self.group_by_scene is true, then shuffle groups of scenes.
def set_next_episode_by_id(self, episode_id: str) -> None
Set the next episode to run by episode ID. The new episode will be loading upon resetting the simulator.
def set_next_episode_by_index(self, episode_index: int) -> None
Set the next episode to run by episode index. The new episode will be loading upon resetting the simulator.
def step_taken(self) -> None
Increments the step counter.

Special methods

def __class_getitem__(...)
Represent a PEP 585 generic type
def __init__(self, episodes: typing.Sequence[T], cycle: bool = True, shuffle: bool = False, group_by_scene: bool = True, max_scene_repeat_episodes: int = -1, max_scene_repeat_steps: int = -1, num_episode_sample: int = -1, step_repetition_range: float = 0.2, seed: typing.Optional[int] = None) -> None
def __iter__(self) -> EpisodeIterator
def __next__(self) -> Episode
Main logic for handling how episodes iterate.
def __subclasshook__(C)

Method documentation

def habitat.core.dataset.EpisodeIterator._randomize_value(value: int, value_range: float) -> int staticmethod

Generates a random int from a uniform distribution centered at value within the provided range of variance.

Parameters
value The int mean of the distribution for the sample.
value_range The float [0,1] which indicates the range of the sampling distribution as a ratio of the mean. For example, value_range==0.1 would produce a uniformly sampled value with a maximum 10% deviation of the mean [value*0.9, value*1.1].
Returns The randomly sampled value from the distribution.

def habitat.core.dataset.EpisodeIterator._group_scenes(self, episodes: typing.Union[typing.Sequence[Episode], typing.List[Episode], numpy.ndarray]) -> typing.List[T]

Internal method that groups episodes by scene Groups will be ordered by the order their first episode’s appearance in the list of episodes.

Parameters
episodes The Episodes to group and re-order.
Returns The Episodes grouped and re-orderd by scene.

So if the episodes list shuffled before calling this method, the scenes will be in a random order.

def habitat.core.dataset.EpisodeIterator.set_next_episode_by_id(self, episode_id: str) -> None

Set the next episode to run by episode ID. The new episode will be loading upon resetting the simulator.

Parameters
episode_id The desired id string for the next Episode queued by the iterator.

def habitat.core.dataset.EpisodeIterator.set_next_episode_by_index(self, episode_index: int) -> None

Set the next episode to run by episode index. The new episode will be loading upon resetting the simulator.

Parameters
episode_index The desired index for the next Episode queued by the iterator.

def habitat.core.dataset.EpisodeIterator.__class_getitem__(...) classmethod

Represent a PEP 585 generic type

E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).

def habitat.core.dataset.EpisodeIterator.__init__(self, episodes: typing.Sequence[T], cycle: bool = True, shuffle: bool = False, group_by_scene: bool = True, max_scene_repeat_episodes: int = -1, max_scene_repeat_steps: int = -1, num_episode_sample: int = -1, step_repetition_range: float = 0.2, seed: typing.Optional[int] = None) -> None

Parameters
episodes list of episodes.
cycle if True, cycle back to first episodes when StopIteration.
shuffle if True, shuffle scene groups when cycle. No effect if cycle is set to False. Will shuffle grouped scenes if group_by_scene is True.
group_by_scene if True, group episodes from same scene.
max_scene_repeat_episodes threshold of how many episodes from the same scene can be loaded consecutively. -1 for no limit
max_scene_repeat_steps threshold of how many steps from the same scene can be taken consecutively. -1 for no limit
num_episode_sample number of episodes to be sampled. -1 for no sampling.
step_repetition_range The maximum number of steps within each scene is uniformly drawn from [1 - step_repeat_range, 1 + step_repeat_range] * max_scene_repeat_steps on each scene switch. This stops all workers from swapping scenes at the same time
seed Provide an option random seed (for numpy and random module) to make shuffling behavior deterministic.

def habitat.core.dataset.EpisodeIterator.__next__(self) -> Episode

Main logic for handling how episodes iterate.

Returns next episode.