Keras: Conv2D TypeError: __init()__ takes at least 4 arguments (4 given)

Created on 21 Mar 2017  Â·  7Comments  Â·  Source: keras-team/keras

I am learning to use Keras's Functional API . I tried running one of code snippet (ex: inception module ) from the documentation (https://keras.io/getting-started/functional-api-guide/). I get the above mentioned error. I tried running other code snippets as well from the documentation. I get same error for each one.


Inception Module code snippet from the docs:

from keras.layers import Conv2D, MaxPooling2D, Input

input_img = Input(shape=(256, 256,3))

tower_1 = Conv2D(64, (1, 1), padding='same', activation='relu')(input_img)
tower_1 = Conv2D(64, (3, 3), padding='same', activation='relu')(tower_1)

tower_2 = Conv2D(64, (1, 1), padding='same', activation='relu')(input_img)
tower_2 = Conv2D(64, (5, 5), padding='same', activation='relu')(tower_2)

tower_3 = MaxPooling2D((3, 3), strides=(1, 1), padding='same')(input_img)
tower_3 = Conv2D(64, (1, 1), padding='same', activation='relu')(tower_3)

output = keras.layers.concatenate([tower_1, tower_2, tower_3], axis=1)

I am trying to use Conv2D as the first layer in functional API setting. Can anyone please provide me some suggestion on how to resolve this issue?

Thank you.

Ankit Sharma.

Most helpful comment

Have you checked your keras version?

Consider upgrading as the API call has been changed.

sudo pip install --upgrade keras

All 7 comments

Have you checked your keras version?

Consider upgrading as the API call has been changed.

sudo pip install --upgrade keras

@ramanb25: I did the same few hours back. The issue got resolved. Thank you for your suggestion.

I have the same problem as you, could you tell me how to solve this issue? Thanks

@ramanb25 Where do I type that command? I'm using a Jupyter notebook on AWS. In my shell, I shut down the notebook in order to access my ubuntu command line (while ssh'ed into the AWS server) and typed that line, but it said "sudo: pip: command not found". Thanks.

x1 = Conv2D(16, (4, 4), strides=(2, 2), activation='relu')(input_1)
TypeError: __init__() takes at least 4 arguments (4 given)
This is the error I'm getting, I tried upgrading keras and tensorflow versions but nothing seems to be effective. Please give me some solution

@SabariRaaj Me too!Could you tell me how to solve this issue?

@SabariRaaj Me too!Could you tell me how to solve this issue?

@brotheryun Bro just use the following versions, keras 2.1.5 and tensorflow 1.5.0. only these versions matched perfectly and solved my issue. These versions are for python 3.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fredtcaroli picture fredtcaroli  Â·  3Comments

MarkVdBergh picture MarkVdBergh  Â·  3Comments

LuCeHe picture LuCeHe  Â·  3Comments

Imorton-zd picture Imorton-zd  Â·  3Comments

amityaffliction picture amityaffliction  Â·  3Comments