Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yolov5 in EdgeRealtimeVideoAnalytics: issue importing pytorch model #49

Open
davave opened this issue May 12, 2021 · 0 comments
Open

Yolov5 in EdgeRealtimeVideoAnalytics: issue importing pytorch model #49

davave opened this issue May 12, 2021 · 0 comments

Comments

@davave
Copy link

davave commented May 12, 2021

Dear all,

First of all many thanks for this project.
I am new both to Redis and deep learning so forgive me if i'm making trivial mistakes.

I am trying to run YoloV5 model within EdgeRealtimeVideoAnalytics framework, but i am having troubles. that's what I did:

  1. first I exported the model with torchscript using this script provided by Ultralytics
   # TorchScript export ----------------------------------------------------------------------------------------------- 
    prefix = colorstr('TorchScript:') 
    try:  
        print(f'\n{prefix} starting export with torch {torch.__version__}...')  
        f = opt.weights.replace('.pt', '.torchscript.pt')  # filename  
        ts = torch.jit.trace(model, img, strict=False)  
        (optimize_for_mobile(ts) if opt.optimize else ts).save(f)  
        print(f'{prefix} export success, saved as {f} ({file_size(f):.1f} MB)')  
    except Exception as e:  
        print(f'{prefix} export failure: {e}')

I got the file 23weights.torchscript.pt

  1. I then modified init.py (obviously putting the .pt file in the right directory)
    with open('models/23weights.torchscript.pt', 'rb') as f:
        model = f.read()
        #res = conn.execute_command('AI.MODELSET', 'yolo:model', 'TF', args.device, 'INPUTS', 'input', 'OUTPUTS', 'output', model)
        res = conn.execute_command('AI.MODELSET', 'yolo:model', 'TORCH', args.device, model)
        print(res)

but i get the following message:

init_1                                | Loading model - Traceback (most recent call last):
init_1                                |   File "init.py", line 37, in <module>
init_1                                |     res = conn.execute_command('AI.MODELSET', 'yolo:model', 'TORCH', args.device, model)
init_1                                |   File "/usr/local/lib/python3.7/site-packages/redis/client.py", line 775, in execute_command
init_1                                |     return self.parse_response(connection, command_name, **options)
init_1                                |   File "/usr/local/lib/python3.7/site-packages/redis/client.py", line 789, in parse_response
init_1                                |     response = connection.read_response()
init_1                                |   File "/usr/local/lib/python3.7/site-packages/redis/connection.py", line 642, in read_response
init_1                                |     raise response
init_1                                | redis.exceptions.ResponseError: version_number <= kMaxSupportedFileFormatVersion INTERNAL ASSERT FAILED at /pytorch/caffe2/serialize/inline_container.cc:131, please report a bug to PyTorch. Attempted to read a PyTorch file with version 3, but the maximum supported version for reading is 1. Your PyTorch installation may be too old. (init at /pytorch/caffe2/serialize/inline_container.cc:131) frame #0: c10::Error::Error(c10::SourceLocation, std::string const&) + 0x33 (0x7f12e31a6273 in /usr/lib/redis/modules/backends/redisai_torch/lib/libc10.so) frame #1: caffe2::serialize::PyTorchStreamReader::init() + 0x1e9a (0x7f12e500040a in /usr/lib/redis/modules/backends/redisai_torch/lib/libtorch.so) frame #2: caffe2::serialize::PyTorchStreamReader::PyTorchStreamReader(std::unique_ptr<caffe2::serialize::ReadAdapterInterface, std::default_delete<caffe2::serialize::ReadAdapterInterface> >) + 0x53 (0x7f12e50015c3 in /usr/lib/redis/modules/backends/redisai_torch/lib/libtorch.so) frame #3: <unknown function> + 0x2d120d2 (0x7f12e60df0d2 in /usr/lib/redis/modules/backends/redisai_torch/lib/libtorch.so) frame #4: torch::jit::load(std::unique_ptr<caffe2::serialize::ReadAdapterInterface, std::default_delete<caffe2::serialize::ReadAdapterInterface> >, c10::optional<c10::Device>, 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> > >&) + 0x27 (0x7f12e60de027 in /usr/lib/redis/modules/backends/redisai_torch/lib/libtorch.so) frame #5: torch::jit::load(std::istream&, c10::optional<c10::Device>, 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> > >&) + 0x69 (0x7f12e60de2a9 in /usr/lib/redis/modules/backends/redisai_torch/lib/libtorch.so) frame #6: torchLoadModel + 0x1f7 (0x7f12ef5e48b7 in /usr/lib/redis/modules/backends/redisai_torch/redisai_torch.so) frame #7: RAI_ModelCreateTorch + 0x9d (0x7f12ef5e0ebd in /usr/lib/redis/modules/backends/redisai_torch/redisai_torch.so) frame #8: RedisAI_ModelSet_RedisCommand + 0x242 (0x7f12fa57b782 in /usr/lib/redis/modules/redisai.so) frame #9: RedisModuleCommandDispatcher + 0x56 (0x564747ba66d6 in redis-server *:6379) frame #10: call + 0xa7 (0x564747b362b7 in redis-server *:6379) frame #11: processCommand + 0x51e (0x564747b36b5e in redis-server *:6379) frame #12: processInputBuffer + 0x171 (0x564747b46d51 in redis-server *:6379) frame #13: aeProcessEvents + 0x101 (0x564747b302e1 in redis-server *:6379) frame #14: aeMain + 0x2b (0x564747b306eb in redis-server *:6379) frame #15: main + 0x4b9 (0x564747b2d569 in redis-server *:6379) frame #16: __libc_start_main + 0xeb (0x7f12fa5b809b in /lib/x86_64-linux-gnu/libc.so.6) frame #17: _start + 0x2a (0x564747b2d7aa in redis-server *:6379) 
edgerealtimevideoanalytics_init_1 exited with code 1

As you can see the problem is related with pytorch version, but I can't figure out how to fix this problem. Could you please help me? I am not even sure I am passing to RedisAI the right formatted model, so please let me know if I am making mistakes.

Thank you
Davide

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant