Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (17.6k points)

When I try to make a convolutional neural network in keras and when I want to check my model I got this error :

init() missing 1 required positional argument: 'units'

the keras version that I am using is version 2.2.4

this is the model :

input_shape = (224, 224, 1)

model = Sequential()

model.add(Conv2D(16, kernel_size=(5, 5), strides=2, padding='same', activation='relu', input_shape=input_shape))

model.add(MaxPooling2D(pool_size=(2, 2)))

model.add(Conv2D(32, kernel_size=(5, 5), strides=1, padding='same', activation='relu'))

model.add(MaxPooling2D(pool_size=(4, 4)))

model.add(Conv2D(64, kernel_size=(5, 5), strides=1, padding='same', activation='relu'))

model.add(MaxPooling2D(pool_size=(4, 4)))

model.add(Flatten())

model.add(Dense(1024, activation='relu'))

model.add(Dense(activation='linear'))

model.compile(loss='mse',

              optimizer='adam')

model.summary()

and the error is:

init() missing 1 required positional argument: 'units'

1 Answer

0 votes
by (17.6k points)

The last line is generating the error:

model.add(Dense(activation='linear'))

Size of the Dense layer should be specified:

model.add(Dense(1024, activation='relu'))

model.add(Dense(NEWSIZE, activation='linear'))

#Here, NEWSIZE is the number of units you want

You can also do this :

model.add(Dense(1024, activation='relu'))

model.add(Activation('linear'))

Browse Categories

...