src.plangym.utils#
Generic utilities for working with environments.
Attributes#
Classes#
Convert the image observation from RGB to gray scale. |
Functions#
|
Start a virtual display. |
Remove the maximum time limit of an environment spec. |
|
|
Remove the maximum time limit of the provided environment. |
|
Resize an RGB frame to a specified shape and mode. |
|
Resize an RGB frame to a specified shape and mode. |
|
Resize an RGB frame to a specified shape and mode. |
Module Contents#
- src.plangym.utils.USE_PIL = True#
- src.plangym.utils.get_display(visible=False, size=(400, 400), **kwargs)[source]#
Start a virtual display.
- src.plangym.utils.remove_time_limit_from_spec(spec)[source]#
Remove the maximum time limit of an environment spec.
- src.plangym.utils.remove_time_limit(gym_env)[source]#
Remove the maximum time limit of the provided environment.
- Parameters:
gym_env (gymnasium.Env)
- Return type:
gymnasium.Env
- src.plangym.utils.process_frame_pil(frame, width=None, height=None, mode='RGB')[source]#
Resize an RGB frame to a specified shape and mode.
Use PIL to resize an RGB frame to a specified height and width or changing it to a different mode.
- Parameters:
frame (numpy.ndarray) – Target numpy array representing the image that will be resized.
width (int | None) – Width of the resized image.
height (int | None) – Height of the resized image.
mode (str) – Passed to Image.convert.
- Returns:
The resized frame that matches the provided width and height.
- Return type:
numpy.ndarray
- src.plangym.utils.process_frame_opencv(frame, width=None, height=None, mode='RGB')[source]#
Resize an RGB frame to a specified shape and mode.
Use OpenCV to resize an RGB frame to a specified height and width or changing it to a different mode.
- Parameters:
frame (numpy.ndarray) – Target numpy array representing the image that will be resized.
width (int | None) – Width of the resized image.
height (int | None) – Height of the resized image.
mode (str) – Passed to cv2.cvtColor.
- Returns:
The resized frame that matches the provided width and height.
- Return type:
numpy.ndarray
- src.plangym.utils.process_frame(frame, width=None, height=None, mode='RGB')[source]#
Resize an RGB frame to a specified shape and mode.
Use either PIL or OpenCV to resize an RGB frame to a specified height and width or changing it to a different mode.
- Parameters:
frame (numpy.ndarray) – Target numpy array representing the image that will be resized.
width (int | None) – Width of the resized image.
height (int | None) – Height of the resized image.
mode (str) – Passed to either Image.convert or cv2.cvtColor.
- Returns:
The resized frame that matches the provided width and height.
- Return type:
numpy.ndarray
- class src.plangym.utils.GrayScaleObservation(env, keep_dim=False)[source]#
Bases:
gymnasium.ObservationWrapper,gymnasium.utils.RecordConstructorArgsConvert the image observation from RGB to gray scale.
Example
>>> import gymnasium as gym >>> from gymnasium.wrappers import GrayScaleObservation >>> env = gym.make("CarRacing-v2") >>> env.observation_space Box(0, 255, (96, 96, 3), uint8) >>> env = GrayScaleObservation(gym.make("CarRacing-v2")) >>> env.observation_space Box(0, 255, (96, 96), uint8) >>> env = GrayScaleObservation(gym.make("CarRacing-v2"), keep_dim=True) >>> env.observation_space Box(0, 255, (96, 96, 1), uint8)
- Parameters:
env (gymnasium.Env)
keep_dim (bool)
- keep_dim#
- obs_shape#