44import cv2
55import base64
66import redisAI
7+ import numpy
78
89framesToDrop = 0
910
@@ -27,8 +28,11 @@ def addToGraphRunner(x):
2728 dataM = imageio .imread (data ).astype (dtype = 'float32' )
2829 newImg = (cv2 .resize (dataM , (224 , 224 )) / 128 ) - 1
2930
31+ l = numpy .asarray (newImg , dtype = numpy .float32 )
32+ img_ba = bytearray (l .tobytes ())
33+
3034 # converting the matrix color to Tensor
31- v1 = redisAI .createTensorFromValues ('FLOAT' , [1 , 224 , 224 , 3 ], toOneList ( newImg . tolist ()) )
35+ v1 = redisAI .createTensorFromBlob ('FLOAT' , [1 , 224 , 224 , 3 ], img_ba )
3236
3337 # creating the graph runner, 'g1' is the key in redis on which the graph is located
3438 graphRunner = redisAI .createModelRunner ('mobilenet:model' )
@@ -45,15 +49,15 @@ def addToGraphRunner(x):
4549
4650def addToStream (x ):
4751 # save animal name into a new stream
48- redisgears .executeCommand ('xadd' , 'cats' , 'MAXLEN' , '~' , '1000' , '*' , 'image' , 'data:image/jpeg;base64,' + base64 .b64encode (x [1 ]))
52+ redisgears .executeCommand ('xadd' , 'cats' , 'MAXLEN' , '~' , '1000' , '*' , 'image' , 'data:image/jpeg;base64,' + base64 .b64encode (x [1 ]). decode ( 'utf8' ) )
4953
5054def shouldTakeFrame (x ):
5155 global framesToDrop
5256 framesToDrop += 1
5357 return framesToDrop % 10 == 0
5458
5559def passAll (x ):
56- redisgears .executeCommand ('xadd' , 'all' , 'MAXLEN' , '~' , '1000' , '*' , 'image' , 'data:image/jpeg;base64,' + base64 .b64encode (x ['img' ]))
60+ redisgears .executeCommand ('xadd' , 'all' , 'MAXLEN' , '~' , '1000' , '*' , 'image' , 'data:image/jpeg;base64,' + base64 .b64encode (x ['img' ]). decode ( 'utf8' ) )
5761
5862# creating execution plane
5963gearsCtx ('StreamReader' ).\
0 commit comments