我建立了转移学习模型,并试图获得中间输出。我遵循建议here之一,以获取模型的中间输出,如下所示:
20G
但是我得到一个错误:
import tensorflow as tf
from tensorflow.keras import backend as K
tf.enable_eager_execution()
base_conv = tf.keras.applications.MobileNetV2(input_shape= None,
alpha=1.0, depth_multiplier=1, \
include_top=True, weights='imagenet', input_tensor=None, \
pooling=None, classes=1000)
model = tf.keras.models.Sequential()
model.add(base_conv)
model.add(tf.keras.layers.Dense(512, activation='relu'))
model.add(tf.keras.layers.Dense(5, activation='softmax'))
# with a Sequential model
get_layer_output = K.function([model.layers[0].input],
[model.layers[0].get_layer('Conv_1').output])
#x is the input image
layer_output = get_layer_output([x])