Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keras | TypeError: __init__() missing 1 required positional argument: 'nb_col'

Tags:

python

keras

I am currently trying to implement this tutorial code into my own convnet.py but I get an error. Tutorial

This is the full error:

Traceback (most recent call last):
    File "convnet.py", line 6, in <module>
        model.add(Conv2D(32, (3, 3), input_shape=(3, 150, 150)))
TypeError: __init__() missing 1 required positional argument: 'nb_col'

Here are the first 10 lines on which the program goes wrong:

from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D
from keras.layers import Activation, Dropout, Flatten, Dense

model = Sequential()
model.add(Conv2D(32, (3, 3), input_shape=(3, 150, 150)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))

The code is located in the file convnet.py and I run the file like this: python convnet.py

like image 415
Gertjan Brouwer Avatar asked Mar 22 '17 09:03

Gertjan Brouwer


1 Answers

You are probably using an old version of Keras that had the following signature:

Conv2D(self, nb_filter, nb_row, nb_col, ...)

With this old version, you would define the conv layer as:

model.add(Conv2D(32, 3, 3, input_shape=(3, 150, 150)))

You can check the version you are using with:

import keras
print(keras.__version__)

I suggest that you update your Keras.

like image 177
Fábio Perez Avatar answered Sep 22 '22 04:09

Fábio Perez