1

To use multi-GPU, I upgrade keras(1.2.0 --> 2.2.4) version. I don't change any of code, but there is an error. What is the reason of this ERROR?

I attached the reproducible code below. As you can see A & B have same shapes, but only testB got the dimension error.

< Keras 1.2.0 LOGS >

> pip3 install keras==1.2.0 --user
> python test.py
Using TensorFlow backend.
Done

< Keras 2.2.4 LOGS >

> pip3 install git+git://github.com/fchollet/keras.git --upgrade --user
> python test.py
Using TensorFlow backend.
test.py:26: UserWarning: Update your `Conv1D` call to the Keras 2 API: `Conv1D(128, 3, use_bias=False)`
  testA = keras.layers.Conv1D(128,3,bias=False)(A)
test.py:27: UserWarning: Update your `Conv1D` call to the Keras 2 API: `Conv1D(128, 3, use_bias=False)`
  testB = keras.layers.Conv1D(128,3,bias=False)(B)
Traceback (most recent call last):
  File "test.py", line 27, in <module>
    testB = keras.layers.Conv1D(128,3,bias=False)(B) 
  File "/home/nam/.local/lib/python3.6/site-packages/keras/engine/base_layer.py", line 457, in __call__
    output = self.call(inputs, **kwargs)
  File "/home/nam/.local/lib/python3.6/site-packages/keras/layers/convolutional.py", line 163, in call
    dilation_rate=self.dilation_rate[0])
  File "/home/nam/.local/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 3881, in conv1d
    data_format=tf_data_format)
  File "/home/nam/.local/lib/python3.6/site-packages/tensorflow/python/ops/nn_ops.py", line 779, in convolution
    data_format=data_format)
  File "/home/nam/.local/lib/python3.6/site-packages/tensorflow/python/ops/nn_ops.py", line 839, in __init__
    filter_shape[num_spatial_dims]))
ValueError: number of input channels does not match corresponding dimension of filter, 1 != 1603

This is the reproducible code.

import keras

class AddSingletonDepth(keras.layers.Layer):

    def call(self, x, mask=None):
        x = keras.backend.expand_dims(x, -1)  # add a dimension of the right

        if keras.backend.ndim(x) == 4:
            return keras.backend.permute_dimensions(x, (0, 3, 1, 2))
        else:
            return x

    def get_output_shape_for(self, input_shape):
        if len(input_shape) == 3:
            return input_shape[0], 1, input_shape[1], input_shape[2]
        else:
            return input_shape[0], input_shape[1], 1


data = keras.engine.Input([1603])
A=keras.backend.expand_dims(data,-1)
B=AddSingletonDepth()(data)
testA = keras.layers.Conv1D(128,3,bias=False)(A)
testB = keras.layers.Conv1D(128,3,bias=False)(B) 
print('Done')

I expect to know the reason of the Error. And I really likes to use this formation as possible, but if it's impossible could you show me how to fix the error?

Thank you.

남현준
  • 31
  • 2

0 Answers0