Keras 张量对象的I gor错误没有属性编译

Keras 张量对象的I gor错误没有属性编译,keras,model,tf.keras,Keras,Model,Tf.keras,这是基于keras tensorflow的模型 base_model = VGG16(include_top = False, input_shape=(32, 32, 3)) base_model.layers.pop() base_model.outputs = [base_model.layers[-1].output] last = base_model.outputs[0] x = ZeroPadding2D(padding=(1, 1))(last) x = Conv2D(filte

这是基于keras tensorflow的模型

base_model = VGG16(include_top = False, input_shape=(32, 32, 3))
base_model.layers.pop()
base_model.outputs = [base_model.layers[-1].output]
last = base_model.outputs[0]
x = ZeroPadding2D(padding=(1, 1))(last)
x = Conv2D(filters=1024, kernel_size=(3, 3), activation='relu')(x)
x = GlobalAveragePooling2D()(x)
model = Dense(10, activation='softmax')(x) ## nb_classes=5
然后我尝试编译它

model.compile(loss='categorical_crossentropy',
              optimizer=optimizer,
              metrics=['accuracy'])
然后出现以下错误

---->6模型编译(loss='classifical_crossentropy', 7优化器=优化器, 8个指标=[‘准确度’])

AttributeError:“Tensor”对象没有属性“compile”


只有一个模型实例有一个编译方法,您没有构建模型,这就是它出错的原因。了解如何使用KerasAPI创建模型