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

There is argument issue about Pooling layer(AveragePooling2D : border_mode) #82

Open
4 tasks done
linetor opened this issue Sep 13, 2017 · 2 comments · May be fixed by #89
Open
4 tasks done

There is argument issue about Pooling layer(AveragePooling2D : border_mode) #82

linetor opened this issue Sep 13, 2017 · 2 comments · May be fixed by #89

Comments

@linetor
Copy link

linetor commented Sep 13, 2017

I want to use keras.applications.inception_v3 model. After I load that model it, there is an error about pooling layer.

Error Message
:----> 1 InceptionV3(include_top=True,input_tensor=None, input_shape=None,weights=None)

/pang/linetor/miniconda2/envs/py27/lib/python2.7/site-packages/keras/applications/inception_v3.pyc in InceptionV3(include_top, weights, input_tensor, input_shape, classes)
149
150 branch_pool = AveragePooling2D(
--> 151 (3, 3), strides=(1, 1), border_mode='same')(x)
152 branch_pool = conv2d_bn(branch_pool, 32, 1, 1)
153 x = merge([branch1x1, branch5x5, branch3x3dbl, branch_pool],

/pang/linetor/miniconda2/envs/py27/lib/python2.7/site-packages/keras/engine/topology.pyc in call(self, x, mask)
570 if inbound_layers:
571 # This will call layer.build() if necessary.
--> 572 self.add_inbound_node(inbound_layers, node_indices, tensor_indices)
573 # Outputs were already computed when calling self.add_inbound_node.
574 outputs = self.inbound_nodes[-1].output_tensors

/pang/linetor/miniconda2/envs/py27/lib/python2.7/site-packages/keras/engine/topology.pyc in add_inbound_node(self, inbound_layers, node_indices, tensor_indices)
633 # creating the node automatically updates self.inbound_nodes
634 # as well as outbound_nodes on inbound layers.
--> 635 Node.create_node(self, inbound_layers, node_indices, tensor_indices)
636
637 def get_output_shape_for(self, input_shape):

/pang/linetor/miniconda2/envs/py27/lib/python2.7/site-packages/keras/engine/topology.pyc in create_node(cls, outbound_layer, inbound_layers, node_indices, tensor_indices)
164
165 if len(input_tensors) == 1:
--> 166 output_tensors = to_list(outbound_layer.call(input_tensors[0], mask=input_masks[0]))
167 output_masks = to_list(outbound_layer.compute_mask(input_tensors[0], input_masks[0]))
168 # TODO: try to auto-infer shape

/pang/linetor/miniconda2/envs/py27/lib/python2.7/site-packages/keras/layers/pooling.pyc in call(self, x, mask)
158 strides=self.strides,
159 border_mode=self.border_mode,
--> 160 dim_ordering=self.dim_ordering)
161 return output
162

/pang/linetor/miniconda2/envs/py27/lib/python2.7/site-packages/keras/layers/pooling.pyc in _pooling_function(self, inputs, pool_size, strides, border_mode, dim_ordering)
249 border_mode, dim_ordering):
250 output = K.pool2d(inputs, pool_size, strides,
--> 251 border_mode, dim_ordering, pool_mode='avg')
252 return output
253

/pang/linetor/miniconda2/envs/py27/lib/python2.7/site-packages/keras/backend/mxnet_backend.pyc in func_wrapper(*args, **kwargs)
31 old = learning_phase()
32 set_learning_phase(1)
---> 33 train_ret = func(*args, **kwargs)
34 set_learning_phase(0)
35 test_ret = func(*args, **kwargs)

/pang/linetor/miniconda2/envs/py27/lib/python2.7/site-packages/keras/backend/mxnet_backend.pyc in pool2d(x, pool_size, strides, border_mode, dim_ordering, pool_mode)
2910 x = _preprocess_convnd_input(x, dim_ordering)
2911 s = mx.sym.Pooling(data=x.symbol, kernel=pool_size, pool_type=pool_mode, pooling_convention=border_mode,
-> 2912 stride=strides)
2913 out = _postprocess_convnd_output(KerasSymbol(s), dim_ordering)
2914 return out

