【发布时间】: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