allenact.base_abstractions.sensor
#
Sensor
#
class Sensor(Generic[EnvType, SubTaskType])
Represents a sensor that provides data from the environment to agent. The user of this class needs to implement the get_observation method and the user is also required to set the below attributes:
Attributes
uuid
: universally unique id.observation_space
:gym.Space
object corresponding to observation of sensor.
Sensor.get_observation
#
| get_observation(env: EnvType, task: Optional[SubTaskType], *args: Any, **kwargs: Any) -> Any
Returns observations from the environment (or task).
Parameters
- env : The environment the sensor is used upon.
- task : (Optionally) a Task from which the sensor should get data.
Returns
Current observation for Sensor.
SensorSuite
#
class SensorSuite(Generic[EnvType])
Represents a set of sensors, with each sensor being identified through a unique id.
Attributes
sensors
: list containing sensors for the environment, uuid of each sensor must be unique.
SensorSuite.__init__
#
| __init__(sensors: Sequence[Sensor]) -> None
Initializer.
Parameters
- param sensors: the sensors that will be included in the suite.
SensorSuite.get
#
| get(uuid: str) -> Sensor
Return sensor with the given uuid
.
Parameters
- uuid : The unique id of the sensor
Returns
The sensor with unique id uuid
.
SensorSuite.get_observations
#
| get_observations(env: EnvType, task: Optional[SubTaskType], **kwargs: Any) -> Dict[str, Any]
Get all observations corresponding to the sensors in the suite.
Parameters
- env : The environment from which to get the observation.
- task : (Optionally) the task from which to get the observation.
Returns
Data from all sensors packaged inside a Dict.
ExpertActionSensor
#
class ExpertActionSensor(Sensor[EnvType, SubTaskType])
A sensor that obtains the expert action for a given task (if available).
ExpertActionSensor.__init__
#
| __init__(action_space: Optional[Union[gym.Space, int]] = None, uuid: str = "expert_action", expert_args: Optional[Dict[str, Any]] = None, nactions: Optional[int] = None, **kwargs: Any) -> None
Initialize an ExpertActionSensor
.
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 talling the
query_expert
method of the task.expert_args
are any keyword arguments that should be passed to thequery_expert
method when called. - nactions : [DEPRECATED] The number of actions available to the agent, corresponds to an
action_space
ofgym.spaces.Discrete(nactions)
.
VisionSensor
#
class VisionSensor(Sensor[EnvType, SubTaskType])
VisionSensor.__init__
#
| __init__(mean: Optional[np.ndarray] = None, stdev: Optional[np.ndarray] = None, height: Optional[int] = None, width: Optional[int] = None, uuid: str = "vision", output_shape: Optional[Tuple[int, ...]] = None, output_channels: Optional[int] = None, unnormalized_infimum: float = -np.inf, unnormalized_supremum: float = np.inf, scale_first: bool = True, **kwargs: Any)
Initializer.
Parameters
- config : The images will be normalized
with means
config["mean"]
and standard deviationsconfig["stdev"]
. If bothconfig["height"]
andconfig["width"]
are non-negative integers then the image returned from the environment will be rescaled to haveconfig["height"]
rows andconfig["width"]
columns using bilinear sampling. The universally unique identifier will be set asconfig["uuid"]
. - args : Extra args. Currently unused.
- kwargs : Extra kwargs. Currently unused.
VisionSensor.height
#
| @property
| height() -> Optional[int]
Height that input image will be rescale to have.
Returns
The height as a non-negative integer or None
if no rescaling is done.
VisionSensor.width
#
| @property
| width() -> Optional[int]
Width that input image will be rescale to have.
Returns
The width as a non-negative integer or None
if no rescaling is done.
RGBSensor
#
class RGBSensor(VisionSensor[EnvType, SubTaskType], ABC)
RGBSensor.__init__
#
| __init__(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)
Initializer.
Parameters
- config : If
config["use_resnet_normalization"]
isTrue
then the RGB images will be normalized with means[0.485, 0.456, 0.406]
and standard deviations[0.229, 0.224, 0.225]
(i.e. using the standard resnet normalization). If bothconfig["height"]
andconfig["width"]
are non-negative integers then the RGB image returned from the environment will be rescaled to have shape (config["height"], config["width"], 3) using bilinear sampling. - args : Extra args. Currently unused.
- kwargs : Extra kwargs. Currently unused.
DepthSensor
#
class DepthSensor(VisionSensor[EnvType, SubTaskType], ABC)
DepthSensor.__init__
#
| __init__(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"]
isTrue
then the depth images will be normalized with mean 0.5 and standard deviation 0.25. If bothconfig["height"]
andconfig["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.