有没有一种方法可以在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代码。
谢谢。
发布于 2018-08-28 09:09:10
SSDMobileNetV1FeatureExtractor.extract_features从inspecting the code重定向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参数。不需要修剪构建的图形,只需构建图形直到您想要的端点。
https://stackoverflow.com/questions/52047963
复制相似问题