我试图了解如何在OpenVino的模型优化器中添加对TensorFlow层FusedBatchNormV3的支持。我在Ubuntu 18.03上运行,并使用Tensorflow 15。
我的目标是在Neural Computer Stick 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中进行了介绍)。我想用FusedBatchNormV3
操作代替函数ScaleShift
,因为据说here FusedBatchNorm
与它相关,但是我不知道如何找到这个{ {1}}对象。有人可以帮我吗?
答案 0 :(得分: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]
该解决方案适合您吗?