Esempio n. 1
0
    def __init__(
        self,
        object_types: List[str],
        target_to_detector_map: Optional[Dict[str, str]] = None,
        detector_types: Optional[List[str]] = None,
        uuid: str = "goal_object_type_ind",
        **kwargs: Any
    ):
        self.ordered_object_types = list(object_types)
        assert self.ordered_object_types == sorted(
            self.ordered_object_types
        ), "object types input to goal object type sensor must be ordered"

        if target_to_detector_map is None:
            self.object_type_to_ind = {
                ot: i for i, ot in enumerate(self.ordered_object_types)
            }

            observation_space = gym.spaces.Discrete(len(self.ordered_object_types))
        else:
            assert (
                detector_types is not None
            ), "Missing detector_types for map {}".format(target_to_detector_map)
            self.target_to_detector = target_to_detector_map
            self.detector_types = detector_types

            detector_index = {ot: i for i, ot in enumerate(self.detector_types)}
            self.object_type_to_ind = {
                ot: detector_index[self.target_to_detector[ot]]
                for ot in self.ordered_object_types
            }

            observation_space = gym.spaces.Discrete(len(self.detector_types))

        super().__init__(**prepare_locals_for_super(locals()))
Esempio n. 2
0
    def __init__(
        self,
        action_space: gym.spaces.Discrete,
        observation_space: gym.spaces.Dict,
        rgb_uuid: str,
        unshuffled_rgb_uuid: str,
        in_walkthrough_phase_uuid: str,
        is_walkthrough_phase_embedding_dim: int,
        done_action_index: int,
        walkthrougher_should_ignore_action_mask: Optional[
            Sequence[float]] = None,
        prev_action_embedding_dim: int = 32,
        hidden_size=512,
        num_rnn_layers=1,
        rnn_type="GRU",
    ):
        """A CNN->RNN for joint training of the Walkthrough and Unshuffle tasks
        that expects ResNet features instead of RGB images.

        Nearly identical to `TwoPhaseRearrangeActorCriticSimpleConvRNN`
        but `rgb_uuid` should now be the unique id of the
        ResNetPreprocessor used to featurize RGB images using a
        pretrained ResNet before they're passed to this model.
        """
        self.visual_attention: Optional[nn.Module] = None
        super().__init__(**prepare_locals_for_super(locals()))
Esempio n. 3
0
    def __init__(self,
                 use_normalization: bool = False,
                 mean: Optional[np.ndarray] = np.array([[0.5]],
                                                       dtype=np.float32),
                 stdev: Optional[np.ndarray] = np.array([[0.25]],
                                                        dtype=np.float32),
                 height: Optional[int] = None,
                 width: Optional[int] = None,
                 uuid: str = "depth",
                 output_shape: Optional[Tuple[int, ...]] = None,
                 output_channels: int = 1,
                 unnormalized_infimum: float = 0.0,
                 unnormalized_supremum: float = 5.0,
                 scale_first: bool = True,
                 **kwargs: Any):
        """Initializer.

        # Parameters

        config : If `config["use_normalization"]` is `True` then the depth images will be normalized
            with mean 0.5 and standard deviation 0.25. If both `config["height"]` and `config["width"]` are
            non-negative integers then the depth image returned from the environment will be rescaled to have shape
            (config["height"], config["width"]) using bilinear sampling.
        args : Extra args. Currently unused.
        kwargs : Extra kwargs. Currently unused.
        """

        if not use_normalization:
            mean, stdev = None, None

        super().__init__(**prepare_locals_for_super(locals()))
Esempio n. 4
0
 def __init__(self,
              uuid: str = "relative_current_obj_state",
              **kwargs: Any):
     observation_space = gym.spaces.Box(
         low=-100, high=100, shape=(6, ), dtype=np.float32
     )  # (low=-1.0, high=2.0, shape=(3, 4), dtype=np.float32)
     super().__init__(**prepare_locals_for_super(locals()))
Esempio n. 5
0
    def __init__(
        self,
        action_space: gym.spaces.Discrete,
        observation_space: SpaceDict,
        num_objects: int,
        num_colors: int,
        num_states: int,
        object_embedding_dim: int = 8,
        **kwargs,
    ):
        super().__init__(**prepare_locals_for_super(locals()))

        agent_view_x, agent_view_y, view_channels = observation_space[
            "minigrid_ego_image"].shape
        self.actor_critic = LinearActorCritic(
            self.ac_key,
            action_space=action_space,
            observation_space=SpaceDict({
                self.ac_key:
                gym.spaces.Box(
                    low=np.float32(-1.0),
                    high=np.float32(1.0),
                    shape=(self.object_embedding_dim * agent_view_x *
                           agent_view_y * view_channels, ),
                )
            }),
        )
        self.memory_key = None

        self.train()
Esempio n. 6
0
 def __init__(self, uuid: str = "target_coordinates_ind", **kwargs: Any):
     observation_space = gym.spaces.Box(
         low=np.finfo(np.float32).min,
         high=np.finfo(np.float32).max,
         shape=(2,),
         dtype=np.float32,
     )
     super().__init__(**prepare_locals_for_super(locals()))
Esempio n. 7
0
    def __init__(
        self, coordinate_dims: int, uuid: str = "target_coordinates_ind", **kwargs: Any
    ):
        self.coordinate_dims = coordinate_dims

        observation_space = self._get_observation_space()

        super().__init__(**prepare_locals_for_super(locals()))
Esempio n. 8
0
    def __init__(
            self,
            uuid: str = "missing_action_mask",
            **kwargs: Any
    ) -> None:
        observation_space = self._get_observation_space()

        super().__init__(**prepare_locals_for_super(locals()))
Esempio n. 9
0
 def __init__(self, uuid: str = "rel_position", **kwargs: Any):
     observation_space = gym.spaces.Box(
         low=np.array([-np.inf, -np.inf, -360], dtype=np.float32),
         high=np.array([-np.inf, -np.inf, 360], dtype=np.float32),
         shape=(3, ),
         dtype=np.float32,
     )
     super().__init__(**prepare_locals_for_super(locals()))
Esempio n. 10
0
    def __init__(
        self,
        *,  # Disables positional arguments. Please provide arguments as keyword arguments.
        loss_names: List[str],
        max_stage_steps: Union[int, Callable],
        loss_weights: Optional[Sequence[float]] = None,
        loss_update_repeats: Optional[Sequence[int]] = None,
        teacher_forcing: Optional[LinearDecay] = None,
        offpolicy_component: Optional[OffPolicyPipelineComponent] = None,
        early_stopping_criterion: Optional[EarlyStoppingCriterion] = None,
        num_mini_batch: Optional[int] = None,
        update_repeats: Optional[int] = None,
        max_grad_norm: Optional[float] = None,
        num_steps: Optional[int] = None,
        gamma: Optional[float] = None,
        use_gae: Optional[bool] = None,
        gae_lambda: Optional[float] = None,
        advance_scene_rollout_period: Optional[int] = None,
        save_interval: Optional[int] = None,
        metric_accumulate_interval: Optional[int] = None,
    ):
        self._update_repeats: Optional[int] = None

        # Populate TrainingSettings members
        super().__init__(**prepare_locals_for_super(locals()))

        self.loss_names = loss_names
        self.max_stage_steps = max_stage_steps

        self.loss_weights = loss_weights
        self.loss_update_repeats = loss_update_repeats

        assert self.loss_weights is None or len(self.loss_weights) == len(
            self.loss_names
        )
        assert self.loss_update_repeats is None or (
            len(self.loss_update_repeats) == len(self.loss_names)
            and self._update_repeats is None
        )

        self.teacher_forcing = teacher_forcing
        self.offpolicy_component = offpolicy_component
        self.early_stopping_criterion = early_stopping_criterion

        self.steps_taken_in_stage: int = 0
        self.rollout_count = 0
        self.early_stopping_criterion_met = False

        self.named_losses: Optional[Dict[str, AbstractActorCriticLoss]] = None
        self._named_loss_weights: Optional[Dict[str, float]] = None
        self._named_loss_update_repeats: Optional[Dict[str, float]] = None

        self.offpolicy_memory = Memory()
        self.offpolicy_epochs: Optional[int] = None
        self.offpolicy_named_losses: Optional[Dict[str, AbstractOffPolicyLoss]] = None
        self._offpolicy_named_loss_weights: Optional[Dict[str, float]] = None
        self.offpolicy_steps_taken_in_stage: int = 0
Esempio n. 11
0
    def __init__(self,
                 nactions: int,
                 uuid: str = "expert_policy",
                 expert_args: Optional[Dict[str, Any]] = None,
                 **kwargs: Any) -> None:
        self.nactions = nactions
        self.expert_args: Dict[str, Any] = expert_args or {}

        super().__init__(**prepare_locals_for_super(locals()))
Esempio n. 12
0
    def __init__(
        self,
        named_losses: Dict[str, Union[Loss, Builder[Loss]]],
        pipeline_stages: List[PipelineStage],
        optimizer_builder: Builder[optim.Optimizer],  # type: ignore
        num_mini_batch: int,
        update_repeats: Optional[int],
        max_grad_norm: float,
        num_steps: int,
        gamma: float,
        use_gae: bool,
        gae_lambda: float,
        advance_scene_rollout_period: Optional[int],
        save_interval: Optional[int],
        metric_accumulate_interval: int,
        should_log: bool = True,
        lr_scheduler_builder: Optional[Builder[optim.lr_scheduler._LRScheduler]] = None,  # type: ignore
    ):
        """Initializer.

        See class docstring for parameter definitions.
        """
        all_vars = prepare_locals_for_super(locals())

        # Populate TrainingSettings members
        super().__init__(**all_vars)

        self.optimizer_builder = optimizer_builder
        self.lr_scheduler_builder = lr_scheduler_builder

        self.named_losses = named_losses
        self.should_log = should_log

        self.pipeline_stages = pipeline_stages
        if len(self.pipeline_stages) > len(set(id(ps) for ps in pipeline_stages)):
            raise RuntimeError(
                "Duplicate `PipelineStage` object instances found in the pipeline stages input"
                " to `TrainingPipeline`. `PipelineStage` objects are not immutable, if you'd"
                " like to have multiple pipeline stages of the same type, please instantiate"
                " multiple separate instances."
            )

        self._current_stage: Optional[PipelineStage] = None
        for sit, stage in enumerate(self.pipeline_stages):
            # Forward all global `TrainingSettings` to all `PipelineStage`s unless overridden:
            for var in _TRAINING_SETTINGS_NAMES:
                if getattr(stage, var) is None:
                    setattr(stage, var, getattr(self, var))

            assert (
                stage.num_steps <= self.num_steps
            ), f"Stage {sit} has `num_steps` {stage.num_steps} > {self.num_steps} in pipeline."

        self.rollout_count = 0
        self.off_policy_epochs = None

        self._refresh_current_stage(force_stage_search_from_start=True)
Esempio n. 13
0
 def __init__(self,
              uuid="agent_pose"):
     observation_space = gym.spaces.Box(
         low=-360,
         high=360,
         shape=(6,),
         dtype=np.float32,
     )
     super().__init__(**prepare_locals_for_super(locals()))
Esempio n. 14
0
    def __init__(self,
                 uuid: str = "human_poses",
                 use_gesture: bool = True,
                 **kwargs: Any):
        self.use_gesture = use_gesture

        observation_space = self._get_observation_space()

        super().__init__(**prepare_locals_for_super(locals()))
        return
Esempio n. 15
0
 def __init__(
     self,
     action_space: Optional[Union[gym.Space, int]] = None,
     uuid: str = "expert_policy",
     expert_args: Optional[Dict[str, Any]] = None,
     nactions: Optional[int] = None,
     use_dict_as_groups: bool = True,
     **kwargs: Any,
 ) -> None:
     super().__init__(**prepare_locals_for_super(locals()))
Esempio n. 16
0
    def __init__(
        self,
        action_space: Optional[Union[gym.Space, int]] = None,
        uuid: str = "expert_sensor_type_uuid",
        expert_args: Optional[Dict[str, Any]] = None,
        nactions: Optional[int] = None,
        use_dict_as_groups: bool = True,
        **kwargs: Any,
    ) -> None:
        """Initialize an `ExpertSensor`.

        # Parameters
        action_space : The action space of the agent. This is necessary in order for this sensor
            to know what its output observation space is.
        uuid : A string specifying the unique ID of this sensor.
        expert_args : This sensor obtains an expert action from the task by calling the `query_expert`
            method of the task. `expert_args` are any keyword arguments that should be passed to the
            `query_expert` method when called.
        nactions : [DEPRECATED] The number of actions available to the agent, corresponds to an `action_space`
            of `gym.spaces.Discrete(nactions)`.
        use_dict_as_groups : Whether to use the top-level action_space of type `gym.spaces.Dict` as action groups.
        """
        if isinstance(action_space, int):
            action_space = gym.spaces.Discrete(action_space)
        elif action_space is None:
            assert (
                nactions is not None
            ), "One of `action_space` or `nactions` must be not `None`."
            get_logger().warning(
                "The `nactions` parameter to `AbstractExpertSensor` is deprecated and will be removed, please use"
                " the `action_space` parameter instead."
            )
            action_space = gym.spaces.Discrete(nactions)

        self.action_space = action_space

        self.use_groups = (
            isinstance(action_space, gym.spaces.Dict) and use_dict_as_groups
        )

        self.group_spaces = (
            self.action_space
            if self.use_groups
            else OrderedDict([(self._NO_GROUPS_LABEL, self.action_space,)])
        )

        self.expert_args: Dict[str, Any] = expert_args or {}

        assert (
            "expert_sensor_group_name" not in self.expert_args
        ), "`expert_sensor_group_name` is reserved for `AbstractExpertSensor`"

        observation_space = self._get_observation_space()

        super().__init__(**prepare_locals_for_super(locals()))
Esempio n. 17
0
 def __init__(self,
              height: Optional[int] = None,
              width: Optional[int] = None,
              uuid="frame"):
     observation_space = gym.spaces.Box(
         low=0,
         high=1,
         shape=(height, width, 3),
         dtype=np.float64,
     )
     super().__init__(**prepare_locals_for_super(locals()))
Esempio n. 18
0
 def __init__(self,
              objectTypes,
              uuid="object_action_mask"):
     self.objectTypes = objectTypes
     observation_space = gym.spaces.Box(
         low=0,
         high=1,
         shape=(len(objectTypes), 1),
         dtype=np.float32,
     )
     super().__init__(**prepare_locals_for_super(locals()))
    def __init__(
        self,
        input_uuids: List[str],
        output_uuid: str,
        input_height: int,
        input_width: int,
        max_dets: int,
        detector_spatial_res: int,
        detector_thres: float,
        device: Optional[torch.device] = None,
        device_ids: Optional[List[torch.device]] = None,
        **kwargs: Any,
    ):
        self.input_height = input_height
        self.input_width = input_width
        self.max_dets = max_dets
        self.detector_spatial_res = detector_spatial_res
        self.detector_thres = detector_thres
        self.device = torch.device("cpu") if device is None else device
        self.device_ids = device_ids or cast(
            List[torch.device], list(range(torch.cuda.device_count())))

        self.frcnn: BatchedFasterRCNN = BatchedFasterRCNN(
            thres=self.detector_thres,
            maxdets=self.max_dets,
            res=self.detector_spatial_res,
        )

        spaces: OrderedDict[str, gym.Space] = OrderedDict()
        shape = (self.max_dets, self.detector_spatial_res,
                 self.detector_spatial_res)
        spaces["frcnn_classes"] = gym.spaces.Box(
            low=0,  # 0 is bg
            high=len(self.COCO_INSTANCE_CATEGORY_NAMES) - 1,
            shape=shape,
            dtype=np.int64,
        )
        shape = (
            self.max_dets * 5,
            self.detector_spatial_res,
            self.detector_spatial_res,
        )
        spaces["frcnn_boxes"] = gym.spaces.Box(low=-np.inf,
                                               high=np.inf,
                                               shape=shape)

        assert (
            len(input_uuids) == 1
        ), "fasterrcnn preprocessor can only consume one observation type"

        observation_space = SpaceDict(spaces=spaces)

        super().__init__(**prepare_locals_for_super(locals()))
Esempio n. 20
0
    def __init__(self,
                 uuid: str = "gestures",
                 add_intervention: bool = False,
                 use_gesture: bool = True,
                 **kwargs: Any):
        self.add_intervention = add_intervention
        self.use_gesture = use_gesture

        observation_space = self._get_observation_space()

        super().__init__(**prepare_locals_for_super(locals()))
        return
Esempio n. 21
0
 def __init__(self,
              objectTypes,
              uuid="class_segmentation"):
     self.objectTypes = objectTypes
     self.sorted_objectTypes = sorted(list(objectTypes))
     observation_space = gym.spaces.Box(
         low=-10,
         high=10,
         shape=(len(objectTypes), 8, 3),
         dtype=np.float32,
     )
     super().__init__(**prepare_locals_for_super(locals()))
    def __init__(
        self,
        x_display: Optional[str] = None,
        docker_enabled: bool = False,
        local_thor_build: Optional[str] = None,
        visibility_distance: float = VISIBILITY_DISTANCE,
        fov: float = FOV,
        player_screen_width: int = 224,
        player_screen_height: int = 224,
        quality: str = "Very Low",
        restrict_to_initially_reachable_points: bool = False,
        make_agents_visible: bool = True,
        object_open_speed: float = 1.0,
        simplify_physics: bool = False,
        verbose: bool = False,
        env_args=None,
    ) -> None:
        """Initializer.

        # Parameters

        x_display : The x display into which to launch ai2thor (possibly necessarily if you are running on a server
            without an attached display).
        docker_enabled : Whether or not to run thor in a docker container (useful on a server without an attached
            display so that you don't have to start an x display).
        local_thor_build : The path to a local build of ai2thor. This is probably not necessary for your use case
            and can be safely ignored.
        visibility_distance : The distance (in meters) at which objects, in the viewport of the agent,
            are considered visible by ai2thor and will have their "visible" flag be set to `True` in the metadata.
        fov : The agent's camera's field of view.
        width : The width resolution (in pixels) of the images returned by ai2thor.
        height : The height resolution (in pixels) of the images returned by ai2thor.
        quality : The quality at which to render. Possible quality settings can be found in
            `ai2thor._quality_settings.QUALITY_SETTINGS`.
        restrict_to_initially_reachable_points : Whether or not to restrict the agent to locations in ai2thor
            that were found to be (initially) reachable by the agent (i.e. reachable by the agent after resetting
            the scene). This can be useful if you want to ensure there are only a fixed set of locations where the
            agent can go.
        make_agents_visible : Whether or not the agent should be visible. Most noticable when there are multiple agents
            or when quality settings are high so that the agent casts a shadow.
        object_open_speed : How quickly objects should be opened. High speeds mean faster simulation but also mean
            that opening objects have a lot of kinetic energy and can, possibly, knock other objects away.
        simplify_physics : Whether or not to simplify physics when applicable. Currently this only simplies object
            interactions when opening drawers (when simplified, objects within a drawer do not slide around on
            their own when the drawer is opened or closed, instead they are effectively glued down).
        """
        self._verbose = verbose
        self.env_args = env_args
        del verbose
        del env_args
        super(ManipulaTHOREnvironment,
              self).__init__(**prepare_locals_for_super(locals()))
Esempio n. 23
0
 def __init__(self,
              objectTypes,
              height: Optional[int] = None,
              width: Optional[int] = None,
              uuid="seg"):
     self.objectTypes = sorted(list(objectTypes))
     observation_space = gym.spaces.Box(
         low=0,
         high=1,
         shape=(height, width, len(objectTypes)),
         dtype=np.float64,
     )
     super().__init__(**prepare_locals_for_super(locals()))
Esempio n. 24
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]:
     kwargs = super(
         ObjectNavRoboThorBaseConfig,
         self).train_task_sampler_args(**prepare_locals_for_super(locals()))
     if self.randomize_train_materials:
         kwargs["env_args"][
             "commit_id"] = self.THOR_COMMIT_ID_FOR_RAND_MATERIALS
     return kwargs
Esempio n. 25
0
    def __init__(
        self,
        input_uuids: List[str],
        output_uuid: str,
        input_height: int,
        input_width: int,
        output_height: int,
        output_width: int,
        output_dims: int,
        pool: bool,
        torchvision_resnet_model: Callable[..., models.ResNet] = models.resnet18,
        device: Optional[torch.device] = None,
        device_ids: Optional[List[torch.device]] = None,
        **kwargs: Any
    ):
        def f(x, k):
            assert k in x, "{} must be set in ResNetPreprocessor".format(k)
            return x[k]

        def optf(x, k, default):
            return x[k] if k in x else default

        self.input_height = input_height
        self.input_width = input_width
        self.output_height = output_height
        self.output_width = output_width
        self.output_dims = output_dims
        self.pool = pool
        self.make_model = torchvision_resnet_model

        self.device = torch.device("cpu") if device is None else device
        self.device_ids = device_ids or cast(
            List[torch.device], list(range(torch.cuda.device_count()))
        )

        self._resnet: Optional[ResNetEmbedder] = None

        low = -np.inf
        high = np.inf
        shape = (self.output_dims, self.output_height, self.output_width)

        assert (
            len(input_uuids) == 1
        ), "resnet preprocessor can only consume one observation type"

        observation_space = gym.spaces.Box(low=low, high=high, shape=shape)

        super().__init__(**prepare_locals_for_super(locals()))
Esempio n. 26
0
    def __init__(self,
                 use_resnet_normalization: bool = False,
                 mean: Optional[Union[np.ndarray,
                                      Sequence[float]]] = (0.485, 0.456,
                                                           0.406),
                 stdev: Optional[Union[np.ndarray,
                                       Sequence[float]]] = (0.229, 0.224,
                                                            0.225),
                 height: Optional[int] = None,
                 width: Optional[int] = None,
                 uuid: str = "rgb",
                 output_shape: Optional[Tuple[int, ...]] = None,
                 output_channels: int = 3,
                 unnormalized_infimum: float = 0.0,
                 unnormalized_supremum: float = 1.0,
                 scale_first: bool = True,
                 **kwargs: Any):
        """Initializer.

        # Parameters

        use_resnet_normalization : Whether to apply image normalization with the given `mean` and `stdev`.
        mean : The images will be normalized with the given mean if `use_resnet_normalization` is True (default
               `[0.485, 0.456, 0.406]`, i.e. the standard resnet normalization mean).
        stdev : The images will be normalized with the given standard deviation if `use_resnet_normalization` is True
                (default `[0.229, 0.224, 0.225]`, i.e. the standard resnet normalization standard deviation).
        height: If it's a non-negative integer and `width` is also non-negative integer, the image returned from the
                environment will be rescaled to have `height` rows and `width` columns using bilinear sampling.
        width: If it's a non-negative integer and `height` is also non-negative integer, the image returned from the
                environment will be rescaled to have `height` rows and `width` columns using bilinear sampling.
        uuid: The universally unique identifier for the sensor.
        output_shape: Optional observation space shape (alternative to `output_channels`).
        output_channels: Optional observation space number of channels (alternative to `output_shape`).
        unnormalized_infimum: Lower limit(s) for the observation space range.
        unnormalized_supremum: Upper limit(s) for the observation space range.
        scale_first: Whether to scale image before normalization (if needed).
        kwargs : Extra kwargs. Currently unused.
        """

        if not use_resnet_normalization:
            mean, stdev = None, None

        if isinstance(mean, tuple):
            mean = np.array(mean, dtype=np.float32).reshape(1, 1, len(mean))
        if isinstance(stdev, tuple):
            stdev = np.array(stdev, dtype=np.float32).reshape(1, 1, len(stdev))

        super().__init__(**prepare_locals_for_super(locals()))
Esempio n. 27
0
    def __init__(
        self,
        action_space: gym.spaces.Discrete,
        observation_space: SpaceDict,
        num_objects: int,
        num_colors: int,
        num_states: int,
        object_embedding_dim: int = 8,
        hidden_size=512,
        num_layers=1,
        rnn_type="GRU",
        head_type: Callable[
            ..., ActorCriticModel[CategoricalDistr]
        ] = LinearActorCritic,
        **kwargs,
    ):
        super().__init__(**prepare_locals_for_super(locals()))

        self._hidden_size = hidden_size
        agent_view_x, agent_view_y, view_channels = observation_space[
            "minigrid_ego_image"
        ].shape
        self.actor_critic = RNNActorCritic(
            input_uuid=self.ac_key,
            action_space=action_space,
            observation_space=SpaceDict(
                {
                    self.ac_key: gym.spaces.Box(
                        low=np.float32(-1.0),
                        high=np.float32(1.0),
                        shape=(
                            self.object_embedding_dim
                            * agent_view_x
                            * agent_view_y
                            * view_channels,
                        ),
                    )
                }
            ),
            hidden_size=hidden_size,
            num_layers=num_layers,
            rnn_type=rnn_type,
            head_type=head_type,
        )
        self.memory_key = "rnn"

        self.train()
Esempio n. 28
0
    def __init__(self,
                 use_normalization: bool = False,
                 mean: Optional[Union[np.ndarray, float]] = 0.5,
                 stdev: Optional[Union[np.ndarray, float]] = 0.25,
                 height: Optional[int] = None,
                 width: Optional[int] = None,
                 uuid: str = "depth",
                 output_shape: Optional[Tuple[int, ...]] = None,
                 output_channels: int = 1,
                 unnormalized_infimum: float = 0.0,
                 unnormalized_supremum: float = 5.0,
                 scale_first: bool = True,
                 **kwargs: Any):
        """Initializer.

        # Parameters

        config : If `config["use_normalization"]` is `True` then the depth images will be normalized
            with mean 0.5 and standard deviation 0.25. If both `config["height"]` and `config["width"]` are
            non-negative integers then the depth image returned from the environment will be rescaled to have shape
            (config["height"], config["width"]) using bilinear sampling.
        use_normalization : Whether to apply image normalization with the given `mean` and `stdev`.
        mean : The images will be normalized with the given mean if `use_normalization` is True (default 0.5).
        stdev : The images will be normalized with the given standard deviation if `use_normalization` is True
                (default 0.25).
        height: If it's a non-negative integer and `width` is also non-negative integer, the image returned from the
                environment will be rescaled to have `height` rows and `width` columns using bilinear sampling.
        width: If it's a non-negative integer and `height` is also non-negative integer, the image returned from the
                environment will be rescaled to have `height` rows and `width` columns using bilinear sampling.
        uuid: The universally unique identifier for the sensor.
        output_shape: Optional observation space shape (alternative to `output_channels`).
        output_channels: Optional observation space number of channels (alternative to `output_shape`).
        unnormalized_infimum: Lower limit(s) for the observation space range.
        unnormalized_supremum: Upper limit(s) for the observation space range.
        scale_first: Whether to scale image before normalization (if needed).
        kwargs : Extra kwargs. Currently unused.
        """

        if not use_normalization:
            mean, stdev = None, None

        if isinstance(mean, float):
            mean = np.array(mean, dtype=np.float32).reshape(1, 1)
        if isinstance(stdev, float):
            stdev = np.array(stdev, dtype=np.float32).reshape(1, 1)

        super().__init__(**prepare_locals_for_super(locals()))
 def __init__(
         self,
         use_resnet_normalization: bool = False,
         mean: Optional[np.ndarray] = np.array([[[0.485, 0.456, 0.406]]],
                                               dtype=np.float32),
         stdev: Optional[np.ndarray] = np.array([[[0.229, 0.224, 0.225]]],
                                                dtype=np.float32),
         height: Optional[int] = None,
         width: Optional[int] = None,
         uuid: str = "rgb",
         output_shape: Optional[Tuple[int, ...]] = None,
         output_channels: int = 3,
         unnormalized_infimum: float = 0.0,
         unnormalized_supremum: float = 1.0,
         scale_first: bool = True,
         **kwargs: Any):
     super().__init__(**prepare_locals_for_super(locals()))
Esempio n. 30
0
    def __init__(
        self,
        fov: float,
        vision_range_in_cm: int,
        map_size_in_cm: int,
        resolution_in_cm: int,
        map_range_sensor: Sensor,
        height_bins: Sequence[float] = (0.02, 2),
        ego_only: bool = True,
        uuid: str = "binned_pc_map",
        **kwargs: Any,
    ):
        self.fov = fov
        self.vision_range_in_cm = vision_range_in_cm
        self.map_size_in_cm = map_size_in_cm
        self.resolution_in_cm = resolution_in_cm
        self.height_bins = height_bins
        self.ego_only = ego_only

        self.binned_pc_map_builder = BinnedPointCloudMapBuilder(
            fov=fov,
            vision_range_in_cm=vision_range_in_cm,
            map_size_in_cm=map_size_in_cm,
            resolution_in_cm=resolution_in_cm,
            height_bins=height_bins,
        )

        map_space = gym.spaces.Box(
            low=0,
            high=np.inf,
            shape=self.binned_pc_map_builder.binned_point_cloud_map.shape,
            dtype=np.float32,
        )

        space_dict = {
            "egocentric_update": map_space,
        }
        if not ego_only:
            space_dict["allocentric_update"] = copy.deepcopy(map_space)
            space_dict["map"] = copy.deepcopy(map_space)

        observation_space = gym.spaces.Dict(space_dict)
        super().__init__(**prepare_locals_for_super(locals()))

        self.map_range_sensor = map_range_sensor