tokb23 / dqn

DQN implementation in Keras + TensorFlow + OpenAI Gym
158 stars 58 forks source link

ValueError: Negative dimension size caused by subtracting 8 from 4 #1

Closed lxpan closed 7 years ago

lxpan commented 7 years ago

I'm getting the error, ValueError: Negative dimension size caused by subtracting 8 from 4, when running dqn.py. What could be causing this?

[2016-12-15 00:50:34,381] Making new env: Breakout-v0
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/common_shapes.py", line 594, in call_cpp_shape_fn
    status)
  File "/usr/lib/python3.5/contextlib.py", line 66, in __exit__
    next(self.gen)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/errors.py", line 463, in raise_exception_on_not_ok_status
    pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors.InvalidArgumentError: Negative dimension size caused by subtracting 8 from 4

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "dqn.py", line 312, in <module>
    main()
  File "dqn.py", line 275, in main
    agent = Agent(num_actions=env.action_space.n)
  File "dqn.py", line 58, in __init__
    self.s, self.q_values, q_network = self.build_network()
  File "dqn.py", line 90, in build_network
    model.add(Convolution2D(32, 8, 8, subsample=(4, 4), activation='relu', input_shape=(STATE_LENGTH, FRAME_WIDTH, FRAME_HEIGHT)))
  File "/usr/local/lib/python3.5/dist-packages/Keras-1.1.2-py3.5.egg/keras/models.py", line 294, in add
    layer.create_input_layer(batch_input_shape, input_dtype)
  File "/usr/local/lib/python3.5/dist-packages/Keras-1.1.2-py3.5.egg/keras/engine/topology.py", line 374, in create_input_layer
    self(x)
  File "/usr/local/lib/python3.5/dist-packages/Keras-1.1.2-py3.5.egg/keras/engine/topology.py", line 519, in __call__
    self.add_inbound_node(inbound_layers, node_indices, tensor_indices)
  File "/usr/local/lib/python3.5/dist-packages/Keras-1.1.2-py3.5.egg/keras/engine/topology.py", line 573, in add_inbound_node
    Node.create_node(self, inbound_layers, node_indices, tensor_indices)
  File "/usr/local/lib/python3.5/dist-packages/Keras-1.1.2-py3.5.egg/keras/engine/topology.py", line 155, in create_node
    output_tensors = to_list(outbound_layer.call(input_tensors[0], mask=input_masks[0]))
  File "/usr/local/lib/python3.5/dist-packages/Keras-1.1.2-py3.5.egg/keras/layers/convolutional.py", line 465, in call
    filter_shape=self.W_shape)
  File "/usr/local/lib/python3.5/dist-packages/Keras-1.1.2-py3.5.egg/keras/backend/tensorflow_backend.py", line 1734, in conv2d
    x = tf.nn.conv2d(x, kernel, strides, padding=padding)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/gen_nn_ops.py", line 394, in conv2d
    data_format=data_format, name=name)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/op_def_library.py", line 749, in apply_op
    op_def=op_def)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 2382, in create_op
    set_shapes_for_outputs(ret)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 1783, in set_shapes_for_outputs
    shapes = shape_func(op)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/common_shapes.py", line 596, in call_cpp_shape_fn
    raise ValueError(err.message)
ValueError: Negative dimension size caused by subtracting 8 from 4
tokb23 commented 7 years ago

Change image_dim_ordering (th or tf) in the file ~/.keras/keras.json. It can maybe fix the error.

barneydmedia commented 7 years ago

I had the same issue, but this fixed it. Thanks!

lxpan commented 7 years ago

Thanks, that did actually fix it!

DanielTakeshi commented 7 years ago

This worked for me as well. But would it also affect the results if one were to use other DQN software which used a different ordering? I'm using the Tensorflow backend and had to switch from tf to th which seems to be the opposite of the way it should be.