我需要用一个机器人手臂和一个目标点的基本模型来创建一个2D环境。我希望手臂通过一系列离散的动作(例如,向右、向左、向上和向下)到达目标,并且我需要观察空间是屏幕的RGB图像,然后将其用作DQN的输入。
我的问题是,我不明白如何使用图像观察来移动机器人,并获得其手臂和目标的位置(例如,根据它们的距离创建奖励函数)。
看起来我唯一可以从健身房环境中获得灵感的是Atari的环境,但我找不到单个游戏的具体代码,可能是因为它们嵌入在ROM中。
那么,如果我想在健身房中学习Atari环境的例子并使用atari_env.py,这是否意味着我也需要创建一个游戏及其ROM,然后将其集成到Stella中?还是有别的办法?一般来说,有没有其他类型的环境使用图像作为观察,我可以从中获得灵感?
非常感谢
发布于 2021-10-17 07:58:50
您只需使用适当的方法实现一个类,即可创建一个自定义的Gym环境:
import gym
from gym.spaces import Discrete, Box
class RobotEnv(gym.Env):
metadata = {'render.modes': ['human', 'rgb_array']}
def __init__(self, arg1, arg2, ...):
super().__init__()
# The action and observation spaces need to be gym.spaces objects:
self.action_space = Discrete(4) # up, left, right, down
# Here's an observation space for 200 wide x 100 high RGB image inputs:
self.observation_space = Box(
low=0, high=255, shape=(100, 200, 3), dtype=np.uint8)
def step(self, action):
# Execute one time step in the environment
...
def reset(self):
# Reset the state of the environment
...
def render(self, mode='human', close=False):
if mode == 'human':
# render to screen
...
elif mode == 'rgb_array':
# render to a NumPy 100x200x3 array
...
return array
else:
# raise an error, unsupported mode不需要实现自己的Atari ROM或任何类似的东西。它可以是纯Python (+ NumPy数组)。要生成表示图像的NumPy数组,有许多选择。例如,您可以使用Matplotlib、PIL或其他库。或者,如果图像非常简单,您甚至可以手动创建NumPy数组。例如,下面的代码创建一个随机的200x100 RGB图像:
import numpy as np
random_image = np.random.rand(100, 200, 3)https://stackoverflow.com/questions/63633802
复制相似问题