Toybrick

pytorch多标签分类模型转换失败

xlbjs

新手上路

积分
40
楼主
发表于 2021-1-6 09:59:23    查看: 9943|回复: 2 | [复制链接]    打印 | 只看该作者
pytorch训练的多标签分类模型,转成rknn时加载模型直接报错,是还不支持pytorch多标签模型,还是其他原因:
--> config model
done
--> Loading model

WARNING: 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
If you depend on functionality not listed there, please file an issue.

/usr/local/lib/python3.5/dist-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)
checkpoint_best.pt ********************
E Catch exception when loading pytorch model: checkpoint_best.pt!
E Traceback (most recent call last):
E   File "rknn/api/rknn_base.py", line 657, in rknn.api.rknn_base.RKNNBase.load_pytorch
E   File "rknn/base/RKNNlib/app/importer/import_pytorch.py", line 97, in rknn.base.RKNNlib.app.importer.import_pytorch.ImportPytorch.run
E   File "rknn/base/RKNNlib/converter/convert_pytorch.py", line 737, in rknn.base.RKNNlib.converter.convert_pytorch.convert_pytorch.__init__
E   File "/usr/local/lib/python3.5/dist-packages/torch/jit/__init__.py", line 235, in load
E     cpp_module = torch._C.import_ir_module(cu, f, map_location, _extra_files)
E RuntimeError: [enforce fail at inline_container.cc:143] . PytorchStreamReader failed reading zip archive: failed finding central directory
E frame #0: c10::ThrowEnforceNotMet(char const*, int, char const*, std::string const&, void const*) + 0x47 (0x7f33ec7e4d37 in /usr/local/lib/python3.5/dist-packages/torch/lib/libc10.so)
E frame #1: caffe2::serialize:yTorchStreamReader::valid(char const*, char const*) + 0x72 (0x7f33ef903db2 in /usr/local/lib/python3.5/dist-packages/torch/lib/libtorch.so)
E frame #2: caffe2::serialize:yTorchStreamReader::init() + 0xa1 (0x7f33ef906d81 in /usr/local/lib/python3.5/dist-packages/torch/lib/libtorch.so)
E frame #3: caffe2::serialize:yTorchStreamReader:yTorchStreamReader(std::string const&) + 0x64 (0x7f33ef909e54 in /usr/local/lib/python3.5/dist-packages/torch/lib/libtorch.so)
E frame #4: torch::jit::import_ir_module(std::shared_ptr<torch::jit::script::CompilationUnit>, std::string const&, c10:ptional<c10:evice>, std::unordered_map<std::string, std::string, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, std::string> > >&) + 0x35 (0x7f33f0c69a95 in /usr/local/lib/python3.5/dist-packages/torch/lib/libtorch.so)
E frame #5: <unknown function> + 0x7765bb (0x7f342e3e35bb in /usr/local/lib/python3.5/dist-packages/torch/lib/libtorch_python.so)
E frame #6: <unknown function> + 0x2956c4 (0x7f342df026c4 in /usr/local/lib/python3.5/dist-packages/torch/lib/libtorch_python.so)
E <omitting python frames>
E frame #10: <unknown function> + 0x1df15 (0x7f34373b3f15 in /usr/local/lib/python3.5/dist-packages/rknn/base/RKNNlib/converter/convert_pytorch.cpython-35m-x86_64-linux-gnu.so)
E frame #11: <unknown function> + 0x1ed5f (0x7f34373b4d5f in /usr/local/lib/python3.5/dist-packages/rknn/base/RKNNlib/converter/convert_pytorch.cpython-35m-x86_64-linux-gnu.so)
E frame #12: <unknown function> + 0x60b48 (0x7f34373f6b48 in /usr/local/lib/python3.5/dist-packages/rknn/base/RKNNlib/converter/convert_pytorch.cpython-35m-x86_64-linux-gnu.so)
E frame #14: python3() [0x4f42ce]
E frame #16: python3() [0x5991b9]
E frame #17: python3() [0x56c40c]
E frame #18: <unknown function> + 0x65b0 (0x7f34388735b0 in /usr/local/lib/python3.5/dist-packages/rknn/base/RKNNlib/app/importer/import_pytorch.cpython-35m-x86_64-linux-gnu.so)
E frame #19: <unknown function> + 0xbb87 (0x7f3438878b87 in /usr/local/lib/python3.5/dist-packages/rknn/base/RKNNlib/app/importer/import_pytorch.cpython-35m-x86_64-linux-gnu.so)
E frame #20: <unknown function> + 0x236bd (0x7f351b4266bd in /usr/local/lib/python3.5/dist-packages/rknn/api/rknn_base.cpython-35m-x86_64-linux-gnu.so)
E frame #21: <unknown function> + 0xc8fc3 (0x7f351b4cbfc3 in /usr/local/lib/python3.5/dist-packages/rknn/api/rknn_base.cpython-35m-x86_64-linux-gnu.so)
E frame #24: python3() [0x544399]
E frame #26: python3() [0x544399]
E frame #28: python3() [0x625042]
E frame #33: __libc_start_main + 0xf0 (0x7f359f8f3840 in /lib/x86_64-linux-gnu/libc.so.6)
Load model.pt failed!



转换代码:
import numpy as np
import cv2
from rknn.api import RKNN

if __name__ == '__main__':

    # Create RKNN object
    # rknn = RKNN()
    rknn = RKNN()

    # pre-process config
    print('--> config model')
    rknn.config(batch_size=1, channel_mean_value='123.675 116.28 103.53 58.395', reorder_channel='0 1 2')
    print('done')

    input_size_list = [[3,224,224]]
    # Load tensorflow model
    print('--> Loading model')
    ret = rknn.load_pytorch(model='checkpoint_best.pt', input_size_list=input_size_list)
    if ret != 0:
        print('Load model.pt failed!')
        exit(ret)
    print('done')

    # Build model
    print('--> Building model')
    ret = rknn.build(do_quantization=True, dataset='./dataset.txt', pre_compile=False)
    if ret != 0:
        print('Build platemark failed!')
        exit(ret)
    print('done')

    # Export rknn model
    print('--> Export RKNN model')
    ret = rknn.export_rknn('./rcfv4-20210106.rknn')
    if ret != 0:
        print('Export platemark.rknn failed!')
        exit(ret)
    print('done')

    exit(0)


回复

使用道具 举报

leok

版主

积分
894
沙发
发表于 2021-1-8 15:03:39 | 只看该作者
可以加RKNN 官网QQ交流群讨论
1025468710
回复

使用道具 举报

zqwwwm

新手上路

积分
46
板凳
发表于 2021-1-20 10:31:01 | 只看该作者
发现很多问题是版本对应问题 之前一直会报错 对应好版本后 就好了
回复

使用道具 举报

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

本版积分规则

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


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