0

I am using TensorFlow with Keras for pattern recognition.

My input data is a 32*32 pixel binary image and the output is 4 classes.

I created model as follow

model = models.Sequential()
model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32,1)))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.Flatten())
model.add(layers.Dense(32, activation='relu'))
model.add(layers.Dense(4))

but when I try to show the model summary I get

Model: "sequential"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d (Conv2D)              (None, 30, 30, 32)        320       
_________________________________________________________________
max_pooling2d (MaxPooling2D) (None, 15, 15, 32)        0         
_________________________________________________________________
conv2d_1 (Conv2D)            (None, 13, 13, 64)        18496     
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 6, 6, 64)          0         
_________________________________________________________________
conv2d_2 (Conv2D)            (None, 4, 4, 64)          36928     
_________________________________________________________________
flatten (Flatten)            (None, 1024)              0         
_________________________________________________________________
dense (Dense)                (None, 32)                32800     
_________________________________________________________________
dense_1 (Dense)              (None, 4)                 132       
=================================================================

enter image description here

my question is what is the meaning of "?" & "None" in layer dimensions

Hossam Alzomor
  • 149
  • 1
  • 10

2 Answers2

3

In 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.

Elements in convolution layer represent in this order batchSize, height, width, channels

? and None are placeholders for batch size.

bsquare
  • 943
  • 5
  • 10
2

In your case, the batch size will only be known when you call fit, so, when you define the model, TF still doesn't know the batch size.

? and None are thus placeholders for the batch size.

nbro
  • 15,395
  • 32
  • 113
  • 196