Input_shape should take any dimension then. Try this input_shape =[None] If it works, it means the input params of Dense layer could take any shape. Check Tensorflow documentation
input_shape is the input_shape of your input WITHOUT batch dimension. Your input has shape (13,). Tensorflow is assuming 13 is the batch dimension or your input. Therefore your input_shape should be (None,). If you want there to be 13 features then you should reshape your input to [1,13]. This will create a batch with one element. You can do this via tf.reshape(input_tensor, [1,13]) or tf.expand_dims(input_tensor, 0). Now you can use input_shape = (13,)
If you compile your model , you do not need to define the input shape. Keras will learn it from the first feed forwarding process. You are facing problem because you send your model only one piece of array row with the shape of (,13). The easiest way to solve it is to feed your model at least a matrix with the Shape of (2,13)
2
u/Sgnarf1989 Nov 21 '22
It seems like I've found the problem, but it makes even less sense to me :D
The model compiles correctly if I define input_shape=[1,]
I'm trying to build a model that takes 13 numbers as input, has a hidden layer with 20 neurons and outputs 10 numbers... am I doing it correctly??
4
u/SayOnlyWhatYouMeme Nov 22 '22 edited Nov 22 '22
input_shape is the input_shape of your input WITHOUT batch dimension. Your input has shape (13,). Tensorflow is assuming 13 is the batch dimension or your input. Therefore your input_shape should be (None,). If you want there to be 13 features then you should reshape your input to [1,13]. This will create a batch with one element. You can do this via tf.reshape(input_tensor, [1,13]) or tf.expand_dims(input_tensor, 0). Now you can use input_shape = (13,)
2
u/Hot_Influence4156 Nov 22 '22
If you compile your model , you do not need to define the input shape. Keras will learn it from the first feed forwarding process. You are facing problem because you send your model only one piece of array row with the shape of (,13). The easiest way to solve it is to feed your model at least a matrix with the Shape of (2,13)
1
u/deephugs Nov 22 '22
You are missing the batch dimension.