openvino踩坑之Data type is unsupported

今天在用openvino将pb文件转成ir文件的时候,遇到了一个小问题,记录下来分享给需要的人。

我用tensorflow自己存了个pb文件,具体的方法是在session中加入如下的语句

        for n in tf.get_default_graph().as_graph_def().node:
            print(n.name)
            print(n.attr["value"].tensor.dtype)

        output_node_names = [n.name for n in tf.get_default_graph().as_graph_def().node]
        #print(output_node_names)
        frozen = tf.graph_util.convert_variables_to_constants(sess, sess.graph_def, output_node_names)
        graph_io.write_graph(frozen, './', 'inference_graph.pb', as_text=False)

然后把这个生成的inference_graph.pb文件用mo.py转成openvino识别的.xml和.bin,但是遇到了下面的错误

[ ERROR ]  -------------------------------------------------
[ ERROR ]  ----------------- INTERNAL ERROR ----------------
[ ERROR ]  Unexpected exception happened.
[ ERROR ]  Please contact Model Optimizer developers and forward the following information:
[ ERROR ]  local variable 'new_attrs' referenced before assignment
[ ERROR ]  Traceback (most recent call last):
  File "C:\Program Files (x86)\IntelSWTools\openvino_2019.1.148\deployment_tools\model_optimizer\mo\front\extractor.py", line 604, in extract_node_attrs
    supported, new_attrs = extractor(Node(graph, node))
  File "C:\Program Files (x86)\IntelSWTools\openvino_2019.1.148\deployment_tools\model_optimizer\mo\pipeline\tf.py", line 124, in <lambda>
    extract_node_attrs(graph, lambda node: tf_op_extractor(node, check_for_duplicates(tf_op_extractors)))
  File "C:\Program Files (x86)\IntelSWTools\openvino_2019.1.148\deployment_tools\model_optimizer\mo\front\tf\extractor.py", line 140, in tf_op_extractor
    attrs = tf_op_extractors[op](node)
  File "C:\Program Files (x86)\IntelSWTools\openvino_2019.1.148\deployment_tools\model_optimizer\mo\front\tf\extractor.py", line 74, in <lambda>
    return lambda node: pb_extractor(node.pb)
  File "C:\Program Files (x86)\IntelSWTools\openvino_2019.1.148\deployment_tools\model_optimizer\mo\front\tf\extractors\const.py", line 32, in tf_const_ext
    result['value'] = tf_tensor_content(pb_tensor.dtype, result['shape'], pb_tensor)
  File "C:\Program Files (x86)\IntelSWTools\openvino_2019.1.148\deployment_tools\model_optimizer\mo\front\tf\extractors\utils.py", line 70, in tf_tensor_content
    refer_to_faq_msg(50), tf_dtype)
mo.utils.error.Error: Data type is unsupported: 19.
 For more information please refer to Model Optimizer FAQ (<INSTALL_DIR>/deployment_tools/documentation/docs/MO_FAQ.html), question #50.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files (x86)\IntelSWTools\openvino_2019.1.148\deployment_tools\model_optimizer\mo\main.py", line 312, in main
    return driver(argv)
  File "C:\Program Files (x86)\IntelSWTools\openvino_2019.1.148\deployment_tools\model_optimizer\mo\main.py", line 263, in driver
    is_binary=not argv.input_model_is_text)
  File "C:\Program Files (x86)\IntelSWTools\openvino_2019.1.148\deployment_tools\model_optimizer\mo\pipeline\tf.py", line 124, in tf2nx
    extract_node_attrs(graph, lambda node: tf_op_extractor(node, check_for_duplicates(tf_op_extractors)))
  File "C:\Program Files (x86)\IntelSWTools\openvino_2019.1.148\deployment_tools\model_optimizer\mo\front\extractor.py", line 610, in extract_node_attrs
    new_attrs['name'] if 'name' in new_attrs else '<UNKNOWN>',
UnboundLocalError: local variable 'new_attrs' referenced before assignment

[ ERROR ]  ---------------- END OF BUG REPORT --------------
[ ERROR ]  -------------------------------------------------

主要的错误就是标红的这一条 

mo.utils.error.Error: Data type is unsupported: 19.

根据 https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/framework/types.proto这里的定义,
 
  DT_INVALID = 0
 // Data types that all computation devices are expected to be
 // capable to support.
 DT_FLOAT = 1;
 DT_DOUBLE = 2;
 DT_INT32 = 3;
 DT_UINT8 = 4;
 DT_INT16 = 5;
 DT_INT8 = 6;
 DT_STRING = 7;
 DT_COMPLEX64 = 8; // Single-precision complex
 DT_INT64 = 9;
 DT_BOOL = 10;
 DT_QINT8 = 11; // Quantized int8
 DT_QUINT8 = 12; // Quantized uint8
 DT_QINT32 = 13; // Quantized int32
 DT_BFLOAT16 = 14; // Float32 truncated to 16 bits. Only for cast ops.
 DT_QINT16 = 15; // Quantized int16
 DT_QUINT16 = 16; // Quantized uint16
 DT_UINT16 = 17;
 DT_COMPLEX128 = 18; // Double-precision complex
 DT_HALF = 19;

19指的就是fp16,所以这个错误的意思是说我的pb file里面有fp16类型的变量,我直接在mo.py后面指定 --data_type FP16,不过也不起作用,后面,还是在freeze model的时候,全部改用了fp32的类型,再保存,然后运行mo.py就没有错误了。

参考:
https://github.com/opencv/dldt/issues/145

转载于:https://www.cnblogs.com/sunny-li/p/11240587.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值