diff --git a/allenact/utils/inference.py b/allenact/utils/inference.py index 9fef87086..4549ef936 100644 --- a/allenact/utils/inference.py +++ b/allenact/utils/inference.py @@ -13,8 +13,8 @@ DistributionType, ) from allenact.base_abstractions.preprocessor import SensorPreprocessorGraph -from allenact.utils.tensor_utils import batch_observations from allenact.utils import spaces_utils as su +from allenact.utils.tensor_utils import batch_observations @attr.s(kw_only=True) @@ -121,7 +121,7 @@ def act(self, observations: ObservationType): self.steps_taken_in_task += 1 - if self.steps_taken_in_task % self.steps_before_rollout_refresh: + if self.steps_taken_in_task % self.steps_before_rollout_refresh == 0: self.rollout_storage.after_updates() return su.action_list(self.actor_critic.action_space, self.last_action_flat)[0] diff --git a/projects/objectnav_baselines/experiments/clip/mixins.py b/projects/objectnav_baselines/experiments/clip/mixins.py index 8ef3b59fa..09e7f3b84 100644 --- a/projects/objectnav_baselines/experiments/clip/mixins.py +++ b/projects/objectnav_baselines/experiments/clip/mixins.py @@ -67,7 +67,7 @@ def preprocessors(self) -> Sequence[Union[Preprocessor, Builder[Preprocessor]]]: return preprocessors - def create_model(self, num_actions: int, **kwargs) -> nn.Module: + def create_model(self, num_actions: int, add_prev_actions: bool, **kwargs) -> nn.Module: has_rgb = any(isinstance(s, RGBSensor) for s in self.sensors) has_depth = any(isinstance(s, DepthSensor) for s in self.sensors) @@ -84,4 +84,5 @@ def create_model(self, num_actions: int, **kwargs) -> nn.Module: depth_resnet_preprocessor_uuid="depth_clip_resnet" if has_depth else None, hidden_size=512, goal_dims=32, + add_prev_actions=add_prev_actions ) diff --git a/projects/objectnav_baselines/experiments/habitat/clip/objectnav_habitat_rgb_clipresnet50gru_ddppo.py b/projects/objectnav_baselines/experiments/habitat/clip/objectnav_habitat_rgb_clipresnet50gru_ddppo.py index 3826f75d8..7d255d8fc 100644 --- a/projects/objectnav_baselines/experiments/habitat/clip/objectnav_habitat_rgb_clipresnet50gru_ddppo.py +++ b/projects/objectnav_baselines/experiments/habitat/clip/objectnav_habitat_rgb_clipresnet50gru_ddppo.py @@ -64,7 +64,7 @@ def preprocessors(self) -> Sequence[Union[Preprocessor, Builder[Preprocessor]]]: def create_model(self, **kwargs) -> nn.Module: return self.preprocessing_and_model.create_model( - num_actions=self.ACTION_SPACE.n, **kwargs + num_actions=self.ACTION_SPACE.n, add_prev_actions=self.add_prev_actions, **kwargs ) def tag(self): diff --git a/projects/objectnav_baselines/experiments/habitat/objectnav_habitat_base.py b/projects/objectnav_baselines/experiments/habitat/objectnav_habitat_base.py index 2ae1b4f52..7e23353d4 100644 --- a/projects/objectnav_baselines/experiments/habitat/objectnav_habitat_base.py +++ b/projects/objectnav_baselines/experiments/habitat/objectnav_habitat_base.py @@ -6,13 +6,12 @@ from typing import Dict, Any, List, Optional, Sequence, Union import gym - -# noinspection PyUnresolvedReferences -import habitat import numpy as np import torch from torch.distributions.utils import lazy_property +# noinspection PyUnresolvedReferences +import habitat from allenact.base_abstractions.experiment_config import MachineParams from allenact.base_abstractions.preprocessor import ( SensorPreprocessorGraph, @@ -116,7 +115,6 @@ class ObjectNavHabitatBaseConfig(ObjectNavBaseConfig, ABC): # CPCA8Loss.UUID, # CPCA16Loss.UUID, ] - ADD_PREV_ACTIONS = False MULTIPLE_BELIEFS = False BELIEF_FUSION = ( # choose one None @@ -149,6 +147,7 @@ def __init__( train_gpu_ids: Optional[Sequence[int]] = None, val_gpu_ids: Optional[Sequence[int]] = None, test_gpu_ids: Optional[Sequence[int]] = None, + add_prev_actions: bool = False, **kwargs, ): super().__init__(**kwargs) @@ -172,6 +171,7 @@ def v_or_default(v, default): val_gpu_ids, self.DEFAULT_VALID_GPU_IDS if run_valid else [] ) self.test_gpu_ids = v_or_default(test_gpu_ids, self.DEFAULT_TEST_GPU_IDS) + self.add_prev_actions = add_prev_actions def _create_config( self, @@ -355,7 +355,10 @@ def test_scenes_path(self): # return self.TASK_DATA_DIR_TEMPLATE.format(*(["test"] * 2)) def tag(self): - return f"ObjectNav-Habitat-{self.scene_dataset.upper()}" + t = f"ObjectNav-Habitat-{self.scene_dataset.upper()}" + if not self.add_prev_actions: + return t + return f"{t}-PrevActions" def preprocessors(self) -> Sequence[Union[Preprocessor, Builder[Preprocessor]]]: return tuple() diff --git a/projects/objectnav_baselines/experiments/robothor/clip/objectnav_robothor_rgb_clipresnet50gru_ddppo.py b/projects/objectnav_baselines/experiments/robothor/clip/objectnav_robothor_rgb_clipresnet50gru_ddppo.py index e9db7aae0..b027e27b9 100644 --- a/projects/objectnav_baselines/experiments/robothor/clip/objectnav_robothor_rgb_clipresnet50gru_ddppo.py +++ b/projects/objectnav_baselines/experiments/robothor/clip/objectnav_robothor_rgb_clipresnet50gru_ddppo.py @@ -38,7 +38,7 @@ class ObjectNavRoboThorClipRGBPPOExperimentConfig(ObjectNavRoboThorBaseConfig): ), ] - def __init__(self, **kwargs): + def __init__(self, add_prev_actions: bool = False, **kwargs): super().__init__(**kwargs) self.preprocessing_and_model = ClipResNetPreprocessGRUActorCriticMixin( @@ -47,6 +47,7 @@ def __init__(self, **kwargs): screen_size=self.SCREEN_SIZE, goal_sensor_type=GoalObjectTypeThorSensor, ) + self.add_prev_actions = add_prev_actions def training_pipeline(self, **kwargs) -> TrainingPipeline: return ObjectNavPPOMixin.training_pipeline( @@ -60,7 +61,7 @@ def preprocessors(self) -> Sequence[Union[Preprocessor, Builder[Preprocessor]]]: def create_model(self, **kwargs) -> nn.Module: return self.preprocessing_and_model.create_model( - num_actions=self.ACTION_SPACE.n, **kwargs + num_actions=self.ACTION_SPACE.n, add_prev_actions=self.add_prev_actions, **kwargs ) @classmethod diff --git a/projects/objectnav_baselines/experiments/robothor/clip/objectnav_robothor_rgb_clipresnet50x16gru_ddppo.py b/projects/objectnav_baselines/experiments/robothor/clip/objectnav_robothor_rgb_clipresnet50x16gru_ddppo.py index 80220d4aa..e772ae9f5 100644 --- a/projects/objectnav_baselines/experiments/robothor/clip/objectnav_robothor_rgb_clipresnet50x16gru_ddppo.py +++ b/projects/objectnav_baselines/experiments/robothor/clip/objectnav_robothor_rgb_clipresnet50x16gru_ddppo.py @@ -38,7 +38,7 @@ class ObjectNavRoboThorRGBPPOExperimentConfig(ObjectNavRoboThorBaseConfig): ), ] - def __init__(self, **kwargs): + def __init__(self, add_prev_actions: bool = False, **kwargs): super().__init__(**kwargs) self.preprocessing_and_model = ClipResNetPreprocessGRUActorCriticMixin( @@ -47,6 +47,7 @@ def __init__(self, **kwargs): screen_size=self.SCREEN_SIZE, goal_sensor_type=GoalObjectTypeThorSensor, ) + self.add_prev_actions = add_prev_actions def training_pipeline(self, **kwargs) -> TrainingPipeline: return ObjectNavPPOMixin.training_pipeline( @@ -60,7 +61,7 @@ def preprocessors(self) -> Sequence[Union[Preprocessor, Builder[Preprocessor]]]: def create_model(self, **kwargs) -> nn.Module: return self.preprocessing_and_model.create_model( - num_actions=self.ACTION_SPACE.n, **kwargs + num_actions=self.ACTION_SPACE.n, add_prev_actions=self.add_prev_actions, **kwargs ) @classmethod diff --git a/projects/pointnav_baselines/experiments/habitat/clip/pointnav_habitat_rgb_clipresnet50gru_ddppo.py b/projects/pointnav_baselines/experiments/habitat/clip/pointnav_habitat_rgb_clipresnet50gru_ddppo.py index 3375b8c7a..c3271d6d8 100644 --- a/projects/pointnav_baselines/experiments/habitat/clip/pointnav_habitat_rgb_clipresnet50gru_ddppo.py +++ b/projects/pointnav_baselines/experiments/habitat/clip/pointnav_habitat_rgb_clipresnet50gru_ddppo.py @@ -35,7 +35,7 @@ class PointNavHabitatRGBClipResNet50GRUDDPPOExperimentConfig(PointNavHabitatBase TargetCoordinatesSensorHabitat(coordinate_dims=2), ] - def __init__(self, **kwargs): + def __init__(self, add_prev_actions: bool = False, **kwargs): super().__init__(**kwargs) self.preprocessing_and_model = ClipResNetPreprocessGRUActorCriticMixin( @@ -44,6 +44,7 @@ def __init__(self, **kwargs): screen_size=self.SCREEN_SIZE, goal_sensor_type=TargetCoordinatesSensorHabitat, ) + self.add_prev_actions = add_prev_actions def training_pipeline(self, **kwargs) -> TrainingPipeline: return PointNavPPOMixin.training_pipeline( @@ -58,7 +59,9 @@ def preprocessors(self) -> Sequence[Union[Preprocessor, Builder[Preprocessor]]]: def create_model(self, **kwargs) -> nn.Module: return self.preprocessing_and_model.create_model( - num_actions=self.ACTION_SPACE.n, **kwargs + num_actions=self.ACTION_SPACE.n, + add_prev_actions=self.add_prev_actions, + **kwargs, ) @classmethod