Skip to content

Problems loading torchscript #795

Open
@davave

Description

@davave

Background

python version: 3.7.3
pytorch version: 1.8.1
torchvision version: 0.9.1

Issue

I'm trying to run a torchscript model from Ultralytics/YoloV5 in RedisAI using python.
I exported the model using export.py:

# TorchScript export -----------------------------------------------------------------------------------------------   
 if 'torchscript' in include or 'coreml' in include:
    prefix = colorstr('TorchScript:')
    try:
         print(f'\n{prefix} starting export with torch {torch.__version__}...')
         f = weights.replace('.pt', '.torchscript.pt')  # filename
         ts = torch.jit.trace(model, img, strict=False)
         (optimize_for_mobile(ts) if 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}')

and the file weights.torchscript.pt is generated. When I try to run

    import redis
    from urllib.parse import urlparse
    url = urlparse('redis://127.0.0.1:6379')
    conn = redis.Redis(host=url.hostname, port=url.port)
    with open('./weights.torchscript.pt', 'rb') as f:
        model = f.read()
        res = conn.execute_command('AI.SCRIPTSET', 'yolo:model', args.device, model)

the following error appears:

Traceback (most recent call last):
  File "init.py", line 45, in <module>
    res = conn.execute_command('AI.SCRIPTSET', 'yolo:model', args.device, model)
  File ".../.pyenv/versions/3.7.3/envs/3_7_3_venv/lib/python3.7/site-packages/redis/client.py", line 775, in execute_command
    return self.parse_response(connection, command_name, **options)
  File ".../.pyenv/versions/3.7.3/envs/3_7_3_venv/lib/python3.7/site-packages/redis/client.py", line 789, in parse_response
    response = connection.read_response()
  File ".../.pyenv/versions/3.7.3/envs/3_7_3_venv/lib/python3.7/site-packages/redis/connection.py", line 642, in read_response
    raise response
redis.exceptions.ResponseError: expected def but found 'ident' here: at <string>:1:0 PK ~~ <--- HERE 

Could anyone help me please? I am starting to use redisAI into the redisedge framework but I can't figure out whether the problem is in torchscript export, in the redisAI loading, or I am missing something important.
Thank you!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions