0

Here is the code I've run:

def fish_model():
    model = Sequential()
    from keras.layers import Activation, Dense
    from keras.layers.convolutional import Convolution2D
    from keras.layers.convolutional import MaxPooling2D
    from keras.layers import Dropout
    model.add(Convolution2D(filters=(6,3,3),input_shape=(256,768,1),activation='relu'))
    model.add(MaxPooling2D(pool_size=(2,2),strides=2))
    model.add(Convolution2D(filters=6, nb_row=3, nb_col=3,subsample=(2,2),
    input_shape=(256, 768, 1,), activation='relu', border_mode='same'))
    model.add(Dropout(0.1))
    model.add(Flatten())
    model.add(Dense(8, activation='softmax'))
    epochs = 5
    lrate = 0.1
    decay = lrate/epochs
    #sgd = SGD(lr=lrate, momentum=0.5, decay=decay, nesterov=False)
    model.compile(loss='categorical_crossentropy', optimizer='sgd', metrics=['categorical_accuracy'])
    return model

model= fish_model()
print(model.summary())
history = model.fit(X_train, Y_train, validation_data=(x_validation, y_validation), nb_epoch=6, batch_size=4)

I am getting the following error:

Traceback (most recent call last)
<ipython-input-28-bf6be1e3ca4c> in <module>
----> 1 model= fish_model()
      2 print(model.summary())
      3 history = model.fit(X_train, Y_train, validation_data=(x_validation, y_validation), nb_epoch=6, batch_size=4)

<ipython-input-26-634ceb657d80> in fish_model()
     23     from keras.layers.convolutional import MaxPooling2D
     24     from keras.layers import Dropout
---> 25     model.add(Convolution2D(filters=(6,3,3),input_shape=(256,768,1),activation='relu'))
     26     model.add(MaxPooling2D(pool_size=(2,2),strides=2))
     27     model.add(Convolution2D(filters=6, nb_row=3, nb_col=3,subsample=(2,2),

~\Anaconda3\lib\site-packages\keras\legacy\interfaces.py in wrapper(*args, **kwargs)
     89                 warnings.warn('Update your `' + object_name + '` call to the ' +
     90                               'Keras 2 API: ' + signature, stacklevel=2)
---> 91             return func(*args, **kwargs)
     92         wrapper._original_function = func
     93         return wrapper

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

Why am I getting an error in Convolution2D? How can I fix the code?

In the code above I added 2 Convolution2D calls. When I try to make it in single line I'm getting the error.

1 Answer 1

0

You are attempting to use the same parameters as for Conv2D. You should change the line to
model.add(Convolution2D(6,3,3,input_shape=(256,768,1),activation='relu'))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.