Arsey/keras-transfer-learning-for-oxford102

predict.py fails on vgg16

xdvx opened this issue · 1 comments

xdvx commented

I have fine-tunned vgg16 model. Then I wanted to run predict.py, I got this:

Called with args: Namespace(accuracy=False, batch_size=500, data_dir=None, execution_time=False, model='vgg16', novelty_detection=False, path='/home/xdvx/deeplearningtools/nudity/negative/', plot_confusion_matrix=False, store_activations=False) Creating model Traceback (most recent call last): File "predict.py", line 142, in <module> model = model_module.load() File "/home/xdvx/deeplearningtools/keras-transfer-learning-for-oxford102/models/base_model.py", line 56, in load self._create() File "/home/xdvx/deeplearningtools/keras-transfer-learning-for-oxford102/models/vgg16.py", line 16, in _create base_model = KerasVGG16(weights='imagenet', include_top=False, input_tensor=self.get_input_tensor()) File "/usr/local/lib/python2.7/dist-packages/keras/applications/vgg16.py", line 118, in VGG16 x = MaxPooling2D((2, 2), strides=(2, 2), name='block2_pool')(x) File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 596, in __call__ output = self.call(inputs, **kwargs) File "/usr/local/lib/python2.7/dist-packages/keras/layers/pooling.py", line 154, in call data_format=self.data_format) File "/usr/local/lib/python2.7/dist-packages/keras/layers/pooling.py", line 217, in _pooling_function pool_mode='max') File "/usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py", line 3288, in pool2d x = tf.nn.max_pool(x, pool_size, strides, padding=padding) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/nn_ops.py", line 1839, in max_pool name=name) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_nn_ops.py", line 1672, in _max_pool data_format=data_format, name=name) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 768, in apply_op op_def=op_def) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2338, in create_op set_shapes_for_outputs(ret) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1719, in set_shapes_for_outputs shapes = shape_func(op) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1669, in call_with_requiring return call_cpp_shape_fn(op, require_shape_fn=True) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/common_shapes.py", line 610, in call_cpp_shape_fn debug_python_shape_fn, require_shape_fn) File "/usr/local/lib/python2.7/dist-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 'block2_pool/MaxPool' (op: 'MaxPool') with input shapes: [?,1,112,128].

xdvx commented

I solved the issue, just had to include this on the top:

from keras import backend as K

K.set_image_dim_ordering('th')