Toybrick

标题: rknn.load_tensorflow 出错. [打印本页]

作者: xiaqing10    时间: 2019-5-15 14:11
标题: rknn.load_tensorflow 出错.
转换其他模型没问题,已经转过很多其他模型.这次就出现问题了.

环境: ubuntu16.04 , rknn0.99  ,代码如下, 转的是faceNet 的模型.



from rknn.api import RKNN

INPUT_SIZE = 224

if __name__ == '__main__':

    # Create RKNN object
    rknn = RKNN()

    # Config for Model Input PreProcess
    rknn.config(channel_mean_value='127.5 127.5 127.5 127.5', reorder_channel='0 1 2' ,quantized_dtype = 'asymmetric_quantized-u8')

    # Load TensorFlow Model
    print('--> Loading model')
    out = 'InceptionResnetV1/Bottleneck/BatchNorm/batchnorm/add_1'
    rknn.load_tensorflow(tf_pb='20170512-110547.pb',
                         inputs=['input_1', 'phase_train'],
                         outputs=[out],
                         input_size_list=[[INPUT_SIZE, INPUT_SIZE, 3] , [1] ])
    print('done')

    # Build Model
    print('--> Building model')
    rknn.build(do_quantization=True, dataset='./dataset.txt')
    print('done')

    # Export RKNN Model
    rknn.export_rknn('./exmaple.rknn')
    print("rknn convert sucess! ")

出错信息:
   --> Loading model
E Catch exception when loading tensorflow model: 20170512-110547.pb!
T Traceback (most recent call last):
T   File "rknn/api/rknn_base.py", line 132, in rknn.api.rknn_base.RKNNBase.load_tensorflow
T   File "rknn/base/RKNNlib/converter/convert_tf.py", line 95, in rknn.base.RKNNlib.converter.convert_tf.convert_tf.__init__
T   File "rknn/base/RKNNlib/converter/tensorflowloader.py", line 53, in rknn.base.RKNNlib.converter.tensorflowloader.TF_Graph_Preprocess.__init__
T AttributeError: 'NoneType' object has no attribute 'op'
done
--> Building model
E Catch exception when building RKNN model!
T Traceback (most recent call last):
T   File "rknn/api/rknn_base.py", line 459, in rknn.api.rknn_base.RKNNBase.build
T   File "rknn/api/rknn_base.py", line 939, in rknn.api.rknn_base.RKNNBase._quantize
T   File "rknn/base/RKNNlib/console/utils.py", line 7, in rknn.base.RKNNlib.console.utils.get_model_data_file
T   File "/usr/lib/python3.5/posixpath.py", line 122, in splitext
T     return genericpath._splitext(p, sep, None, extsep)
T   File "/usr/lib/python3.5/genericpath.py", line 118, in _splitext
T     sepIndex = p.rfind(sep)
T AttributeError: 'NoneType' object has no attribute 'rfind'
done




作者: xiaqing10    时间: 2019-5-15 15:35
这个应该是某些层不支持,不过请问怎么才能查看具体是哪些层呢?
作者: jefferyzhang    时间: 2019-5-17 11:58
xiaqing10 发表于 2019-5-15 15:35
这个应该是某些层不支持,不过请问怎么才能查看具体是哪些层呢?

吧verbose=True打开,就可以看到是那一层不支持了
作者: xiaqing10    时间: 2019-5-17 14:32
jefferyzhang 发表于 2019-5-17 11:58
吧verbose=True打开,就可以看到是那一层不支持了

好的,多谢.
作者: hfu    时间: 2019-6-25 03:20
20170512-110547.pb 似乎无法load。我用https://github.com/nyoki-mtl/keras-facenet 把20170512-110547的checkpoint文件转换到h5格式。 再用以下code重新freeze到pb
文件就可以用rknn load了。 最终rknn 测试结果96fps。

# Clear any previous session.
tf.keras.backend.clear_session()

save_pb_dir = "./model"
model_fname = "./model/facenet_keras.h5"


def freeze_graph(
    graph,
    session,
    output,
    save_pb_dir=".",
    save_pb_name="frozen_model.pb",
    save_pb_as_text=False,
):
    with graph.as_default():
        graphdef_inf = tf.graph_util.remove_training_nodes(graph.as_graph_def())
        graphdef_frozen = tf.graph_util.convert_variables_to_constants(
            session, graphdef_inf, output
        )
        graph_io.write_graph(
            graphdef_frozen, save_pb_dir, save_pb_name, as_text=save_pb_as_text
        )
        return graphdef_frozen


# This line must be executed before loading Keras model.
tf.keras.backend.set_learning_phase(0)

model = load_model(model_fname)
model.summary()
session = tf.keras.backend.get_session()

INPUT_NODE = [t.op.name for t in model.inputs]
OUTPUT_NODE = [t.op.name for t in model.outputs]
print("\nINPUT_NODE: {}\nOUTPUT_NODE: {}".format(INPUT_NODE, OUTPUT_NODE))
frozen_graph = freeze_graph(
    session.graph,
    session,
    [out.op.name for out in model.outputs],
    save_pb_dir=save_pb_dir,
)


# ## Convert `.pb` file to RKNN model
#
# Run `convert_rknn.py`

作者: sunkai    时间: 2021-6-5 09:24
hfu 发表于 2019-6-25 03:20
20170512-110547.pb 似乎无法load。我用https://github.com/nyoki-mtl/keras-facenet 把20170512-110547的c ...

phase_train怎么设置呢




欢迎光临 Toybrick (https://t.rock-chips.com/) Powered by Discuz! X3.3