0

In the book "Deep Learning with Python" by Francois Chollet, I found a piece of code which had input shape as 784 and units as 32?

I was wondering how they be can different.

Here's the exact piece of code:

from keras import layers
from keras import models
model = models.Sequential()
model.add(layers.Dense(32, input_shape = 784))
model.add(layers.Dense(32))
desertnaut
  • 57,590
  • 26
  • 140
  • 166
Sanskar Kumar
  • 363
  • 2
  • 5
  • 10

2 Answers2

1

Input_shape is a shape of the Dense layer input. Units - is a shape of the Dense layer output. Basically - they are two different dimensions of the weights matrix.

Andrey
  • 5,932
  • 3
  • 17
  • 35
0

Although you cannot set the input shape dynamically in a Dense layer, because the weight dimension will be effected by the input neuron number, Conv2D layers can have an input shape such as (None, None, 3). This is possible because the parameter of convolutional layers are kernels of fixed size, that aren't effected by the input shape. This is how we can use pretrained imagenet models for computer vision tasks of various image sizes.

krenerd
  • 741
  • 4
  • 22