0

I have this simple layer for my model

states = Input(shape=(len(inputFinal),))

This should generate a (328,None) but dunno why when I check is inverted

model.inputs
[<tf.Tensor 'input_1:0' shape=(None, 328) dtype=float32>]

And when I try to pass data to the model the layer is not correct

value.shape
(328,)

model.predict(value)

Input 0 of layer dense is incompatible with the layer: expected axis -1 of input shape to have value 328 but received input with shape [None, 1]

I cannot find the problem, any ideas ?

Nicolas Gervais
  • 33,817
  • 13
  • 115
  • 143

1 Answers1

1

When specifying the input shape, you only need to specify the number of features. Keras doesn't want to know the number of sample because it can accept any size. So, when you do this:

states = Input(shape=(len(inputFinal),))

You're telling Keras that your input has 328 columns, which isn't the case. Keras realizes this when you feed the input, and crashes.

If inputFinal is a 2D NumPy array, try:

Input(shape=inputFinal.shape[1:])
Nicolas Gervais
  • 33,817
  • 13
  • 115
  • 143
  • Thx for the answer but with your example I get this `Error converting shape to a TensorShape: Dimension value must be integer or None or have an __index__ method, got value '(328,)' with type ''.` – user2496229 Oct 24 '20 at 17:07
  • Ok I changed my answer slightly. Or just try `shape=328` – Nicolas Gervais Oct 24 '20 at 17:34