oarriaga / STN.keras

Implementation of spatial transformer networks (STNs) in keras 2 with tensorflow as backend.
MIT License
278 stars 75 forks source link

ValueError: The channel dimension of the inputs should be defined. Found `None`. #16

Open jiangkansg opened 4 years ago

jiangkansg commented 4 years ago

Hi, thank you for sharing your code.

When I run it in a google colab (keras=2.4.3), I got following error. Any idea on how to correct it?

Thank you.


ValueError Traceback (most recent call last)

in () ----> 1 model = STN() 2 model.compile(loss='categorical_crossentropy', optimizer='adam') 3 model.summary() 5 frames /content/STN.keras/src/models/STN.py in STN(input_shape, sampling_size, num_classes) 23 locnet = Dense(6, weights=weights)(locnet) 24 x = BilinearInterpolation(sampling_size)([image, locnet]) ---> 25 x = Conv2D(32, (3, 3), padding='same')(x) 26 x = Activation('relu')(x) 27 x = MaxPool2D(pool_size=(2, 2))(x) /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/base_layer.py in __call__(self, *args, **kwargs) 924 if _in_functional_construction_mode(self, inputs, args, kwargs, input_list): 925 return self._functional_construction_call(inputs, args, kwargs, --> 926 input_list) 927 928 # Maintains info about the `Layer.call` stack. /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/base_layer.py in _functional_construction_call(self, inputs, args, kwargs, input_list) 1096 # Build layer if applicable (if the `build` method has been 1097 # overridden). -> 1098 self._maybe_build(inputs) 1099 cast_inputs = self._maybe_cast_inputs(inputs, input_list) 1100 /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/base_layer.py in _maybe_build(self, inputs) 2641 # operations. 2642 with tf_utils.maybe_init_scope(self): -> 2643 self.build(input_shapes) # pylint:disable=not-callable 2644 # We must set also ensure that the layer is marked as built, and the build 2645 # shape is stored since user defined build functions may not be calling /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/layers/convolutional.py in build(self, input_shape) 185 def build(self, input_shape): 186 input_shape = tensor_shape.TensorShape(input_shape) --> 187 input_channel = self._get_input_channel(input_shape) 188 if input_channel % self.groups != 0: 189 raise ValueError( /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/layers/convolutional.py in _get_input_channel(self, input_shape) 357 channel_axis = self._get_channel_axis() 358 if input_shape.dims[channel_axis].value is None: --> 359 raise ValueError('The channel dimension of the inputs ' 360 'should be defined. Found `None`.') 361 return int(input_shape[channel_axis]) ValueError: The channel dimension of the inputs should be defined. Found `None`.
YToleubay commented 4 years ago

Good day, @jiangkansg!

I am facing the same issue. have you found an solution to the problem?

jiangkansg commented 4 years ago

Change line 128 (the second line below) of layers.py to def _transform(self, X, affine_transformation, output_size): batch_size, num_channels = K.shape(X)[0], 1