【问题标题】:OpenVino: how to add support to FusedBatchNormV3 in model optimizer?OpenVino:如何在模型优化器中添加对 FusedBatchNormV3 的支持?
【发布时间】:2020-01-19 14:20:39
【问题描述】:

我正在尝试了解如何在 OpenVino 的模型优化器中添加对 TensorFlow 层 FusedBatchNormV3 的支持。我在 Ubuntu 18.03 上运行并使用 Tensorflow 15。

我的目标是在神经计算机棒 2 上使用一些预先训练的标准网络进行几次测试,我现在正在使用 ResNet50。我下载的网络如下:

import tensorflow as tf
keras = tf.keras

input_shape = (200,200,3)
model = keras.applications.resnet50.ResNet50(input_shape=input_shape,
                                              include_top=False, 
                                              weights='imagenet')

在我按照this post 中的描述冻结model 之后。

我正在使用以下命令运行模型优化器:

sudo python3 mo.py \
--input_model ~<PATH_TO_MODEL>/model.pb \
--output_dir ~<PATH_TO_MODEL> \
--data_type FP16 -b 1

但我收到此错误消息:

[ ERROR ]  1 elements of 64 were clipped to infinity while converting a blob for node [['conv1_bn_1/cond/FusedBatchNormV3_1/ReadVariableOp_1/Output_0/Data__const']] to <class 'numpy.float16'>. 
 For more information please refer to Model Optimizer FAQ (https://docs.openvinotoolkit.org/latest/_docs_MO_DG_prepare_model_Model_Optimizer_FAQ.html), question #76. 
[ ERROR ]  List of operations that cannot be converted to Inference Engine IR:
[ ERROR ]      FusedBatchNormV3 (53)
[ ERROR ]          conv1_bn_1/cond/FusedBatchNormV3_1
[ ERROR ]          conv2_block1_0_bn_1/cond/FusedBatchNormV3_1
[ ERROR ]          conv2_block1_1_bn_2/cond/FusedBatchNormV3_1
...
[ ERROR ]          conv5_block3_3_bn_1/cond/FusedBatchNormV3_1
[ ERROR ]  Part of the nodes was not converted to IR. Stopped.

我发现 this forum post 建议将 TensorFlow 降级到版本 13,但这样做之后我也遇到了同一层的另一个错误:

[ ERROR ]  Cannot infer shapes or values for node "conv1_bn_1/cond/FusedBatchNormV3_1".
[ ERROR ]  Op type not registered 'FusedBatchNormV3' in binary running on <USER>. Make sure the Op and Kernel are registered in the binary running in this process. Note that if you are loading a saved graph which used ops from tf.contrib, accessing (e.g.) `tf.contrib.resampler` should be done before importing the graph, as contrib ops are lazily registered when the module is first accessed.

我目前的想法是通过使用模型优化器中引入的 Sub-Graph 替换来添加对 FusedBatchNormV3 的支持(在this official page 中描述)。我想用ScaleShift 操作替换函数FusedBatchNormV3,因为据说here FusedBatchNorm 与之关联,但我不知道如何找到这个ScaleShift 对象。有人可以帮帮我吗?

【问题讨论】:

    标签: python tensorflow openvino


    【解决方案1】:

    很遗憾,我无法在更换机制方面提供帮助,但我还有另一件事可以提供帮助。

    根据https://github.com/opencv/dldt/issues/352 的评论,您可以假装 FusedBatchNormV3 的行为方式与 FusedBatchNorm 相同,并且不会导致准确性下降。

    我为模型优化器添加了一个补丁,它实现了上述行为。请检查一下: https://github.com/ArtemSkrebkov/dldt/tree/askrebko/treat_bnv3_as_bn

    我检查了生成的 IR 的推理结果(使用一张图片),我得到了与 Keras 模型给出的相同的 top-3。

    我使用的模型优化器命令(不确定预处理参数): python3 ./mo_tf.py --input_model ~/workspace/reps/keras_to_tensorflow/resnet-50.pb --input_shape [1,224,224,3] --mean_values [103.939,116.779,123.68]

    你觉得这个解决方案可以吗?

    【讨论】:

      猜你喜欢
      • 2020-02-23
      • 2021-04-12
      • 2019-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多