Search code examples
pythontensorflowkeraskeras-layer

Tensorflow + Keras + Convolution2d: TypeError: 'int' object is not callable


I run the code about CNN in my machine, but it got an ERROR feedback.

The snippet of my code:

model.add(Convolution2D(4 ,3 ,5, 5, border_mode='valid' ,input_shape=(200,200,3))) 

and I also try:

model.add(Convolution2D(4 ,3 ,5, 5, border_mode='valid' ,input_shape=(3,200,200))) 

and the ERROR are:


Traceback (most recent call last):
  File "", line 1, in 
  File "/Users/liumengyang/anaconda/lib/python3.5/site-packages/spyder/utils/site/sitecustomize.py", line 866, in runfile
    execfile(filename, namespace)
  File "/Users/liumengyang/anaconda/lib/python3.5/site-packages/spyder/utils/site/sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)
  File "/Users/liumengyang/Desktop/visual/pre-processing.py", line 61, in 
    model.add(Convolution2D(4 ,3 ,5, 5, border_mode='valid' ,input_shape=(200,200,3))) 
  File "/Users/liumengyang/anaconda/lib/python3.5/site-packages/keras/models.py", line 280, in add
    layer.create_input_layer(batch_input_shape, input_dtype)
  File "/Users/liumengyang/anaconda/lib/python3.5/site-packages/keras/engine/topology.py", line 370, in create_input_layer
    self(x)
  File "/Users/liumengyang/anaconda/lib/python3.5/site-packages/keras/engine/topology.py", line 487, in __call__
    self.build(input_shapes[0])
  File "/Users/liumengyang/anaconda/lib/python3.5/site-packages/keras/layers/convolutional.py", line 410, in build
    self.W = self.init(self.W_shape, name='{}_W'.format(self.name))
TypeError: 'int' object is not callable

How to solve this problem?


Solution

  • I think maybe you are confused with the syntax of tensorflow.

    There is some typo in your statement,model.add(Convolution2D(4 ,3 ,5, 5, border_mode='valid' ,input_shape=(200,200,3))),

    Try this model.add(Convolution2D(4 ,5, 5, border_mode='valid' ,input_shape=(200,200,3))) if your want to have 4 filters which size is 5x5.