poke-env icon indicating copy to clipboard operation
poke-env copied to clipboard

ValueError: Error when checking input: expected dense_input to have shape (1, 10) but got array with shape (1, 2)

Open wogikaze opened this issue 2 years ago • 2 comments

An error occurred while trying to run rl_with_new_open_ai_gym_wrapper. I made the following changes from the original code

  • ObservationType-> ObsType
  • tensorflow.keras -> keras
C:\Users\User\AppData\Roaming\Python\Python310\site-packages\gymnasium\utils\env_checker.py:190: UserWarning: WARN: Official support for the `seed` function is dropped. Standard practice is to reset gymnasium environments using `env.reset(seed=<desired seed>)`
  logger.warn(
C:\Users\User\AppData\Roaming\Python\Python310\site-packages\gymnasium\utils\env_checker.py:173: UserWarning: WARN: `return_info` is deprecated as an optional argument to `reset`. `reset`should now always return `obs, info` where `obs` is an observation, and `info` is a dictionarycontaining additional information.
  logger.warn(
C:\Users\User\AppData\Roaming\Python\Python310\site-packages\gymnasium\utils\env_checker.py:321: UserWarning: WARN: Not able to test alternative render modes due to the environment not having a spec. Try instantialising the environment through gymnasium.make
  logger.warn(
2024-01-08 14:19:59.771311: W tensorflow/core/common_runtime/pluggable_device/pluggable_device_bfc_allocator.cc:28] Overriding allow_growth setting because force_memory_growth was requested by the device.
Training for 10000 steps ...
Interval 1 (0 steps performed)
Traceback (most recent call last):
  File "c:\Users\User\Desktop\poke-ai\Players\QLPlayer.py", line 184, in <module>
    asyncio.get_event_loop().run_until_complete(main())
  File "C:\Program Files\Python310\lib\asyncio\base_events.py", line 649, in run_until_complete
    return future.result()
  File "c:\Users\User\Desktop\poke-ai\Players\QLPlayer.py", line 131, in main
    dqn.fit(train_env, nb_steps=10000)
  File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\rl\core.py", line 168, in fit
    action = self.forward(observation)
  File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\rl\agents\dqn.py", line 224, in forward
    q_values = self.compute_q_values(state)
  File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\rl\agents\dqn.py", line 68, in compute_q_values
    q_values = self.compute_batch_q_values([state]).flatten()
  File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\rl\agents\dqn.py", line 63, in compute_batch_q_values
    q_values = self.model.predict_on_batch(batch)
  File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\keras\engine\training_v1.py", line 1304, in predict_on_batch
    inputs, _, _ = self._standardize_user_data(
  File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\keras\engine\training_v1.py", line 2649, in _standardize_user_data
    return self._standardize_tensors(
  File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\keras\engine\training_v1.py", line 2690, in _standardize_tensors
    x = training_utils_v1.standardize_input_data(
  File "C:\Users\User\AppData\Roaming\Python\Python310\site-packages\keras\engine\training_utils_v1.py", line 733, in standardize_input_data
    raise ValueError(
ValueError: Error when checking input: expected dense_input to have shape (1, 10) but got array with shape (1, 2)

wogikaze avatar Jan 08 '24 05:01 wogikaze

I believe most - if not all - of the examples are being reworked in #459 since it is true that most of the examples don't work as-is currently.

cameronangliss avatar Jan 16 '24 00:01 cameronangliss

I have the same problem. Can someone please tell me what to do.

turibito avatar Mar 23 '24 14:03 turibito

Any solution to this ? Please let Me know since I have to submit a project in a week

Ank-22 avatar Apr 14 '24 08:04 Ank-22

Hello, the problem is that when the env is resetted the return of the function is a tuple (observation, Dict) in the file rl/core.py.

I personnally modified this code and just extract the first element of the tuple as the observation as temp solution:

(site-packages/rl/core.py line 122)
....
        try:
            while self.step < nb_steps:
                if observation is None:  # start of a new episode
                    callbacks.on_episode_begin(episode)
                    episode_step = np.int16(0)
                    episode_reward = np.float32(0)

                    # Obtain the initial observation by resetting the environment.
                    self.reset_states()
                    observation = deepcopy(env.reset())

                    # ADDED - Process the observation
                    observation = observation[0]

FIEVEZDHELHa avatar Apr 16 '24 13:04 FIEVEZDHELHa

Please see https://github.com/hsahovic/poke-env/issues/508#issuecomment-2054201642

hsahovic avatar Apr 16 '24 13:04 hsahovic