Receiving a TypeError: Required argument 'object' (pos 1) not found
Receiving a TypeError: Required argument 'object' (pos 1) not found
我正在尝试创建一个可以移动鼠标的健身房环境(显然是在 VM 中)...我对 类 了解不多,但是应该有一个论据自己还是什么……?此外,任何改进将不胜感激...
这段代码基本上是 运行 在 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
预期结果:
我希望鼠标根据代理的 input/actions 移动,并且观察是屏幕的实时视频提要...
问题在于,在您的 reset
函数中,当您尝试使用空的 numpy 数组初始化 self.observation
时,您没有将任何参数传递给 np.array()
。这里有两个选项,将一个空列表传递给函数:
self.observation = np.array([])
或使用np.empty
,这将创建一个空的numpy数组:
self.observation = np.empty(0)
我正在尝试创建一个可以移动鼠标的健身房环境(显然是在 VM 中)...我对 类 了解不多,但是应该有一个论据自己还是什么……?此外,任何改进将不胜感激...
这段代码基本上是 运行 在 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
预期结果:
我希望鼠标根据代理的 input/actions 移动,并且观察是屏幕的实时视频提要...
问题在于,在您的 reset
函数中,当您尝试使用空的 numpy 数组初始化 self.observation
时,您没有将任何参数传递给 np.array()
。这里有两个选项,将一个空列表传递给函数:
self.observation = np.array([])
或使用np.empty
,这将创建一个空的numpy数组:
self.observation = np.empty(0)