【问题标题】:what does "conv_base.output" and "conv_base.input" mean or do in this code?“conv_base.output”和“conv_base.input”在这段代码中是什么意思或做什么?
【发布时间】:2020-12-23 14:03:32
【问题描述】:
conv_base = Xception(include_top=False, input_tensor=None,
pooling=None, input_shape=(TARGET_SIZE, TARGET_SIZE, 3), classifier_activation='softmax')
                           
model = conv_base.output
model = layers.GlobalAveragePooling2D()(model)
model = layers.Dense(5, activation = "softmax")(model)
model = models.Model(conv_base.input, model)

model.compile(optimizer = Adam(lr = 0.001),
              loss = "sparse_categorical_crossentropy",
              metrics = ["acc"])

谁能解释一下这段代码中conv_base.outputconv_base.input 的含义?它是做什么用的,有什么作用??

【问题讨论】:

标签: python tensorflow machine-learning keras conv-neural-network


【解决方案1】:

tf.keras.models.Model 需要 inputsoutputs 作为参数:

参数: 输入:模型的输入:keras.Input 对象或列表 keras.Input 对象。 输出:模型的输出。请参阅下面的功能 API 示例。 name:字符串,模型的名称。

在 Keras 模型中,model.inputmodel.output 返回输入/输出张量,您可以将其作为新模型的输入/输出传递:

from tensorflow.keras.applications.vgg19 import VGG19

base_model = VGG19(weights=None)

print(base_model.input)
Tensor("input_2:0", shape=(None, 224, 224, 3), dtype=float32)

请注意,调用这些层会返回张量,而不是模型,因此您似乎错误地分配了变量名称。相反,请使用以下内容:

model_output = conv_base.output
layer_output = layers.GlobalAveragePooling2D()(model_output)
final_model_output = layers.Dense(5, activation = "softmax")(layer_output)
model = models.Model(conv_base.input, final_model_output)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多