如何在Tensorflow检测模型上使用清晰的可解释性工具?

如何在Tensorflow检测模型上使用清晰的可解释性工具?,tensorflow,machine-learning,object-detection,object-detection-api,lucid,Tensorflow,Machine Learning,Object Detection,Object Detection Api,Lucid,我想用它来分析我在自己的数据集上使用tensorflow对象检测API训练的检测模型的特征提取。所使用的模型来自,即faster\u rcnn\u resnet101 我按照导入我自己的模型的步骤,保存了一个冻结的模型图,该图的节点为/all\u class\u predictions\u,背景为output\u节点 我很难找到图形的输入节点来运行Lucid 此外,我真的认为我没有正确的方法。也许我应该首先提取检测模型的所有分类部分,并在转到Lucid之前冻结一个只有这部分的新图形 或者我应该导

我想用它来分析我在自己的数据集上使用tensorflow对象检测API训练的检测模型的特征提取。所使用的模型来自,即
faster\u rcnn\u resnet101

我按照导入我自己的模型的步骤,保存了一个冻结的模型图,该图的节点为
/all\u class\u predictions\u,背景为
output\u节点

我很难找到图形的输入节点来运行Lucid

此外,我真的认为我没有正确的方法。也许我应该首先提取检测模型的所有分类部分,并在转到Lucid之前冻结一个只有这部分的新图形

或者我应该导入一个
resnet_101
分类模型,然后从检测模型复制/粘贴正确的权重

但我真的不知道怎么做那种事


有人能帮我吗?我真的想尝试在我的检测网络上运行Lucid。

是的,您应该导出一个推理(冻结)图以在Lucid中使用

我使用以下脚本从培训检查点文件导出一个图形。 有关导出文件中节点的有用信息将记录到控制台

training_model="ssd_mnet_v2_ppn_512x288.config"

model_signature="eb_13_v09_ppmn2_13_256_adam_512x288_tf_1.14_200k"

# the specific checkpoint to export from
checkpoint_path="/TRAIN/models/model/train/model.ckpt-200000"

# directory to export into
output_path="/XYZ/graphs/${model_signature}"

# ensure these graph nodes are exported, and everything in between
additional_output_tensor_names="Preprocessor/sub,concat_1"

# 
python export_inference_graph.py \
   --input_type=image_tensor \
   --pipeline_config_path /TRAIN/models/model/$training_model \
   --trained_checkpoint_prefix=$checkpoint_path \
   --output_directory=$output_path \
   --additional_output_tensor_names=$additional_output_tensor_names
在回顾了Lucid Model zoo中的示例之后,我发现创建自己的Lucid Model类很方便。 您必须仔细检查图形,因为您需要指定输入节点,并提供Lucid可以使用的层列表

from lucid.modelzoo.vision_base import Model, _layers_from_list_of_dicts


# the input node "Preprocessor/sub" is appropriate for image injection
class SSD_Mnet2_PPN( Model ):

    def __init__(self, image_shape=None, graph_path=None, labels_path=None ):        
        self.model_path = graph_path
        self.labels_path = labels_path

        self.image_shape = image_shape
        self.image_value_range = (-1, 1) 
        self.input_name = "Preprocessor/sub"

        super().__init__()

# a hand-crafted list of layers - by inspection of the graph
SSD_Mnet2_PPN.layers = _layers_from_list_of_dicts(SSD_Mnet2_PPN, [
  { 'id':  0, 'tags': ['conv'], 'name': 'FeatureExtractor/MobilenetV2/expanded_conv_2/add', 'depth': 24, 'shape': [ 1, 72, 128, 24 ], 'transform_id': 2 },  
  { 'id':  2, 'tags': ['conv'], 'name': 'FeatureExtractor/MobilenetV2/expanded_conv_5/add', 'depth': 32, 'shape': [ 1, 36, 64, 32 ], 'transform_id': 2 },  
  { 'id':  5, 'tags': ['conv'], 'name': 'FeatureExtractor/MobilenetV2/expanded_conv_9/add', 'depth': 64, 'shape': [ 1, 18, 32, 64 ], 'transform_id': 2 },  
  { 'id':  7, 'tags': ['conv'], 'name': 'FeatureExtractor/MobilenetV2/expanded_conv_12/add', 'depth': 96, 'shape': [ 1, 18, 32, 96 ], 'transform_id': 2 },  
  { 'id':  9, 'tags': ['conv'], 'name': 'FeatureExtractor/MobilenetV2/expanded_conv_15/add', 'depth': 160, 'shape': [ 1, 9, 16, 160 ], 'transform_id': 2 },  
  { 'id': 11, 'tags': ['concat'], 'name': 'concat_1', 'depth': 13, 'shape': [ 1, 1212, 13 ], 'transform_id': 4 },
])


def model_for_version( version=None, path=None ):

    if "320x180" in version:
        return SSD_Mnet2_PPN( graph_path=path, image_shape=[ 320, 180, 3 ] )

    if "480x270" in version:
        return SSD_Mnet2_PPN( graph_path=path, image_shape=[ 480, 270, 3 ] )

    if "512x288" in version:
        return SSD_Mnet2_PPN( graph_path=path, image_shape=[ 512, 288, 3 ] )        

    if "720x405" in version:
        return SSD_Mnet2_PPN( graph_path=path, image_shape=[ 720, 405, 3 ] )

    raise ValueError( "No model for graph_version: {}".format( version ) )
然后您可以编写如下代码:

from lucid.optvis import render

model = model_for_version( 
    version = "eb_13_v09_ppmn2_13_256_adam_512x288_tf_1.14", 
    path = "/XYZ/graphs/eb_13_v09_ppmn2_13_256_adam_512x288_tf_1.14_200k/frozen_inference_graph.pb" 
)

model.load_graphdef()

_ = render.render_vis( model, "FeatureExtractor/MobilenetV2/expanded_conv_15/add:17", thresholds=( 32, 256, 1024 ) )    
不可避免地,我们必须进行大量的实验