Tensorflow + Keras + Convolution2d:TypeError:' int'对象不可调用

时间:2016-11-23 02:27:16

标签: python tensorflow keras keras-layer

我在我的机器上运行有关CNN的代码,但它收到了ERROR反馈。

我的代码片段:

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

我也尝试:

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

和错误是:


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

如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我想也许你对tensorflow的语法感到困惑。

您的陈述中有一些拼写错误model.add(Convolution2D(4 ,3 ,5, 5, border_mode='valid' ,input_shape=(200,200,3)))

如果您想要4个尺寸为5x5的过滤器,请尝试 model.add(Convolution2D(4 ,5, 5, border_mode='valid' ,input_shape=(200,200,3)))