• 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)IntelSWToolsopenvino_2019.1.148deployment_toolsmodel_optimizermofrontextractor.py", line 604, in extract_node_attrs
        supported, new_attrs = extractor(Node(graph, node))
      File "C:Program Files (x86)IntelSWToolsopenvino_2019.1.148deployment_toolsmodel_optimizermopipeline	f.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)IntelSWToolsopenvino_2019.1.148deployment_toolsmodel_optimizermofront	fextractor.py", line 140, in tf_op_extractor
        attrs = tf_op_extractors[op](node)
      File "C:Program Files (x86)IntelSWToolsopenvino_2019.1.148deployment_toolsmodel_optimizermofront	fextractor.py", line 74, in <lambda>
        return lambda node: pb_extractor(node.pb)
      File "C:Program Files (x86)IntelSWToolsopenvino_2019.1.148deployment_toolsmodel_optimizermofront	fextractorsconst.py", line 32, in tf_const_ext
        result['value'] = tf_tensor_content(pb_tensor.dtype, result['shape'], pb_tensor)
      File "C:Program Files (x86)IntelSWToolsopenvino_2019.1.148deployment_toolsmodel_optimizermofront	fextractorsutils.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)IntelSWToolsopenvino_2019.1.148deployment_toolsmodel_optimizermomain.py", line 312, in main
        return driver(argv)
      File "C:Program Files (x86)IntelSWToolsopenvino_2019.1.148deployment_toolsmodel_optimizermomain.py", line 263, in driver
        is_binary=not argv.input_model_is_text)
      File "C:Program Files (x86)IntelSWToolsopenvino_2019.1.148deployment_toolsmodel_optimizermopipeline	f.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)IntelSWToolsopenvino_2019.1.148deployment_toolsmodel_optimizermofrontextractor.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
  • 相关阅读:
    分页,上传,下载
    java web 开发模式
    EL/JSTL-jsp页面更简单的输出方式
    过滤器和监听器
    Servlet
    jsp标准动作
    java Bean
    寻找你的热情(1)——检查自己所处的位置
    fedora25 安装sublime text3
    python实例3-天气小模块
  • 原文地址:https://www.cnblogs.com/sunny-li/p/11240587.html
Copyright © 2020-2023  润新知