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

Run error #5

Closed
jindongwang opened this issue Jul 7, 2017 · 5 comments
Closed

Run error #5

jindongwang opened this issue Jul 7, 2017 · 5 comments

Comments

@jindongwang
Copy link

jindongwang commented Jul 7, 2017

I'm using Python3.5+Tensorflow1.2+Keras on Windows 10, and I get the following error:

`C:\Users\jindongwang\Anaconda3\python.exe C:/Users/jindongwang/Desktop/cmd-master/exp_office.py
Using TensorFlow backend.
WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execute optimized C-implementations (for both CPU and GPU) and will default to Python implementations. Performance will be severely degraded. To remove this warning, set Theano flags cxx to an empty string.

Loading office image data...
Found 2817 images belonging to 31 classes.
Found 498 images belonging to 31 classes.
Found 795 images belonging to 31 classes.

Creating/Loading image representations via VGG_16 model...
C:\Users\jindongwang\Anaconda3\lib\site-packages\keras\legacy\interfaces.py:86: UserWarning: Update your Conv2D call to the Keras 2 API: Conv2D(64, (3, 3), activation="relu")
'call to the Keras 2 API: ' + signature) C:\Users\jindongwang\Anaconda3\lib\site-packages\keras\legacy\interfaces.py:86: UserWarning: Update yourConv2Dcall to the Keras 2 API:Conv2D(128, (3, 3), activation="relu") ' call to the Keras 2 API: ' + signature)
Traceback (most recent call last):
File "C:\Users\jindongwang\Anaconda3\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 671, in _call_cpp_shape_fn_impl
input_tensors_as_shapes, status)
File "C:\Users\jindongwang\Anaconda3\lib\contextlib.py", line 66, in exit
next(self.gen)
File "C:\Users\jindongwang\Anaconda3\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 2 from 1 for 'max_pooling2d_2/MaxPool' (op: 'MaxPool') with input shapes: [?,1,112,128].

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:/Users/jindongwang/Desktop/cmd-master/exp_office.py", line 53, in
'amazon', N_IMAGES_AM)
File "C:\Users\jindongwang\Desktop\cmd-master\models\office_mmatch.py", line 154, in create_img_repr
vgg16 = self.VGG_16(weights_file)
File "C:\Users\jindongwang\Desktop\cmd-master\models\office_mmatch.py", line 285, in VGG_16
model.add(MaxPooling2D((2,2), strides=(2,2)))
File "C:\Users\jindongwang\Anaconda3\lib\site-packages\keras\models.py", line 455, in add
output_tensor = layer(self.outputs[0])
File "C:\Users\jindongwang\Anaconda3\lib\site-packages\keras\engine\topology.py", line 554, in call
output = self.call(inputs, **kwargs)
File "C:\Users\jindongwang\Anaconda3\lib\site-packages\keras\layers\pooling.py", line 154, in call
data_format=self.data_format)
File "C:\Users\jindongwang\Anaconda3\lib\site-packages\keras\layers\pooling.py", line 217, in _pooling_function
pool_mode='max')
File "C:\Users\jindongwang\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py", line 3014, in pool2d
x = tf.nn.max_pool(x, pool_size, strides, padding=padding)
File "C:\Users\jindongwang\Anaconda3\lib\site-packages\tensorflow\python\ops\nn_ops.py", line 1769, in max_pool
name=name)
File "C:\Users\jindongwang\Anaconda3\lib\site-packages\tensorflow\python\ops\gen_nn_ops.py", line 1605, in _max_pool
data_format=data_format, name=name)
File "C:\Users\jindongwang\Anaconda3\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 767, in apply_op
op_def=op_def)
File "C:\Users\jindongwang\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 2508, in create_op
set_shapes_for_outputs(ret)
File "C:\Users\jindongwang\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 1873, in set_shapes_for_outputs
shapes = shape_func(op)
File "C:\Users\jindongwang\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py", line 1823, in call_with_requiring
return call_cpp_shape_fn(op, require_shape_fn=True)
File "C:\Users\jindongwang\Anaconda3\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 610, in call_cpp_shape_fn
debug_python_shape_fn, require_shape_fn)
File "C:\Users\jindongwang\Anaconda3\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 676, in _call_cpp_shape_fn_impl
raise ValueError(err.message)
ValueError: Negative dimension size caused by subtracting 2 from 1 for 'max_pooling2d_2/MaxPool' (op: 'MaxPool') with input shapes: [?,1,112,128].

Process finished with exit code 1`

What can I do?

@wzell
Copy link
Owner

wzell commented Jul 7, 2017

Hallo jindongwang,
nice to see Your interest in our project!

Unfortunately our code only supports the theano backend and not tensorflow. However, theano is only used in the file domain_regularizer.py. One simple fix would be to use the keras backend functionality, wherever theano is used (indicated by 'T.'), forcing it to use tensorflow. I.e. using

K.cast(i+2,'int32')

instead of

T.cast(i+2,'int32')

and

K.square(r - x2)

instead of

T.sqr(r - x2)

I have tested this solution with python 2.7 and keras 1.1.0. More details on the requirements can be found in requirements.txt. Downgrading keras works well if you are using pip with

pip install keras==1.1 --no-dependencies

and python 3.5 should work.

If You have futher problems I would be happy to help.

@jindongwang
Copy link
Author

Thank you @wzell for your kind reply!
I tried your way and replaced all "T.x" with "K.x" under Keras 1.1, but it still did not work. Here's some of the error msg:
qq 20170707162640

@wzell
Copy link
Owner

wzell commented Jul 7, 2017

I think this has something to do with the change of the keras backend from theano to tensorflow, see e.g.
keras-team/keras#3945.
The change in the json file should help.

@jindongwang
Copy link
Author

jindongwang commented Jul 8, 2017 via email

@wzell
Copy link
Owner

wzell commented Jul 9, 2017

Yes, this works. See exp_office.py for an example.

@wzell wzell closed this as completed Jul 9, 2017
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