__init__() missing 1 required positional argument: ‘units’ in CNN

I am trying to build a CNN for MNIST fashion, But not sure what is the issue here. I am getting thbis type error..

I have use Seuqential network,but MAxpooling and FLattena dn dense layers. But issue is in DEnse layer

model = Sequential() # type of DNN
model.add(Convolution2D(28, 3, 3, input_shape = (28, 28, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Flatten())
model.add(Dense(output_dim = 100, activation="relu"))   ##### 128 nodes in this layer
model.add(Dense(10, activation=tf.nn.softmax))

TypeError                                 Traceback (most recent call last)
<ipython-input-45-90929a8a33e8> in <module>
  3 model.add(MaxPooling2D(pool_size=(2,2)))
  4 model.add(Flatten())
 ----> 5 model.add(Dense(output_dim = 100,kernel_initializer='he_uniform', activation="relu"))   

  6 model.add(Dense(10, activation=tf.nn.softmax))




 TypeError: __init__() missing 1 required positional argument: 'units'

What seems to be the issue here?

Answer

From docs function definition of Dense is as such,

tf.keras.layers.Dense(
    units,
    activation=None,
    use_bias=True,
    kernel_initializer="glorot_uniform",
    bias_initializer="zeros",
    kernel_regularizer=None,
    bias_regularizer=None,
    activity_regularizer=None,
    kernel_constraint=None,
    bias_constraint=None,
    **kwargs
)

units is not an optional parameter. You seem to forget writing unit argument on first Dense call

Leave a Reply

Your email address will not be published. Required fields are marked *