9

Is this telling the model that there are two dimensions (i.e. it’s a matrix) but we don’t yet know the size of that particular dimension? If so, how can the model be compiled? Doesn’t the size of each dimension affect the number of nodes in middle layers?

pcko1
  • 4,030
  • 2
  • 17
  • 30
Nic Cottrell
  • 303
  • 1
  • 2
  • 10

2 Answers2

12

In tf.keras, a None dimension means that it can be any scalar number, so that you use this model to infer on an arbitrarily long input. This dimension does not affect the size of the network, it just denotes that you are free to select the length (number of samples) of your input during testing.

pcko1
  • 4,030
  • 2
  • 17
  • 30
3

You are almost right. However, in your specific examples (None,) and (None,12), we actually do know the size of the model's input and that's why the model can be compiled. (None,) refers to scalar inputs and (None,12) refers to 12-dimensional input vectors. Therefore, one can think of None as an adjustable variable/placeholder for the batch size of your model's optimization algorithm.

A more specific example: if the batch-size during model optimization/training is 32, then None will take one the value 32 and your model's input will be of size (32,12).