rockchip-linux / rknn-toolkit

BSD 3-Clause "New" or "Revised" License
829 stars 175 forks source link

Sample for converting pytorch ssd-mobilenet-v1 model #227

Open shaojun opened 2 years ago

shaojun commented 2 years ago

hi, thanks for the great repo. I didn't see the sample for how to use the Pytorch ssd-mobilenet-v1 model for convert, I have to reference the code sample under tensorflow/ssd_mobilenet_v1. Since my model was trained on higher version of pytorch, so I upgraded the torch to 1.6.0 before start the converting.

this is the modified piece of code:

if __name__ == '__main__':

    # Create RKNN object
    rknn = RKNN()

    # Config for Model Input PreProcess
    print('--> Config model')
    rknn.config(mean_values=[[127.5, 127.5, 127.5]], std_values=[[127.5, 127.5, 127.5]], reorder_channel='0 1 2')
    print('done')

    # Load TensorFlow Model
    print('--> Loading model')
    ret = rknn.load_pytorch(model='./mb1-ssd-Epoch-159-Loss-2.132093470721018.pth',
                               inputs=['FeatureExtractor/MobilenetV1/MobilenetV1/Conv2d_0/BatchNorm/batchnorm/mul_1'],
                               outputs=['concat', 'concat_1'],
                               input_size_list=[[INPUT_SIZE, INPUT_SIZE, 3]])
    if ret != 0:
        print('Load model failed!')
        exit(ret)
    print('done')

then come out the error:

python3 test.py --> Config model done --> Loading model W Does not support setting the inputs node. Unknown error may occur! W Does not support setting the outputs node. Unknown error may occur! ./mb1-ssd-Epoch-159-Loss-2.132093470721018.pth **** E Catch exception when loading pytorch model: ./mb1-ssd-Epoch-159-Loss-2.132093470721018.pth! E Traceback (most recent call last): E File "rknn/api/rknn_base.py", line 376, in rknn.api.rknn_base.RKNNBase.load_pytorch E File "rknn/base/RKNNlib/RK_nn.py", line 157, in rknn.base.RKNNlib.RK_nn.RKnn.load_pytorch E File "rknn/base/RKNNlib/app/importer/import_pytorch.py", line 129, in rknn.base.RKNNlib.app.importer.import_pytorch.ImportPytorch.run E File "rknn/base/RKNNlib/converter/convert_pytorch_new.py", line 3971, in rknn.base.RKNNlib.converter.convert_pytorch_new.convert_pytorch.load E File "/home/shao/miniconda3/envs/rknntk/lib/python3.6/site-packages/torch/jit/init.py", line 275, in load E cpp_module = torch._C.import_ir_module(cu, f, map_location, _extra_files) E RuntimeError: [enforce fail at inline_container.cc:209] . file not found: archive/constants.pkl E Please feedback the detailed log file to the RKNN Toolkit development team. E You can also check github issues: https://github.com/rockchip-linux/rknn-toolkit/issues Load model failed!

this is the log_feedback_to_the_rknn_toolkit_dev_team.log:

D Using CPPUTILS: True W Does not support setting the inputs node. Unknown error may occur! W Does not support setting the outputs node. Unknown error may occur! I Start importing pytorch... D import clients finished E Catch exception when loading pytorch model: ./mb1-ssd-Epoch-159-Loss-2.132093470721018.pth! E Traceback (most recent call last): E File "rknn/api/rknn_base.py", line 376, in rknn.api.rknn_base.RKNNBase.load_pytorch E File "rknn/base/RKNNlib/RK_nn.py", line 157, in rknn.base.RKNNlib.RK_nn.RKnn.load_pytorch E File "rknn/base/RKNNlib/app/importer/import_pytorch.py", line 129, in rknn.base.RKNNlib.app.importer.import_pytorch.ImportPytorch.run E File "rknn/base/RKNNlib/converter/convert_pytorch_new.py", line 3971, in rknn.base.RKNNlib.converter.convert_pytorch_new.convert_pytorch.load E File "/home/shao/miniconda3/envs/rknntk/lib/python3.6/site-packages/torch/jit/init.py", line 275, in load E cpp_module = torch._C.import_ir_module(cu, f, map_location, _extra_files) E RuntimeError: [enforce fail at inline_container.cc:209] . file not found: archive/constants.pkl E Please feedback the detailed log file to the RKNN Toolkit development team. E You can also check github issues: https://github.com/rockchip-linux/rknn-toolkit/issues

Questions:

  1. Could you help to check the error?
  2. I want to perform object detection on RV1126, as it support varies of models or model format for doing this, just wonder is there any recommendation for it, like which model format (.pth, .tf, .caffe), type (ssd-mobilenet, yolo) are preferred? the reason could be from performance-wise and etc.?
sahi1422 commented 2 years ago

@shaojun , did you find any solution?

shaojun commented 2 years ago

@sahi1422 no, but I personally suggest to use yolov5 as I see most of user have went through smoothly on that.