执行以下用于图像分类的Python代码时出现以下错误。
from keras.models import Sequential
from keras.layers import Conv2D
from keras.layers import MaxPooling2D
from keras.layers import Flatten
from keras.layers import Dense
# Initialising the CNN
classifier = Sequential()
# Step 1 - Convolution
classifier.add(Conv2D(32, (3, 3), input_shape = (64, 64, 3), activation = 'relu'))
当我在这里执行第1步时,我收到以下错误。
Traceback (most recent call last):
File "<ipython-input-230-373aa5a74134>", line 1, in <module>
classifier.add(Conv2D(32, (3, 3), input_shape = (64, 64, 3), activation = 'relu'))
File "C:\Users\naveenn\AppData\Local\Continuum\anaconda3\lib\site-packages\keras\models.py", line 467, in add
layer(x)
File "C:\Users\naveenn\AppData\Local\Continuum\anaconda3\lib\site-packages\keras\engine\topology.py", line 575, in __call__
self.assert_input_compatibility(inputs)
File "C:\Users\naveenn\AppData\Local\Continuum\anaconda3\lib\site-packages\keras\engine\topology.py", line 448, in assert_input_compatibility
str(inputs) + '. All inputs to the layer '
ValueError: Layer conv2d_55 was called with an input that isn't a symbolic tensor. Received type: <class 'tensorflow.python.framework.ops.Tensor'>. Full input: [<tf.Tensor 'conv2d_55_input:0' shape=(?, 64, 64, 3) dtype=float32>]. All inputs to the layer should be tensors.
如果我在classifier.add()
中运行代码,它对我来说工作正常,并且不会返回任何错误。我在下面提到的代码
A = Conv2D(32, (3, 3), input_shape = (64, 64, 3), activation = 'relu')
这里我使用的是keras 2.1.5和tensorflow 1.2.1