Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_snake.py 'Negative Dimension Size caused by... #23

Open
gaara100 opened this issue Sep 4, 2017 · 1 comment
Open

test_snake.py 'Negative Dimension Size caused by... #23

gaara100 opened this issue Sep 4, 2017 · 1 comment

Comments

@gaara100
Copy link

gaara100 commented Sep 4, 2017

Using TensorFlow backend.
Traceback (most recent call last):
File "C:\Users\Me\Anaconda3\envs\tf_rl\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 654, in _call_cpp_shape_fn_impl
input_tensors_as_shapes, status)
File "C:\Users\Me\Anaconda3\envs\tf_rl\lib\contextlib.py", line 66, in exit
next(self.gen)
File "C:\Users\Me\Anaconda3\envs\tf_rl\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 466, in raise_exception_on_not_ok_status
pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: Negative dimension size caused by subtracting 3 from 2 for 'Conv2D_1' (op: 'Conv2D') with input shapes: [?,2,8,16], [3,3,16,32].

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "test_snake.py", line 13, in
model.add(Convolution2D(32, nb_row=3, nb_col=3, activation='relu'))
File "C:\Users\Me\Anaconda3\envs\tf_rl\lib\site-packages\keras-1.2.2-py3.5.egg\keras\models.py", line 332, in add
output_tensor = layer(self.outputs[0])
File "C:\Users\Me\Anaconda3\envs\tf_rl\lib\site-packages\keras-1.2.2-py3.5.egg\keras\engine\topology.py", line 572, in call
self.add_inbound_node(inbound_layers, node_indices, tensor_indices)
File "C:\Users\Me\Anaconda3\envs\tf_rl\lib\site-packages\keras-1.2.2-py3.5.egg\keras\engine\topology.py", line 635, in add_inbound_node
Node.create_node(self, inbound_layers, node_indices, tensor_indices)
File "C:\Users\Me\Anaconda3\envs\tf_rl\lib\site-packages\keras-1.2.2-py3.5.egg\keras\engine\topology.py", line 166, in create_node
output_tensors = to_list(outbound_layer.call(input_tensors[0], mask=input_masks[0]))
File "C:\Users\Me\Anaconda3\envs\tf_rl\lib\site-packages\keras-1.2.2-py3.5.egg\keras\layers\convolutional.py", line 475, in call
filter_shape=self.W_shape)
File "C:\Users\Me\Anaconda3\envs\tf_rl\lib\site-packages\keras-1.2.2-py3.5.egg\keras\backend\tensorflow_backend.py", line 2691, in conv2d
x = tf.nn.conv2d(x, kernel, strides, padding=padding)
File "C:\Users\Me\Anaconda3\envs\tf_rl\lib\site-packages\tensorflow\python\ops\gen_nn_ops.py", line 397, in conv2d
data_format=data_format, name=name)
File "C:\Users\Me\Anaconda3\envs\tf_rl\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 767, in apply_op
op_def=op_def)
File "C:\Users\Me\Anaconda3\envs\tf_rl\lib\site-packages\tensorflow\python\framework\ops.py", line 2632, in create_op
set_shapes_for_outputs(ret)
File "C:\Users\Me\Anaconda3\envs\tf_rl\lib\site-packages\tensorflow\python\framework\ops.py", line 1911, in set_shapes_for_outputs
shapes = shape_func(op)
File "C:\Users\Me\Anaconda3\envs\tf_rl\lib\site-packages\tensorflow\python\framework\ops.py", line 1861, in call_with_requiring
return call_cpp_shape_fn(op, require_shape_fn=True)
File "C:\Users\Me\Anaconda3\envs\tf_rl\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 595, in call_cpp_shape_fn
require_shape_fn)
File "C:\Users\Me\Anaconda3\envs\tf_rl\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 659, in _call_cpp_shape_fn_impl
raise ValueError(err.message)
ValueError: Negative dimension size caused by subtracting 3 from 2 for 'Conv2D_1' (op: 'Conv2D') with input shapes: [?,2,8,16], [3,3,16,32].

I get the above error when I try to run test_snake.py, with Keras version 1.2.2 and Tensorflow-gpu version 1.3.0

Thoughts?

@RozenAstrayChen
Copy link

Hi , I have same problem , I found this to fix it

model.add(Convolution2D(32, (3, 3), activation='relu', input_shape=(1, 28, 28), data_format='channels_first'))

add data_format='channels_first'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants