Table of Contents

Class ResizeObservation<TObs, TAct>

Namespace
Gym.Wrappers
Assembly
Gym.dll

Resizes every image observation to (height, width) by OpenCV's area interpolation, as Gymnasium's ResizeObservation does with cv2.resize(obs, (width, height), interpolation=cv2.INTER_AREA); the channels, if any, are kept. Use it to shrink frames for a learner.

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

Type Parameters

TObs

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

TAct

The action type, passed through.

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

Remarks

The env's space must be a uint8 Box from 0 to 255 of two or three dimensions. The resize is Resize(NDArray, (int Width, int Height), int), Gym.NET's translation of OpenCV's kernels, byte for byte equal to the pinned cv2's (decision DR-23), so no native OpenCV is needed; growing an image takes OpenCV's bilinear emulation of area interpolation, as cv2 does. Each observation is a new array.

Gymnasium refuses a shape that is not a tuple of integers with TypeError; here it is a long[], so only its length and signs are checked, with Gymnasium's messages.

Reference: gymnasium/wrappers/transform_observation.py.

Constructors

ResizeObservation(Env<TObs, TAct>, ResizeObservationOptions)

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

public ResizeObservation(Env<TObs, TAct> env, ResizeObservationOptions options)

Parameters

env Env<TObs, TAct>

The env to wrap.

options ResizeObservationOptions

The options.

Exceptions

ArgumentNullException

Thrown when options is null.

TypeError

Thrown when a required argument is unset, with Python's missing-argument message.

ResizeObservation(Env<TObs, TAct>, long[])

Wraps env.

public ResizeObservation(Env<TObs, TAct> env, long[] shape)

Parameters

env Env<TObs, TAct>

The env; its observation space must be a uint8 Box from 0 to 255 of shape (H, W) or (H, W, C).

shape long[]

The new (height, width), both positive.

Exceptions

TypeError

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

ArgumentNullException

Thrown when shape is null.

ValueError

Thrown, with Gymnasium's messages, for a space that is not 2-D or 3-D, not bounded by 0 and 255, or not uint8, and for a shape whose length is not 2 or whose elements are not positive.

Properties

Cv2Shape

The size OpenCV is given, (width, height) (cv2_shape).

public (int Width, int Height) Cv2Shape { get; }

Property Value

(int Width, int Height)

Shape

The new (height, width) (shape).

public long[] Shape { get; }

Property Value

long[]