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

Non-square images #3

Open
1 task
jlglover opened this issue Sep 21, 2017 · 3 comments
Open
1 task

Non-square images #3

jlglover opened this issue Sep 21, 2017 · 3 comments

Comments

@jlglover
Copy link

Great work on this! I find this to be the most user friendly code for doing transfer learning. I can get it to work well on square images of a variety of sizes but I get errors when working on non-square images (see below). Got any advice on how to get around this?

Thanks again for the great code!

Negative dimension size caused by subtracting 7 from 2 for 'avg_pool/AvgPool' (op: 'AvgPool') with input shapes: [?,2,8,2048].
Traceback (most recent call last):
File "C:\Python35\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 654, in _call_cpp_shape_fn_impl
input_tensors_as_shapes, status)
File "C:\Python35\lib\contextlib.py", line 66, in exit
next(self.gen)
File "C:\Python35\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 7 from 2 for 'avg_pool/AvgPool' (op: 'AvgPool') with input shapes: [?,2,8,2048].

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "W:/work2017/TSA_kaggle/python_code/train_VGG16.py", line 57, in
train(args.nb_epoch, args.freeze_layers_number)
File "W:/work2017/TSA_kaggle/python_code/train_VGG16.py", line 43, in train
model.train()
File "W:\work2017\TSA_kaggle\python_code\models\base_model.py", line 89, in train
self._create()
File "W:\work2017\TSA_kaggle\python_code\models\resnet50.py", line 20, in _create
base_model = KerasResNet50(include_top=False, input_tensor=self.get_input_tensor())
File "C:\Python35\lib\site-packages\keras\applications\resnet50.py", line 232, in ResNet50
x = AveragePooling2D((7, 7), name='avg_pool')(x)
File "C:\Python35\lib\site-packages\keras\engine\topology.py", line 602, in call
output = self.call(inputs, **kwargs)
File "C:\Python35\lib\site-packages\keras\layers\pooling.py", line 154, in call
data_format=self.data_format)
File "C:\Python35\lib\site-packages\keras\layers\pooling.py", line 271, in _pooling_function
padding, data_format, pool_mode='avg')
File "C:\Python35\lib\site-packages\keras\backend\tensorflow_backend.py", line 3388, in pool2d
x = tf.nn.avg_pool(x, pool_size, strides, padding=padding)
File "C:\Python35\lib\site-packages\tensorflow\python\ops\nn_ops.py", line 1744, in avg_pool
name=name)
File "C:\Python35\lib\site-packages\tensorflow\python\ops\gen_nn_ops.py", line 46, in _avg_pool
data_format=data_format, name=name)
File "C:\Python35\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 767, in apply_op
op_def=op_def)
File "C:\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 2632, in create_op
set_shapes_for_outputs(ret)
File "C:\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 1911, in set_shapes_for_outputs
shapes = shape_func(op)
File "C:\Python35\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:\Python35\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 595, in call_cpp_shape_fn
require_shape_fn)
File "C:\Python35\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 7 from 2 for 'avg_pool/AvgPool' (op: 'AvgPool') with input shapes: [?,2,8,2048].

  • [Tensorflow ] Which backend do you use (TensorFlow or Theano) and what its version?

  • [3.5 ] What version of Python?

  • What version of Keras?

@indiejoseph
Copy link

indiejoseph commented Sep 28, 2017

This problem likely caused by Keras version.
FYR: keras-team/keras#3945

  • Tensorflow: v1.3
  • Keras: 2.0.8
  • Python: 3.5

@jlglover
Copy link
Author

I don't think so, as I tried both ordering conventions and got similar errors.

@indiejoseph
Copy link

another reason is your image size cannot divide by the model input size, eg: ResNet50(244, 244)

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