我想利用tensorflow2实现对图像特征的cnn提取,然后输出到支持向量机进行分类。好办法是什么?我已经检查了tensorflow2的文档,没有很好的解释。谁能指引我?
发布于 2019-12-29 18:22:23
感谢您对以上问题的澄清。我以前曾以书面答覆过类似的问题。但是,您可以通过使用所谓的tf.keras函数模型API构造辅助模型,从模型中提取中间层的输出。"Function“使用tf.keras.Model()。调用函数时,可以指定参数inputs和outputs。您可以在outputs参数中包含中间层的输出。请参阅下面的简单代码示例:
import tensorflow as tf
# This is the original model.
model = tf.keras.Sequential([
tf.keras.layers.Flatten(input_shape=[28, 28, 1]),
tf.keras.layers.Dense(100, activation="relu"),
tf.keras.layers.Dense(10, activation="softmax")])
# Make an auxiliary model that exposes the output from the intermediate layer
# of interest, which is the first Dense layer in this case.
aux_model = tf.keras.Model(inputs=model.inputs,
outputs=model.outputs + [model.layers[1].output])
# Access both the final and intermediate output of the original model
# by calling `aux_model.predict()`.
final_output, intermediate_layer_output = aux_model.predict(some_input)https://stackoverflow.com/questions/59504884
复制相似问题