Python 3.x 如何使用异常体系结构

Python 3.x 如何使用异常体系结构,python-3.x,keras,convolutional-neural-network,Python 3.x,Keras,Convolutional Neural Network,我想使用异常模型对图像进行分类,但我得到了一个值错误 xception=keras.applications.xception.Xception(include_top=False,input_shape=(71,71,3)) classifier=Sequential() for layer in xception.layers: classifier.add(layer) 我犯了这个错误 ValueError: Input 0 is incompatible with layer

我想使用异常模型对图像进行分类,但我得到了一个值错误

xception=keras.applications.xception.Xception(include_top=False,input_shape=(71,71,3))
classifier=Sequential()
for layer in xception.layers:
    classifier.add(layer)
我犯了这个错误

ValueError: Input 0 is incompatible with layer conv2d_1: expected axis -1 of input shape to have value 64 but got shape (None, 33, 33, 128)

我在使用resnet时也会遇到这个错误。但我在使用vgg16或vgg19时不会遇到。有人能告诉我如何使用它吗???

您可以使用函数API。下面是一个可能的分类器示例

#Base model Xception
xception=keras.applications.xception.Xception(include_top=False,input_shape=(71,71,3))

# Input of your model
input=Input(shape=(71,71,3))
# Add the inception base model to your model
y=xception(input)
    .

    .
# Other layers by passing previous output  
y=Dense(...)(y)
# Define model
model=Model(input,y)

我不知道为什么我们会这样,但是你可以使用函数api来避免这个错误。你能说一下使用函数api意味着什么吗?检查answerinput\u tensor=Inputshape=71,71,3 xception=keras.applications.xception.xception包括\u top=False,输入张量=输入张量。这很有效。哈哈,我刚刚写了同样的东西。我们不需要展平它。怎么做?这是一种方法。全球平均池2D和展平是相同的还是不同的?它们是不同的