/pang/linetor/.local/lib/python2.7/site-packages/mxnet/symbol.pyc in Pooling(data, global_pool, cudnn_off, kernel, pool_type, pooling_convention, stride, pad, name, attr, out, **kwargs)

/pang/linetor/.local/lib/python2.7/site-packages/mxnet/_ctypes/symbol.pyc in _symbol_creator(handle, args, kwargs, keys, vals, name)
125 c_array(ctypes.c_char_p, [c_str(i) for i in keys]),
126 c_array(ctypes.c_char_p, [c_str(str(i)) for i in vals]),
--> 127 ctypes.byref(sym_handle)))
128
129 if args and kwargs:

/pang/linetor/.local/lib/python2.7/site-packages/mxnet/base.pyc in check_call(ret)
127 """
128 if ret != 0:
--> 129 raise MXNetError(py_str(_LIB.MXGetLastError()))
130
131 if sys.version_info[0] < 3:

MXNetError: Invalid Input: 'same', valid values are: {'full', 'valid'}, in operator Pooling(name="", stride="(1, 1)", pooling_convention="same", pool_type="avg", kernel="(3, 3)")

If I read error message, I think argument about border _mode. In keras 1.2.2, Pooling layer 's argument : border_mode need to be in ('valid' or 'same'). But by using mxnet, back-end it says {'full', 'valid'}.
If I use "same', mxnet makes a issue. If I use 'full', keras makes issue. So I can't implement InceptionResNetV2.

Is there any comment about this?

Please make sure that the boxes below are checked before you submit your issue. If your issue is an implementation question, please ask your question on StackOverflow or join the Keras Slack channel and ask there instead of filing a GitHub issue.

Thank you!

  • Check that you are up-to-date with the master branch of Keras. You can update with:
    pip install git+git://github.com/fchollet/keras.git --upgrade --no-deps

  • If running on TensorFlow, check that you are up-to-date with the latest version. The installation instructions can be found here.

  • If running on Theano, check that you are up-to-date with the master branch of Theano. You can update with:
    pip install git+git://github.com/Theano/Theano.git --upgrade --no-deps

  • Provide a link to a GitHub Gist of a Python script that can reproduce your issue (or just copy the script here if it is short).

@MaJieCornell
Copy link

I also encounter this issue when trying to use Inception_v3 in Keras. I think there is an issue in python2.7/site-packages/keras/backend/mxnet_backend.py when convert the argument from Keras to MXnet. They are not compatible.

Is there anyone look into this issue?

Thanks

@heroxrq
Copy link

heroxrq commented Sep 30, 2017

@mli @pluskid @superbobry @MaJieCornell
I meet the problem too (see #87 ). However, after I add the following 2 lines in mxnet_backend.py pool2d() to convert keras 'same' to mxnet 'full':


    if border_mode == 'same':
        border_mode = 'full'

another problem comes:

Using MXNet backend.
train and valid generator is ok
steps_per_epoch: 55673
validation_steps: 1236
[10:19:53] /home/travis/build/dmlc/mxnet-distro/mxnet-build/dmlc-core/include/dmlc/logging.h:308: [10:19:53] src/operator/./concat-inl.h:184: Check failed: shape_assign(&(*in_shape)[i], dshape) Incompatible input shape: expected (0,0,20,20), got (0,32,18,18)

Stack trace returned 10 entries:
[bt] (0) /home/xierenqiang/install/anaconda3/lib/python3.6/site-packages/mxnet/libmxnet.so(+0x1d57cc) [0x2b02257607cc]
[bt] (1) /home/xierenqiang/install/anaconda3/lib/python3.6/site-packages/mxnet/libmxnet.so(+0x1005a79) [0x2b0226590a79]
[bt] (2) /home/xierenqiang/install/anaconda3/lib/python3.6/site-packages/mxnet/libmxnet.so(+0xf9d2d7) [0x2b02265282d7]
[bt] (3) /home/xierenqiang/install/anaconda3/lib/python3.6/site-packages/mxnet/libmxnet.so(+0x2d6d621) [0x2b02282f8621]
[bt] (4) /home/xierenqiang/install/anaconda3/lib/python3.6/site-packages/mxnet/libmxnet.so(+0x2d6ee32) [0x2b02282f9e32]
[bt] (5) /home/xierenqiang/install/anaconda3/lib/python3.6/site-packages/mxnet/libmxnet.so(+0x2d6f776) [0x2b02282fa776]
[bt] (6) /home/xierenqiang/install/anaconda3/lib/python3.6/site-packages/mxnet/libmxnet.so(+0x2d58f78) [0x2b02282e3f78]
[bt] (7) /home/xierenqiang/install/anaconda3/lib/python3.6/site-packages/mxnet/libmxnet.so(+0xe0fcae) [0x2b022639acae]
[bt] (8) /home/xierenqiang/install/anaconda3/lib/python3.6/site-packages/mxnet/libmxnet.so(+0xe125de) [0x2b022639d5de]
[bt] (9) /home/xierenqiang/install/anaconda3/lib/python3.6/site-packages/mxnet/libmxnet.so(MXSymbolInferShape+0x156f) [0x2b0226395fdf]

Traceback (most recent call last):
File "train_inception_v3_transfer_learning.py", line 64, in
base_model = InceptionV3(include_top=False, weights=None, input_shape=(3, INPUT_HEIGHT, INPUT_WIDTH))
File "/home/xierenqiang/install/anaconda3/lib/python3.6/site-packages/keras/applications/inception_v3.py", line 141, in InceptionV3
branch1x1 = conv2d_bn(x, 64, 1, 1)
File "/home/xierenqiang/install/anaconda3/lib/python3.6/site-packages/keras/applications/inception_v3.py", line 58, in conv2d_bn
name=conv_name)(x)
File "/home/xierenqiang/install/anaconda3/lib/python3.6/site-packages/keras/engine/topology.py", line 529, in call
self.assert_input_compatibility(x)
File "/home/xierenqiang/install/anaconda3/lib/python3.6/site-packages/keras/engine/topology.py", line 464, in assert_input_compatibility
if K.ndim(x) != spec.ndim:
File "/home/xierenqiang/install/anaconda3/lib/python3.6/site-packages/keras/backend/mxnet_backend.py", line 634, in ndim
s = shape(x)
File "/home/xierenqiang/install/anaconda3/lib/python3.6/site-packages/keras/backend/mxnet_backend.py", line 579, in shape
return x.get_shape()
File "/home/xierenqiang/install/anaconda3/lib/python3.6/site-packages/keras/backend/mxnet_backend.py", line 258, in get_shape
_, out_shape, _ = self.symbol.infer_shape_partial()
File "/home/xierenqiang/install/anaconda3/lib/python3.6/site-packages/mxnet/symbol.py", line 1050, in infer_shape_partial
return self._infer_shape_impl(True, *args, **kwargs)
File "/home/xierenqiang/install/anaconda3/lib/python3.6/site-packages/mxnet/symbol.py", line 1107, in _infer_shape_impl
ctypes.byref(complete)))
File "/home/xierenqiang/install/anaconda3/lib/python3.6/site-packages/mxnet/base.py", line 129, in check_call
raise MXNetError(py_str(_LIB.MXGetLastError()))
mxnet.base.MXNetError: Error in operator concat0: [10:19:53] src/operator/./concat-inl.h:184: Check failed: shape_assign(&(*in_shape)[i], dshape) Incompatible input shape: expected (0,0,20,20), got (0,32,18,18)

@rajendra2 rajendra2 linked a pull request Oct 11, 2017 that will close this issue
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

Successfully merging a pull request may close this issue.

3 participants