X2Paddle icon indicating copy to clipboard operation
X2Paddle copied to clipboard

Model is not supported yet

Open luo1230 opened this issue 4 years ago • 1 comments

模型来源: TensorFlow 模型说明: 图像分类模型,其相应repo为 https://github.com/Jackluisus/VisDrone-ensemble-tensorflow 模型文件: 链接: 链接:https://pan.baidu.com/s/1f7HwghJtPmJJPazSxhTtiA 提取码:0eq4

ckpt模型转换为pb模型代码如下:

from tensorflow_core.python.framework import graph_util

import tensorflow as tf

def freeze_graph(input_checkpoint, output_graph):
    '''
    :param input_checkpoint:
    :param output_graph: PB模型保存路径
    '''
    # 输出节点名称
    output_node_names = "save_1/restore_all"

    saver = tf.train.import_meta_graph(input_checkpoint + '.meta', clear_devices=True)
    graph = tf.get_default_graph()
    input_graph_def = graph.as_graph_def()
    with tf.Session() as sess:
        saver.restore(sess, input_checkpoint)

        # fix batch norm nodes
        # 解决value error问题
        for node in input_graph_def.node:
            if node.op == 'RefSwitch':
                node.op = 'Switch'
                for index in xrange(len(node.input)):
                    if 'moving_' in node.input[index]:
                        node.input[index] = node.input[index] + '/read'
            elif node.op == 'AssignSub':
                node.op = 'Sub'
                if 'use_locking' in node.attr: del node.attr['use_locking']
            elif node.op == 'AssignAdd':
                node.op = 'Add'
                if 'use_locking' in node.attr: del node.attr['use_locking']
            elif node.op == 'Assign':
                node.op = 'Identity'
                if 'use_locking' in node.attr: del node.attr['use_locking']
                if 'validate_shape' in node.attr: del node.attr['validate_shape']
                if len(node.input) == 2:
                    # input0: ref: Should be from a Variable node. May be uninitialized.
                    # input1: value: The value to be assigned to the variable.
                    node.input[0] = node.input[1]
                    del node.input[1]

        output_graph_def = graph_util.convert_variables_to_constants(
            sess=sess,
            input_graph_def=input_graph_def,  # 等于:sess.graph_def
            output_node_names=output_node_names.split(","))

        with tf.gfile.GFile(output_graph, "wb") as f:
            f.write(output_graph_def.SerializeToString())
        print("%d ops in the final graph." % len(output_graph_def.node))



if __name__ == '__main__':
    input_checkpoint = 'visdrone_resnet101_v1d_88000_model.ckpt'
    output_graph = 'freeze_model.pb'
    freeze_graph(input_checkpoint, output_graph)

转换过程出错提示如下:

  import imp
Now translating model from tensorflow to paddle.

========= 2 OPs are not supported yet ===========
========== NoOp ============
========== RestoreV2 ============
Traceback (most recent call last):
  File "D:\Anaconda\envs\tfgpu1.5\Scripts\x2paddle-script.py", line 33, in <module>
    sys.exit(load_entry_point('x2paddle==1.2.3', 'console_scripts', 'x2paddle')())
  File "D:\Anaconda\envs\tfgpu1.5\lib\site-packages\x2paddle-1.2.3-py3.6.egg\x2paddle\convert.py", line 251, in main
    tf2paddle(args.model, args.save_dir, define_input_shape)
  File "D:\Anaconda\envs\tfgpu1.5\lib\site-packages\x2paddle-1.2.3-py3.6.egg\x2paddle\convert.py", line 117, in tf2paddle
    mapper = TFOpMapper(model)
  File "D:\Anaconda\envs\tfgpu1.5\lib\site-packages\x2paddle-1.2.3-py3.6.egg\x2paddle\op_mapper\tf2paddle\tf_op_mapper.py", line 91, in __init__
    raise Exception("Model is not supported yet.")
Exception: Model is not supported yet.

luo1230 avatar Aug 03 '21 03:08 luo1230

这里的output_node_names检查下是否是正确的输出节点;对于分类模型而言,一般最后一个节点是softmax或fc全连接层


另外你这里的模型是用于什么场景下的呢?例如什么业务,用什么部署方式之类的

jiangjiajun avatar Aug 04 '21 03:08 jiangjiajun