Esempio n. 1
0
 def valid_task_sampler_args(
     self,
     process_ind: int,
     total_processes: int,
     devices: Optional[List[int]] = None,
     seeds: Optional[List[int]] = None,
     deterministic_cudnn: bool = False,
 ) -> Dict[str, Any]:
     if total_processes != 1:
         raise NotImplementedError(
             "In validation, `total_processes` must equal 1 for habitat tasks"
         )
     config = self.CONFIG.clone()
     config.defrost()
     config.DATASET.DATA_PATH = self.VALID_SCENES
     config.MODE = "validate"
     config.freeze()
     return {
         "env_config":
         config,
         "max_steps":
         self.MAX_STEPS,
         "sensors":
         self.SENSORS,
         "action_space":
         gym.spaces.Discrete(len(PointNavTask.class_action_names())),
         "distance_to_goal":
         self.DISTANCE_TO_GOAL,
     }
    def next_task(self, force_advance_scene=False) -> PointNavTask:
        if self.max_tasks is not None and self.max_tasks <= 0:
            return None

        if self.env is not None:
            self.env.reset()
        else:
            self.env = self._create_environment()
            self.env.reset()
        ep_info = self.env.get_current_episode()
        target = ep_info.goals[0].position

        task_info = {
            "target": target,
            "distance_to_goal": self.distance_to_goal,
        }

        self._last_sampled_task = PointNavTask(
            env=self.env,
            sensors=self.sensors,
            task_info=task_info,
            max_steps=self.max_steps,
            action_space=self._action_space,
        )

        if self.max_tasks is not None:
            self.max_tasks -= 1

        return self._last_sampled_task
class PointNavHabitatRGBDeterministiSimpleConvGRUImitationExperimentConfig(
        DebugPointNavHabitatBaseConfig, PointNavMixInSimpleConvGRUConfig):
    """An Point Navigation experiment configuration in Habitat with Depth
    input."""

    SENSORS = [
        RGBSensorHabitat(
            height=DebugPointNavHabitatBaseConfig.SCREEN_SIZE,
            width=DebugPointNavHabitatBaseConfig.SCREEN_SIZE,
            use_resnet_normalization=True,
        ),
        TargetCoordinatesSensorHabitat(coordinate_dims=2),
        ExpertActionSensor(nactions=len(PointNavTask.class_action_names())),
    ]

    @classmethod
    def tag(cls):
        return "Debug-Pointnav-Habitat-RGB-SimpleConv-BC"

    @classmethod
    def training_pipeline(cls, **kwargs):
        imitate_steps = int(75000000)
        lr = 3e-4
        num_mini_batch = 1
        update_repeats = 3
        num_steps = 30
        save_interval = 5000000
        log_interval = 10000 if torch.cuda.is_available() else 1
        gamma = 0.99
        use_gae = True
        gae_lambda = 0.95
        max_grad_norm = 0.5
        return TrainingPipeline(
            save_interval=save_interval,
            metric_accumulate_interval=log_interval,
            optimizer_builder=Builder(optim.Adam, dict(lr=lr)),
            num_mini_batch=num_mini_batch,
            update_repeats=update_repeats,
            max_grad_norm=max_grad_norm,
            num_steps=num_steps,
            named_losses={"imitation_loss": Imitation()},
            gamma=gamma,
            use_gae=use_gae,
            gae_lambda=gae_lambda,
            advance_scene_rollout_period=cls.ADVANCE_SCENE_ROLLOUT_PERIOD,
            pipeline_stages=[
                PipelineStage(
                    loss_names=["imitation_loss"],
                    max_stage_steps=imitate_steps,
                    # teacher_forcing=LinearDecay(steps=int(1e5), startp=1.0, endp=0.0,),
                ),
            ],
            lr_scheduler_builder=Builder(
                LambdaLR, {"lr_lambda": LinearDecay(steps=imitate_steps)}),
        )
Esempio n. 4
0
 def create_model(cls, **kwargs) -> nn.Module:
     return PointNavActorCriticSimpleConvRNN(
         action_space=gym.spaces.Discrete(
             len(PointNavTask.class_action_names())),
         observation_space=kwargs["observation_set"].observation_spaces,
         goal_sensor_uuid="target_coordinates_ind",
         hidden_size=512,
         embed_coordinates=False,
         coordinate_dims=2,
         num_rnn_layers=1,
         rnn_type="GRU",
     )
Esempio n. 5
0
 def test_task_sampler_args(
     self,
     process_ind: int,
     total_processes: int,
     devices: Optional[List[int]] = None,
     seeds: Optional[List[int]] = None,
     deterministic_cudnn: bool = False,
 ) -> Dict[str, Any]:
     config = self.TEST_CONFIG_PER_PROCESS[process_ind]
     return {
         "env_config":
         config,
         "max_steps":
         self.MAX_STEPS,
         "sensors":
         self.SENSORS,
         "action_space":
         gym.spaces.Discrete(len(PointNavTask.class_action_names())),
         "distance_to_goal":
         self.DISTANCE_TO_GOAL,
     }
Esempio n. 6
0
 def train_task_sampler_args(
     self,
     process_ind: int,
     total_processes: int,
     devices: Optional[List[int]] = None,
     seeds: Optional[List[int]] = None,
     deterministic_cudnn: bool = False,
 ) -> Dict[str, Any]:
     config = self.TRAIN_CONFIGS[process_ind]
     return {
         "env_config":
         config,
         "max_steps":
         self.MAX_STEPS,
         "sensors":
         self.SENSORS,
         "action_space":
         gym.spaces.Discrete(len(PointNavTask.class_action_names())),
         "distance_to_goal":
         self.DISTANCE_TO_GOAL,
         # "filter_dataset_func": DebugPointNavHabitatBaseConfig.make_easy_dataset,
     }
    def __init__(self):
        super().__init__()
        self.SENSORS = [
            RGBSensorHabitat(
                height=self.SCREEN_SIZE,
                width=self.SCREEN_SIZE,
                use_resnet_normalization=True,
            ),
            TargetCoordinatesSensorHabitat(coordinate_dims=2),
            ExpertActionSensor(
                nactions=len(PointNavTask.class_action_names())),
        ]

        self.PREPROCESSORS = []

        self.OBSERVATIONS = ["rgb", "target_coordinates_ind", "expert_action"]

        self.CONFIG = self.CONFIG.clone()
        self.CONFIG.SIMULATOR.AGENT_0.SENSORS = ["RGB_SENSOR"]

        self.TRAIN_CONFIGS = construct_env_configs(config=self.CONFIG,
                                                   allow_scene_repeat=True)