keras-team / keras

Deep Learning for humans
http://keras.io/
Apache License 2.0
61.57k stars 19.42k forks source link

Errors when trying to implement fully convolutional network in Keras #1985

Closed lukovkin closed 8 years ago

lukovkin commented 8 years ago

Trying to implement 1D fully convolutional network in Keras (within the UFCNN implementation, inspired by arXiv:1508.00317v1 [stat.ML] ). One of ideas was to use approach described here - http://cs231n.github.io/convolutional-networks/#convert (and probably used by Roni too) in order to improve computational efficiency (to avoid iterating through the input sequence with a step=1). We found earlier discussion on FCN in Keras, but it seems to be designed for much earlier version - https://github.com/fchollet/keras/issues/356.

Model generation code is here: https://gist.github.com/lukovkin/8d8d9994ecc20914b884 It compiles OK, but when I try to pass to the 'fit' function input/output data shaped like: X.shape (1, 53353, 4) y.shape (1, 53353, 3) I get the following error: on Theano 0.8.0.dev0 and Python 2.7

ValueError: Cannot feed value of shape (1, 53353, 4) for Tensor u'input_1:0', which has shape (Dimension(None), Dimension(500), Dimension(4))

on Theano 0.8.0.rc1 and Python 3.5

ValueError: Input dimension mis-match. (input[0].shape[1] = 500, input[1].shape[1] = 53353) Apply node that caused the error: Elemwise{mul,no_inplace}(InplaceDimShuffle{x,0,1}.0, InplaceDimShuffle{0,2,1}.0) Toposort index: 154 Inputs types: [TensorType(float32, (True, False, False)), TensorType(float32, 3D)] Inputs shapes: [(1, 500, 150), (1, 53353, 150)] Inputs strides: [(300000, 600, 4), (213412, 4, 213412)] Inputs values: ['not shown', 'not shown'] Outputs clients: [[Elemwise{scalar_sigmoid}(Elemwise{mul,no_inplace}.0), Elemwise{ScalarSoftplus}(0, 0)]]

Are there any ideas how to make Keras apply convolution to the sequence larger than input of convolution layer? - Or, rephrasing, how to use input of arbitrary length?

lukovkin commented 8 years ago

Hmm, seems to be different on release 0.3.2 and current working branch of Keras. On release version 0.3.2 will give the following error:

TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

Looks like should be working with input_shape=(None, features), but then fails on different error:

model.add_node(ParametricSoftplus(), name='relu1', input='conv1') TypeError: an integer is required

Probably will be working with simple ReLU, not tested yet, will update later.

lukovkin commented 8 years ago

OK, it works, at least technically, on current master branch of Keras (not on 0.3.2) and on Theano 0.8.0.rc1 and TensorFlow with ReLU activations, gist is here - https://gist.github.com/lukovkin/8d8d9994ecc20914b884#file-fcn_model_working-py.

On ParametricSoftplus activation gives abovementioned error.

I think usage of input_shape to allow arbitrary inputs should be documented in more details. I could try to add something to docs about it.

lukovkin commented 8 years ago

SReLU fails with the same message.

Probably Advanced Activations with weights are not able to process input_shape with None because of the implementation of the 'build' method. E.g. it fails at: self.alphas = K.variable(self.alpha_init * np.ones(input_shape), name='{}_alphas'.format(self.name)) self.betas = K.variable(self.beta_init * np.ones(input_shape), name='{}_betas'.format(self.name))

lukovkin commented 8 years ago

OK, original issue is resolved, bug with advanced activations it's better to create as separate issue.