keon / deep-q-learning

Minimal Deep Q Learning (DQN & DDQN) implementations in Keras
https://keon.io/deep-q-learning
MIT License
1.27k stars 454 forks source link

ValueError: cannot reshape array of size 2 into shape (1,4) #36

Open akshay-paranjape opened 1 year ago

akshay-paranjape commented 1 year ago

I get this numpy error while running the script - dqn.py

2022-10-06 23:47:28.547558: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1934] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform. Skipping registering GPU devices... 2022-10-06 23:47:28.547772: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. /home/akshayparanjape/PhD/deep-q-learning/venv_dqn/lib/python3.8/site-packages/keras/optimizers/optimizer_v2/adam.py:114: UserWarning: Thelrargument is deprecated, uselearning_rateinstead. super().__init__(name, **kwargs) /home/akshayparanjape/PhD/deep-q-learning/venv_dqn/lib/python3.8/site-packages/numpy/core/_asarray.py:102: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray. return array(a, dtype, copy=False, order=order) Traceback (most recent call last): File "ddqn.py", line 100, in <module> state = np.reshape(state, [1, state_size]) File "<__array_function__ internals>", line 5, in reshape File "/home/akshayparanjape/PhD/deep-q-learning/venv_dqn/lib/python3.8/site-packages/numpy/core/fromnumeric.py", line 299, in reshape return _wrapfunc(a, 'reshape', newshape, order=order) File "/home/akshayparanjape/PhD/deep-q-learning/venv_dqn/lib/python3.8/site-packages/numpy/core/fromnumeric.py", line 55, in _wrapfunc return _wrapit(obj, method, *args, **kwds) File "/home/akshayparanjape/PhD/deep-q-learning/venv_dqn/lib/python3.8/site-packages/numpy/core/fromnumeric.py", line 44, in _wrapit result = getattr(asarray(obj), method)(*args, **kwds) ValueError: cannot reshape array of size 2 into shape (1,4) Has anybody encountered the same issue?

stefanomaxenti commented 1 year ago

If you want to run the code as-is, you need to downgrade gym to a very old version (0.7.3). That is: pip install gym==0.7.3 (maybe in a virtual environment).

PietroArsi commented 1 year ago

I get this numpy error while running the script - dqn.py

2022-10-06 23:47:28.547558: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1934] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform. Skipping registering GPU devices... 2022-10-06 23:47:28.547772: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. /home/akshayparanjape/PhD/deep-q-learning/venv_dqn/lib/python3.8/site-packages/keras/optimizers/optimizer_v2/adam.py:114: UserWarning: Thelrargument is deprecated, uselearning_rateinstead. super().__init__(name, **kwargs) /home/akshayparanjape/PhD/deep-q-learning/venv_dqn/lib/python3.8/site-packages/numpy/core/_asarray.py:102: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray. return array(a, dtype, copy=False, order=order) Traceback (most recent call last): File "ddqn.py", line 100, in <module> state = np.reshape(state, [1, state_size]) File "<__array_function__ internals>", line 5, in reshape File "/home/akshayparanjape/PhD/deep-q-learning/venv_dqn/lib/python3.8/site-packages/numpy/core/fromnumeric.py", line 299, in reshape return _wrapfunc(a, 'reshape', newshape, order=order) File "/home/akshayparanjape/PhD/deep-q-learning/venv_dqn/lib/python3.8/site-packages/numpy/core/fromnumeric.py", line 55, in _wrapfunc return _wrapit(obj, method, *args, **kwds) File "/home/akshayparanjape/PhD/deep-q-learning/venv_dqn/lib/python3.8/site-packages/numpy/core/fromnumeric.py", line 44, in _wrapit result = getattr(asarray(obj), method)(*args, **kwds) ValueError: cannot reshape array of size 2 into shape (1,4) Has anybody encountered the same issue?

Change code to state = env.reset()[0] More recent version of gym return the first state along with something else