RedisAI/redisai-py

model get method returns incorrect backend type

shreyanair01 opened this issue · 4 comments

I am working with a yolo model. I was able to set and run the model by:

con = Client()
with open('yolo.pb', 'rb') as f:
     model = f.read()
con.modelset(
     'yolomodel', rai.Backend.tf, rai.Device.cpu, model,
     input=['input_1', 'input_image_shape'],
     output=['concat_11', 'concat_12', 'concat_13'])
con.modelrun(
     'yolomodel',
     input=['normalized_image', 'input_shape'],
     output=['boxes', 'scores', 'classes'])

After this when I try to simply get the model with following command, it returns an error:

con = Client()
model = con.modelget('yolomodel')
con.modelrun(
     'yolomodel',
     input=['normalized_image', 'input_shape'],
     output=['boxes', 'scores', 'classes'])

Error is as follows:

ValueError: 0 is not a valid Backend

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ".\redis_client.py", line 19, in <module>
    model = con.modelget('yolomodel')
  File "C:\Users\212767749\redisai_example\redisai_example\lib\site-packages\redisai\client.py", line 197, in modelget
    'backend': Backend(rv[0]),
  File "C:\Users\212767749\redisai_example\redisai_example\lib\enum.py", line 310, in __call__
    return cls.__new__(cls, value)
  File "C:\Users\212767749\redisai_example\redisai_example\lib\enum.py", line 564, in __new__
    raise exc
  File "C:\Users\212767749\redisai_example\redisai_example\lib\enum.py", line 548, in __new__
    result = cls._missing_(value)
  File "C:\Users\212767749\redisai_example\redisai_example\lib\enum.py", line 577, in _missing_
    raise ValueError("%r is not a valid %s" % (value, cls.__name__))
ValueError: 0 is not a valid Backend

However from redis-cli, I can see that the model exists in redis(EXISTS yolomodel) and can retrieve model on cli using AI.MODELGET yolomodel

How can I resolve this error?

@shreyanair01 Thanks a lot for the issue. It is causing due to the way we are handling the response inside modelget. Let me push a fix for this soon. Meanwhile, you can use the modelget function from the code below to simulate the same behavior redisai-py will have after the fix.

from redisai import Client, Backend, Device


con = Client()


def modelget(name):
    rv = con.execute_command('AI.MODELGET', name)
    backend = list(Backend)[rv[0]]
    device = list(Device)[rv[1]]
    return {
        'backend': backend,
        'device': device,
        'data': rv[2]
    }

I have also opened a ticket in RedisAI for required changes in the response values
RedisAI/RedisAI#175

@shreyanair01 This has been fixed in RedisAI/RedisAI#178 and will be out in the next RedisAI release. Please use the above function till then. Closing the issue for now but feel free to re-open if you have any more queries

Thank you! this worked for me