Toybrick

pb模型转rknn模型出错

hhhjjjwww

中级会员

积分
231
发表于 2020-6-2 14:34:53    查看: 5043|回复: 4 | [复制链接]    打印 | 显示全部楼层
错误如下:

ImportError: cannot import name 'r_add_n_template' from 'tfruler.tf_ruler_generate' (/home/toybrick/.local/lib/python3.7/site-packages/rknn/base/RKNNlib/converter/tfruler/tf_ruler_generate.cpython-37m-aarch64-linux-gnu.so)
done
--> Building model
Traceback (most recent call last):
  File "pb2rknn.py", line 32, in <module>
    rknn.build(do_quantization=False)
  File "/home/toybrick/.local/lib/python3.7/site-packages/rknn/api/rknn.py", line 222, in build
    inputs = self.rknn_base.net.get_input_layers()
AttributeError: 'NoneType' object has no attribute 'get_input_layers'

请问大家有遇到过吗


回复

使用道具 举报

leok

版主

积分
894
发表于 2020-6-2 17:18:27 | 显示全部楼层
信息帖全一些:
rknn toolkit版本;
tf版本;
什么模型;
转换脚本;
回复

使用道具 举报

hhhjjjwww

中级会员

积分
231
 楼主| 发表于 2020-6-3 10:35:04 | 显示全部楼层
leok 发表于 2020-6-2 17:18
信息帖全一些:
rknn toolkit版本;
tf版本;

--> Loading model
W:tensorflow:From /home/toybrick/.local/lib/python3.7/site-packages/onnx_tf/handlers/backend/ceil.py:10: The name tf.ceil is deprecated. Please use tf.math.ceil instead.

W:tensorflow:From /home/toybrick/.local/lib/python3.7/site-packages/onnx_tf/handlers/backend/depth_to_space.py:12: The name tf.depth_to_space is deprecated. Please use tf.compat.v1.depth_to_space instead.

W:tensorflow:
The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
  * https://github.com/tensorflow/co ... 7-contrib-sunset.md
  * https://github.com/tensorflow/addons
  * https://github.com/tensorflow/io (for I/O related ops)
If you depend on functionality not listed there, please file an issue.

W:tensorflow:From /home/toybrick/.local/lib/python3.7/site-packages/onnx_tf/handlers/backend/log.py:10: The name tf.log is deprecated. Please use tf.math.log instead.

W:tensorflow:From /home/toybrick/.local/lib/python3.7/site-packages/onnx_tf/handlers/backend/random_normal.py:9: The name tf.random_normal is deprecated. Please use tf.random.normal instead.

W:tensorflow:From /home/toybrick/.local/lib/python3.7/site-packages/onnx_tf/handlers/backend/random_uniform.py:9: The name tf.random_uniform is deprecated. Please use tf.random.uniform instead.

W:tensorflow:From /home/toybrick/.local/lib/python3.7/site-packages/onnx_tf/handlers/backend/upsample.py:13: The name tf.image.resize_images is deprecated. Please use tf.image.resize instead.

/home/toybrick/.local/lib/python3.7/site-packages/onnx_tf/common/__init__.py:87: UserWarning: FrontendHandler.get_outputs_names is deprecated. It will be removed in future release.. Use node.outputs instead.
  warnings.warn(message)
W:tensorflow:From /home/toybrick/.local/lib/python3.7/site-packages/rknn/api/rknn.py:67: extract_sub_graph (from tensorflow.python.framework.graph_util_impl) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.compat.v1.graph_util.extract_sub_graph`
Killed

rknn-toolkit 1.3版本,tf 1.14版本,darknet-yolov3,pb模型转换rknn模型
回复

使用道具 举报

hhhjjjwww

中级会员

积分
231
 楼主| 发表于 2020-6-3 10:37:10 | 显示全部楼层
leok 发表于 2020-6-2 17:18
信息帖全一些:
rknn toolkit版本;
tf版本;

#!/usr/bin/env python3

import os
import sys

#import yaml
import ruamel.yaml
from rknn.api import RKNN

yaml = ruamel.yaml.YAML(typ='rt')

def parse_model_config(yaml_config_file):
    with open(yaml_config_file) as f:
        yaml_config = f.read()
    model_configs = yaml.load(yaml_config)
    return model_configs


def convert_model(model_path, out_path, pre_compile):
    if os.path.isfile(model_path):
        yaml_config_file = model_path
        model_path = os.path.dirname(yaml_config_file)
    else:
        yaml_config_file = os.path.join(model_path, 'model_config.yml')
    if not os.path.exists(yaml_config_file):
        print('model config % not exist!' % yaml_config_file)
        exit(-1)

    model_configs = parse_model_config(yaml_config_file)

    exported_rknn_model_path_list = []

    for model_name in model_configs['models']:
        model = model_configs['models'][model_name]

        rknn = RKNN()

        rknn.config(**model['configs'])

        print('--> Loading model...')
        if model['platform'] == 'tensorflow':
            model_file_path = os.path.join(model_path, model['model_file_path'])
            input_size_list = []
            for input_size_str in model['subgraphs']['input-size-list']:
                input_size = list(map(int, input_size_str.split(',')))
                input_size_list.append(input_size)
            pass
            rknn.load_tensorflow(tf_pb=model_file_path,
                                 inputs=model['subgraphs']['inputs'],
                                 outputs=model['subgraphs']['outputs'],
                                 input_size_list=input_size_list)
        elif model['platform'] == 'tflite':
            model_file_path = os.path.join(model_path, model['model_file_path'])
            rknn.load_tflite(model=model_file_path)
        elif model['platform'] == 'caffe':
            prototxt_file_path = os.path.join(model_path,model['prototxt_file_path'])
            caffemodel_file_path = os.path.join(model_path,model['caffemodel_file_path'])
            rknn.load_caffe(model=prototxt_file_path, proto='caffe', blobs=caffemodel_file_path)
        elif model['platform'] == 'onnx':
            model_file_path = os.path.join(model_path, model['model_file_path'])
            rknn.load_onnx(model=model_file_path)
        else:
            print("platform %s not support!" % (model['platform']))
        print('done')

        if model['quantize']:
            dataset_path = os.path.join(model_path, model['dataset'])
        else:
            dataset_path = './dataset'

        print('--> Build RKNN model...')
        rknn.build(do_quantization=model['quantize'], dataset=dataset_path, pre_compile=pre_compile)
        print('done')

        export_rknn_model_path = "%s.rknn" % (os.path.join(out_path, model_name))
        print('--> Export RKNN model to: {}'.format(export_rknn_model_path))
        rknn.export_rknn(export_path=export_rknn_model_path)
        exported_rknn_model_path_list.append(export_rknn_model_path)
        print('done')
    rknn.release()
    return exported_rknn_model_path_list


if __name__ == '__main__':
    model_path = './model_config.yml'#sys.argv[1]
    out_path = './out_rknn.rknn'#sys.argv[2]
    pre_compile = False #sys.argv[3] in ['true', '1', 'True']

    convert_model(model_path, out_path, pre_compile)
参考了张老师给的例子
回复

使用道具 举报

leok

版主

积分
894
发表于 2020-6-5 14:35:48 | 显示全部楼层
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

产品中心 购买渠道 开源社区 Wiki教程 资料下载 关于Toybrick


快速回复 返回顶部 返回列表