首页 > 解决方案 > 如何在 TCAV 中加载对象检测模型?

问题描述

我现在为TCAV使用并创建了Keras 的包装器,并且我正在努力为对象检测创建一个包装器。但我无法加载模型。模型已加载,但它是一个空壳,特征提取器之类的块是空的,或者说模型没有构建。这是我的包装的片段

import os
from object_detection.utils import config_util
from object_detection.builders import model_builder
class KerasModelWrapperSSD(ModelWrapper):
    
    
      def __init__(
          self,
          sess,
          model_path,
          labels_path,
      ):
        self.sess = sess
        super(KerasModelWrapperSSD, self).__init__()
        self.import_keras_model(model_path)
        self.labels = tf.io.gfile.GFile(labels_path).read().splitlines()
    
        self._make_gradient_tensors()
        def import_keras_model(self, saved_path):
            """Loads keras model, fetching bottlenecks, inputs and outputs."""
            self.ends = {}
            PATH_TO_CFG=model_path + "pipeline.config"
            PATH_TO_CHECKPOINT = model_path + "checkpoint"
            configs_model = config_util.get_configs_from_pipeline_file(PATH_TO_CFG)
            model_config = configs_model['model']
            detection_model = model_builder.build(model_config=model_config, is_training=False)
            checkpoint_restore = tf.compat.v2.train.Checkpoint(model=detection_model)
            checkpoint_restore.restore(os.path.join(PATH_TO_CHECKPOINT, 'ckpt-0')).expect_partial()
            self.model=detection_moodel
            print(self.model.feature_extractor.classification_backbone)
            print(self.model.feature_extractor.classification_backbone.summary())

输出:

[]
ValueError: This model has not yet been built. Build the model first by calling `build()` or calling `fit()` with some data, or specify an `input_shape` argument in the first layer(s) for automatic build.

如果我在另一个不是的脚本上运行相同的脚本,TCAV 工作得非常好。欢迎任何帮助或指导。提前致谢

标签: tensorflowtensorflow2.0object-detection

解决方案


推荐阅读