Skip to content

core.base_abstractions.sensor#

[view_source]

Sensor#

class Sensor(Generic[EnvType, SubTaskType])

[view_source]

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

[view_source]

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])

[view_source]

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

[view_source]

Initializer.

Parameters

  • param sensors: the sensors that will be included in the suite.

SensorSuite.get#

 | get(uuid: str) -> Sensor

[view_source]

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]

[view_source]

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.

VisionSensor#

class VisionSensor(Sensor[EnvType, SubTaskType])

[view_source]

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)

[view_source]

Initializer.

Parameters

  • config : The images will be normalized with means config["mean"] and standard deviations config["stdev"]. If both config["height"] and config["width"] are non-negative integers then the image returned from the environment will be rescaled to have config["height"] rows and config["width"] columns using bilinear sampling. The universally unique identifier will be set as config["uuid"].
  • args : Extra args. Currently unused.
  • kwargs : Extra kwargs. Currently unused.

VisionSensor.height#

 | @property
 | height() -> Optional[int]

[view_source]

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]

[view_source]

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)

[view_source]

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)

[view_source]

Initializer.

Parameters

  • config : If config["use_resnet_normalization"] is True 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 both config["height"] and config["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)

[view_source]

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)

[view_source]

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.

ResNetSensor#

class ResNetSensor(VisionSensor[EnvType, SubTaskType],  ABC)

[view_source]

ResNetSensor.to#

 | to(device: torch.device) -> "ResNetSensor"

[view_source]

Moves sensor to specified device.

Parameters

  • device : The device for the sensor.

RGBResNetSensor#

class RGBResNetSensor(ResNetSensor[EnvType, SubTaskType],  ABC)

[view_source]

RGBResNetSensor.__init__#

 | __init__(use_resnet_normalization: bool = True, 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 = "rgbresnet", output_shape: Optional[Tuple[int, ...]] = (2048,), output_channels: Optional[int] = None, unnormalized_infimum: float = -np.inf, unnormalized_supremum: float = np.inf, scale_first: bool = True, **kwargs: Any)

[view_source]

Initializer.

Parameters

  • config : If config["use_resnet_normalization"] is True 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 both config["height"] and config["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 before being fed to a ResNet-50 and extracting the flattened 2048-dimensional output embedding.
  • args : Extra args. Currently unused.
  • kwargs : Extra kwargs. Currently unused.

DepthResNetSensor#

class DepthResNetSensor(ResNetSensor[EnvType, SubTaskType],  ABC)

[view_source]

DepthResNetSensor.__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 = "depthresnet", output_shape: Optional[Tuple[int, ...]] = (2048,), output_channels: Optional[int] = None, unnormalized_infimum: float = -np.inf, unnormalized_supremum: float = np.inf, scale_first: bool = True, **kwargs: Any)

[view_source]

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"], 1) using bilinear sampling before being replicated to fill in three channels to feed a ResNet-50 and finally extract the flattened 2048-dimensional output embedding.
  • args : Extra args. Currently unused.
  • kwargs : Extra kwargs. Currently unused.