1

有没有办法在 Tensorflow 中加载预训练模型并删除网络中的顶层?我正在查看 Tensorflow 版本 r1.10

我能找到的唯一文档是tf.keras.Sequential.pop https://www.tensorflow.org/versions/r1.10/api_docs/python/tf/keras/Sequential#pop

我想通过删除一堆顶部卷积层并添加一个自定义的完全卷积层来手动修剪一个预训练的网络。

编辑:

该模型是从Tensorflow Model Zoo下载的 ssd_mobilenet_v1_coco 。我可以访问 freeze_inference_graph.pb 模型文件和检查点文件。

我无权访问用于构建模型的 python 代码。

谢谢。

4

1 回答 1

1

通过检查代码SSDMobileNetV1FeatureExtractor.extract_features重定向research.slim.nets

  from nets import mobilenet_v1  # nets will have to be on your PYTHONPATH

with tf.variable_scope('MobilenetV1',
                       reuse=self._reuse_weights) as scope:
  with slim.arg_scope(
      mobilenet_v1.mobilenet_v1_arg_scope(
          is_training=None, regularize_depthwise=True)):
    with (slim.arg_scope(self._conv_hyperparams_fn())
          if self._override_base_feature_extractor_hyperparams
          else context_manager.IdentityContextManager()):
      _, image_features = mobilenet_v1.mobilenet_v1_base(
          ops.pad_to_multiple(preprocessed_inputs, self._pad_to_multiple),
          final_endpoint='Conv2d_13_pointwise',
          min_depth=self._min_depth,
          depth_multiplier=self._depth_multiplier,
          use_explicit_padding=self._use_explicit_padding,
          scope=scope)

mobilenet_v1_base函数接受一个final_endpoint参数。与其修剪构造的图,不如构造图直到您想要的端点。

于 2018-08-28T01:09:10.070 回答