从Tensorflow 2.0中加载的保存的_模型访问中间层

从Tensorflow 2.0中加载的保存的_模型访问中间层,tensorflow,object-detection,tensorflow2.0,Tensorflow,Object Detection,Tensorflow2.0,在Tensorflow 2.0中使用SavedModels时,是否可以从中间层访问激活?例如,这里有一个模型:,我可以运行,例如 model = tf.saved_model.load('faster_rcnn_inception_v2_coco_2018_01_28/saved_model').signatures['serving_default'] outputs = model(input_tensor) 获取输出预测和边界框。我希望能够访问除输出之外的其他层,但似乎没有任何Tenso

在Tensorflow 2.0中使用SavedModels时,是否可以从中间层访问激活?例如,这里有一个模型:,我可以运行,例如

model = tf.saved_model.load('faster_rcnn_inception_v2_coco_2018_01_28/saved_model').signatures['serving_default']
outputs = model(input_tensor)

获取输出预测和边界框。我希望能够访问除输出之外的其他层,但似乎没有任何Tensorflow 2.0的文档说明如何做到这一点。下载的模型还包括检查点文件,但似乎没有很好的文档说明如何使用Tensorflow 2.0加载这些文件…

如果您使用Tensorflow 2.0生成保存的模型,则可以提取各个层。但是您所指的模型已经保存在TensorFlow 1.x中。使用TF1.x保存的模型,您无法单独提取层

下面是一个关于如何从TensorFlow 2.0中保存的模型中提取图层的示例

import tensorflow as tf
import numpy as np

model = tf.keras.Sequential([
    tf.keras.layers.Dense(64, activation='relu', input_shape=(100,)),
    tf.keras.layers.Dense(10, activation='relu'),
    tf.keras.layers.Dense(1, activation='sigmoid')
])

# Compile and fit the model

model.save('save_model', save_format='tf')
然后加载模型,如图所示

model = tf.keras.models.load_model('save_model')
layer1 = model.get_layer(index=1)

即使使用.pb和ckpt文件,也不可能获得图形定义?我认为首先不能在TF2.0中加载pb和检查点文件。