0

我正在尝试制作一个具有两个输出的模型,一个用于分类,另一个用于回归。我使用来自 Keras 的预训练 VGG16 作为卷积特征提取器。但是当我尝试在两个输出序列中构建下一个展平层时,我得到输入不是张量的错误。如何确保仅将卷积基础的最后一层作为输入提供给下一层?

conv_base = VGG16(include_top = False,
                  weights = 'imagenet')
conv_base.trainable = False
with tf.variable_scope('classification_head', reuse=tf.AUTO_REUSE):
    x = Flatten()(conv_base.layers[-1])
    x = Dense()(x)

错误 :

ValueError:使用不是符号张量的输入调用了层 flatten_1。接收类型:类 'keras.layers.pooling.MaxPooling2D'。完整输入:[keras.layers.pooling.MaxPooling2D object at 0xc2855c9b0]。该层的所有输入都应该是张量。

4

1 回答 1

0

得到所需的张量为:

features = conv_base.output 
print(features)

张量("block5_pool/MaxPool:0", shape=(?, 11, 14, 512), dtype=float32)

于 2019-04-27T11:34:55.657 回答