【问题标题】:KeyError: Frozen Tensorflow Model to UFF graphKeyError:冻结张量流模型到 UFF 图
【发布时间】:2018-07-15 21:19:18
【问题描述】:

我已经使用 Tensorflow Estimator API 训练了一个自定义 CNN 模型。我已成功冻结图表,但转换为 UFF 失败并引发以下错误:

'KeyError: u'IteratorGetNext:1'

进行上述转换的代码:

frozen_graph_filename = "Frozen_model.pb"
TMP_UFF_FILENAME = "output.uff"
output_name = "sigmoid"

uff_model = uff.from_tensorflow_frozen_model(
    frozen_file=frozen_graph_filename,
    output_nodes=[output_name],
    output_filename=TMP_UFF_FILENAME,
    text=False,
)

图中节点的名称是,

prefix/OneShotIterator
prefix/IteratorGetNext
prefix/Reshape/shape
prefix/Reshape
prefix/Reshape_1/shape
prefix/Reshape_1
prefix/conv1/kernel
prefix/conv1/bias
.
.
.
prefix/logits/MatMul
prefix/logits/BiasAdd
prefix/sigmoid

那么有没有办法删除前两个 Iterator 节点?它们在训练环境之外毫无用处。我也使用过tf.graph_util.remove_training_nodes,但它并不能缓解我面临的问题。

【问题讨论】:

    标签: python tensorflow protocol-buffers tensorrt


    【解决方案1】:

    Graph Transform Tool 可以用来完成我想要实现的目标,以便能够使用该工具来克隆 tensorflow 存储库并运行配置文件以设置工作空间。按照1 中提供的说明构建工具。 完成后调用该工具,

    bazel-bin/tensorflow/tools/graph_transforms/transform_graph \
    --in_graph=tensorflow_inception_graph.pb \
    --out_graph=optimized_inception_graph.pb \
    --inputs='Mul:0' \
    --outputs='softmax:0' \
    --transforms='
    strip_unused_nodes(type=float, shape="1,299,299,3")
    remove_nodes(op=Identity, op=CheckNumerics)
    fold_old_batch_norms
    '
    

    一旦你有优化的图形将它传递给

    uff.from_tensorflow_frozen()
    

    https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/graph_transforms/README.md1 https://www.tensorflow.org/mobile/prepare_models#how_do_you_get_a_model_you_can_use_on_mobile

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-18
      • 1970-01-01
      • 2018-10-11
      • 1970-01-01
      • 2018-11-17
      • 2018-11-25
      • 2017-11-22
      • 1970-01-01
      相关资源
      最近更新 更多