Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of the "None" in model.summary of KERAS?

enter image description here

What is the meaning of the (None, 100) in Output Shape? Is this("None") the Sample number or the hidden dimension?

like image 933
jung hyemin Avatar asked Nov 11 '17 16:11

jung hyemin


People also ask

What does none shape mean?

A None value in the shape of a tensor means that the tensor can be of any size (large than or equal to 1) in that dimension.

What is model summary keras?

Summarize ModelKeras provides a way to summarize a model. The summary is textual and includes information about: The layers and their order in the model. The output shape of each layer. The number of parameters (weights) in each layer.

How does keras define input shape?

The input shape In Keras, the input layer itself is not a layer, but a tensor. It's the starting tensor you send to the first hidden layer. This tensor must have the same shape as your training data. Example: if you have 30 images of 50x50 pixels in RGB (3 channels), the shape of your input data is (30,50,50,3) .


2 Answers

None means this dimension is variable.

The first dimension in a keras model is always the batch size. You don't need fixed batch sizes, unless in very specific cases (for instance, when working with stateful=True LSTM layers).

That's why this dimension is often ignored when you define your model. For instance, when you define input_shape=(100,200), actually you're ignoring the batch size and defining the shape of "each sample". Internally the shape will be (None, 100, 200), allowing a variable batch size, each sample in the batch having the shape (100,200).

The batch size will be then automatically defined in the fit or predict methods.


Other None dimensions:

Not only the batch dimension can be None, but many others as well.

For instance, in a 2D convolutional network, where the expected input is (batchSize, height, width, channels), you can have shapes like (None, None, None, 3), allowing variable image sizes.

In recurrent networks and in 1D convolutions, you can also make the length/timesteps dimension variable, with shapes like (None, None, featuresOrChannels)

like image 132
Daniel Möller Avatar answered Nov 11 '22 08:11

Daniel Möller


Yes, None in summary means a dynamic dimension of a batch (mini batch). This is why you can set any batch size to your model.

The summary() method is part of TF that incorporates Keras method print_summary().

like image 22
prosti Avatar answered Nov 11 '22 09:11

prosti