首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tensorflow从预训练模型中删除层

Tensorflow从预训练模型中删除层
EN

Stack Overflow用户
提问于 2018-08-28 06:57:42
回答 1查看 2.7K关注 0票数 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。我可以访问frozen_inference_graph.pb模型文件和检查点文件。

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

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2018-08-28 09:09:10

SSDMobileNetV1FeatureExtractor.extract_featuresinspecting the code重定向research.slim.nets

代码语言:javascript
复制
  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参数。不需要修剪构建的图形,只需构建图形直到您想要的端点。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52047963

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档