【问题标题】:Facing an error and I am not able to find any mistake面对错误,我找不到任何错误
【发布时间】:2021-09-27 09:54:49
【问题描述】:

ValueError: 函数模型的输出张量必须是 TensorFlow Layer 的输出(因此保存过去的层元数据)。找到:

import tensorflow.keras.layers as Layers
from tensorflow.keras.applications import VGG16


vgg = VGG16(
        include_top=False,
        weights="imagenet",
    #  input_shape = (224,224,3)
    # input_tensor = Layers.Input(shape = (224,224,3))
)
vgg.trainable = False

def create_model():

    inputs = Layers.Input(shape = (224,224,3))
    x = vgg(inputs)
    
    flatten = Layers.Flatten()(x)

    bbox = Layers.Dense(512, activation = 'relu')(flatten)
    bbox = Layers.Dropout(0.2)(bbox)
    bbox = Layers.Dense(64, activation = 'relu')(bbox)
    bbox = Layers.Dropout(0.2)(bbox)
    bbox_output = Layers.Dense(4, activation = 'sigmoid', name = 'bounding_box')

    classification = Layers.Dense(512,activation='relu')(flatten)
    classification = Layers.Dropout(0.5)(classification)
    classification = Layers.Dense(128, activation = 'relu')(classification)
    classification = Layers.Dropout(0.25)(classification)
    class_output = Layers.Dense(3, activation = 'softmax', name = 'class')(classification)

    model = tf.keras.Model(inputs = inputs, outputs = [class_output, bbox_output])
    return model

model = create_model()
model.summary()

【问题讨论】:

    标签: python tensorflow keras conv-neural-network


    【解决方案1】:

    我猜你忘记了为层 bbox_output 提供输入。 如果在图层末尾添加(bbox),它就可以了。

    bbox_output = Layers.Dense(4, activation = 'sigmoid', name = 'bounding_box')(bbox)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-24
      • 1970-01-01
      • 2018-12-09
      • 2012-02-07
      • 2021-07-01
      • 2012-12-29
      相关资源
      最近更新 更多