Receiving a TypeError: Required argument 'object' (pos 1) not found
The issue is that in your reset
function, when you try to initialize self.observation
with an empty numpy array, you do not pass any arguments to np.array()
. You have two options here, pass an empty list to the function:
self.observation = np.array([])
or use np.empty
, which will create an empty numpy array:
self.observation = np.empty(0)
ZeroMaxinumXZ
Stack Overflow user and fellow typical programmer who likes coffee.
Updated on July 20, 2022Comments
-
ZeroMaxinumXZ almost 2 years
I'm trying to create an gym environment that moves the mouse (in a VM, obviously)... I don't know much about classes, but is there supposed to be an argument for self or something...? Also, any improvements would be greatly appreciated...
This code is basically going to run on a VM, soo...I've tried to remove the line of code, but there's several lines that don't run... (I'm terrible at explaining things)
Here's the code:
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
And the error:
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
Expected Result:
I expect the mouse to move based on the agent's input/actions, and the observation to be a live video feed of the screen...
-
Aule Mahal over 5 yearsThe traceback quotes the line :
self.observation = np.array()
, but the same line in your code isself.observation = np.array(screen)
. Did you copy your code correctly? -
ZeroMaxinumXZ over 5 yearsOkay, I tried rebuilding my module using pip install -e . in the gym-mouse directory... Same error when I try to make the gym environment using gym.make...
-
ZeroMaxinumXZ over 5 yearsThere's a reset function towards the bottom of my code also...
-
Dillon Davis over 5 yearsIt would be useful to have the code for
reset
as well, given:File ... line 41, in reset
indicates that's where the error is...
-