Table of Contents

Class GrayscaleObservation<TObs, TAct>

Namespace
Gym.Wrappers
Assembly
Gym.dll

Converts an RGB image observation to grayscale (0.2125 R + 0.7154 G + 0.0721 B, truncated to uint8), as Gymnasium's GrayscaleObservation does; keep_dim keeps a channel axis of length 1.

public class GrayscaleObservation<TObs, TAct> : TransformObservation<NDArray, TObs, TAct>, IDynamicAttributes, IWrapper, IEnv, IDisposable, IRecordConstructorArgs

Type Parameters

TObs

The env's observation type: arrays (NDArray, or object holding them).

TAct

The action type, passed through.

Inheritance
Env<NDArray, TAct>
Wrapper<NDArray, TAct, TObs, TAct>
GrayscaleObservation<TObs, TAct>
Implements
Inherited Members
Extension Methods

Remarks

The weighted sum is NumPy's: the uint8 pixels times float64 weights, summed over the channel axis in float64, then cast to uint8, which truncates. Every observation is a new array.

Reference: gymnasium/wrappers/transform_observation.py.

Constructors

GrayscaleObservation(Env<TObs, TAct>, GrayscaleObservationOptions)

Builds the instance from its options record: the properties set, the constructor's defaults for the rest.

public GrayscaleObservation(Env<TObs, TAct> env, GrayscaleObservationOptions options)

Parameters

env Env<TObs, TAct>

The env to wrap.

options GrayscaleObservationOptions

The options.

Exceptions

ArgumentNullException

Thrown when options is null.

GrayscaleObservation(Env<TObs, TAct>, bool)

Wraps env.

public GrayscaleObservation(Env<TObs, TAct> env, bool keepDim = false)

Parameters

env Env<TObs, TAct>

The env; its observation space must be a uint8 Box of shape (h, w, 3) with bounds 0 and 255.

keepDim bool

Whether observations keep a channel axis, (h, w, 1), instead of (h, w).

Exceptions

TypeError

Thrown when the space is no Box (Gymnasium's message), or env is null.

ValueError

Thrown when the space is not a 3-channel image, or not uint8 within 0 and 255, with Gymnasium's messages.

Properties

KeepDim

Whether the channel axis is kept (keep_dim).

public bool KeepDim { get; }

Property Value

bool