我正在尝试创建一个可以移动鼠标(显然是在VM中)的健身环境...我对课程了解不多,但是应该为self或其他内容提供一个论点... ?此外,任何改进将不胜感激...
这段代码基本上将在VM上运行,所以...我试图删除代码行,但是有几行不运行...(我很烂地解释事情)
代码如下:
class MouseEnv(Env):
def __init__(self):
self.ACC = 0
self.reward = 0
self.done = False
self.reset()
def step(self, action):
try:
self.action = action
done = False
if self.action == 1:
pyautogui.click()
self.reward += 0.2
else:
if self.ACC == 1:
self.action = min((self.action/100), 1) * 1920
self.prev_action = min((self.prev_action/100), 1) * 1080
self.reward += 0.4
else:
self.ACC = 1
self.prev_action = self.action()
self.reset()
screen = ImageGrab.grab()
self.observation = np.array(screen)
except:
done = True
return self.observation, self.reward, done, {}
def reset(self):
self.observation = np.array()
self.reward = 0
self.done = 0
return self.observation
错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/rees/.local/lib/python3.6/site-packages/gym/envs/registration.py", line 171, in make
return registry.make(id, **kwargs)
File "/home/rees/.local/lib/python3.6/site-packages/gym/envs/registration.py", line 123, in make
env = spec.make(**kwargs)
File "/home/rees/.local/lib/python3.6/site-packages/gym/envs/registration.py", line 87, in make
env = cls(**_kwargs)
File "/home/rees/Desktop/gym-mouse/MouseGym/envs/mouse_env.py", line 12, in __init__
self.reset()
File "/home/rees/Desktop/gym-mouse/MouseGym/envs/mouse_env.py", line 41, in reset
self.observation = np.array()
TypeError: Required argument 'object' (pos 1) not found
预期结果:
我希望鼠标根据座席的输入/动作而移动,并且观察结果将成为屏幕上的实时视频输入...
答案 0 :(得分:0)
问题在于,在您的reset
函数中,当您尝试使用空的numpy数组初始化self.observation
时,没有将任何参数传递给np.array()
。这里有两个选项,将一个空列表传递给该函数:
self.observation = np.array([])
或使用np.empty
,这将创建一个空的numpy数组:
self.observation = np.empty(0)