RedisGears / AnimalRecognitionDemo

An example of using Redis Streams, RedisGears and RedisAI for Realtime Video Analytics (i.e. filtering cats)
https://redisgears.io
Apache License 2.0
42 stars 18 forks source link

Couple errors, can't get it to work #30

Closed coding-to-music closed 2 years ago

coding-to-music commented 2 years ago

Hello, I am doing this tutorial: https://github.com/RedisGears/AnimalRecognitionDemo

My repo is here: https://github.com/coding-to-music/redisgears-redisai-animal-recognition

I had some hiccups about git lfs, but seem to have that working However, I have not been able to get the "make test" to work In the UI I only see the Redis logo, no images I am unable to view the .pb video file (stored via lfs) so not sure it is correct/working

I am developing on a remote VM (Digitalocean droplet) so not sure if I can use my webcam? I am using a chromebook but run everything on the droplet. Pretty sure it can't see my camera.

Some before / after as I was doing the steps:

make start

make start

Output:

Starting redisgears-redisai-animal-recognition_redis_1 ... done
Creating redisgears-redisai-animal-recognition_app_1     ... done
Creating redisgears-redisai-animal-recognition_weball_1  ... done
Creating redisgears-redisai-animal-recognition_webcats_1 ... done

make camera

make camera

Output:

python3 camera/read_camera.py
Traceback (most recent call last):
  File "camera/read_camera.py", line 3, in <module>
    import cv2
ModuleNotFoundError: No module named 'cv2'
make: *** [Makefile:39: camera] Error 1

pip3 install opencv-python

pip3 install opencv-python

start redis and other services

docker-compose up

make camera

make camera

Output:

python3 camera/read_camera.py
Connected to Redis
Operating in camera mode
[ WARN:0@0.208] global /io/opencv/modules/videoio/src/cap_v4l.cpp (902) open VIDEOIO(V4L2:/dev/video0): can't open camera by index
Traceback (most recent call last):
  File "camera/read_camera.py", line 83, in <module>
    for (count, img) in loader:
  File "camera/read_camera.py", line 35, in __next__
    assert ret_val, 'Webcam Error'
AssertionError: Webcam Error
make: *** [Makefile:39: camera] Error 1

run the camera process in test mode (without streaming from your camera):

Note that the provided code (below) will (without quotes) interpret the pipe symbol as a pipe and not an OR (should the example be revised?)

ANIMAL=[cat|dog] python camera/read_camera.py --test
dog]: command not found

export a value for ANIMAL using quotes

export ANIMAL="[cat|dog]"

ensure the value is correct for ANIMAL

printenv | grep ANIMAL

Output

ANIMAL=[cat|dog]

Run the test

python camera/read_camera.py --test

Output

Connected to Redis
Operating in test mode with image [cat|dog].jpg
Traceback (most recent call last):
  File "camera/read_camera.py", line 99, in <module>
    img = cv2.resize(img0, (IMAGE_WIDTH, IMAGE_HEIGHT))
cv2.error: OpenCV(4.4.0) /tmp/pip-req-build-h2062vqd/opencv/modules/imgproc/src/resize.cpp:3929: error: (-215:Assertion failed) !ssize.empty() in function 'resize'

The docker console log shows this:

redis_1    | 1:M 24 Jun 2022 06:42:45.857 * Ready to accept connections
redis_1    | 1:M 24 Jun 2022 06:42:46.795 # <ai> backend TF not loaded, will try loading default backend
redis_1    | 1:M 24 Jun 2022 06:42:46.866 * <ai> TF backend loaded from /usr/lib/redis/modules/backends/redisai_tensorflow/redisai_tensorflow.so
redis_1    | 1:M 24 Jun 2022 06:42:46.887 # <ai> Invalid GraphDef
app_1      | Loading model - Traceback (most recent call last):
app_1      |   File "/app/init.py", line 39, in <module>
app_1      |     res = conn.execute_command('AI.MODELSTORE', 'mobilenet:model', 'TF', 'CPU', 'INPUTS', '1', 'input', 'OUTPUTS', '1', 'MobilenetV2/Predictions/Reshape_1', 'BLOB', model)
app_1      |   File "/usr/local/lib/python3.9/dist-packages/redis/client.py", line 1235, in execute_command
app_1      |     return conn.retry.call_with_retry(
app_1      |   File "/usr/local/lib/python3.9/dist-packages/redis/retry.py", line 46, in call_with_retry
app_1      |     return do()
app_1      |   File "/usr/local/lib/python3.9/dist-packages/redis/client.py", line 1236, in <lambda>
app_1      |     lambda: self._send_command_parse_response(
app_1      |   File "/usr/local/lib/python3.9/dist-packages/redis/client.py", line 1212, in _send_command_parse_response
app_1      |     return self.parse_response(conn, command_name, **options)
app_1      |   File "/usr/local/lib/python3.9/dist-packages/redis/client.py", line 1251, in parse_response
app_1      |     response = connection.read_response()
app_1      |   File "/usr/local/lib/python3.9/dist-packages/redis/connection.py", line 837, in read_response
app_1      |     raise response
app_1      | redis.exceptions.ResponseError: Invalid GraphDef
weball_1   | Redis Labs - app listening on port 3000!
webcats_1  | Redis Labs - app listening on port 3000!
redisgears-redisai-animal-recognition_app_1 exited with code 1
webcats_1  | received: connected
weball_1   | received: connected

make test

make test

Output:

Testing cats ...
cats: FAIL
make: *** [Makefile:24: test] Error 1

Any assistance is appreciated

GuyAv46 commented 2 years ago

Regarding the camera issue: VM can’t access (by default) to your webcam for security reasons. Remote VM adds another complexity. If you really want to run this demo in this configuration, you will have to make a few changes (maybe run the camera script locally? Or on a local VM that you granted access to the webcam?) Make sure you modify the connection parameters for this kind of configuration.

Regarding the test issue: try running ANIMAL=cat python camera/read_camera.py --test OR ANIMAL=dog python camera/read_camera.py --test The ANIMAL variable determines the test image (cat.jpg or dog.jpg), and this demo doesn’t support both on the same run

coding-to-music commented 2 years ago

ok, thanks, that works

make clean
make setup
make build
export ANIMAL=dog
make test
... more lines ...
1657058108889-1  addToGraphRunner: count= 140
1657058108947-0  addToGraphRunner: animal= golden_retriever
1657058108990-0  shouldTakeFrame 141 False
1657058109091-0  shouldTakeFrame 142 False
1657058109192-0  shouldTakeFrame 143 False
1657058109292-0  shouldTakeFrame 144 False
1657058109394-0  shouldTakeFrame 145 False
1657058109494-0  shouldTakeFrame 146 False
1657058109595-0  shouldTakeFrame 147 False
1657058109696-0  shouldTakeFrame 148 False
1657058109797-0  shouldTakeFrame 149 False
1657058109898-0  shouldTakeFrame 150 True
1657058109899-0  addToGraphRunner: count= 150
1657058109956-0  addToGraphRunner: animal= golden_retriever
1657058109999-0  shouldTakeFrame 151 False
1657058110100-0  shouldTakeFrame 152 False
1657058110201-0  shouldTakeFrame 153 False
1657058110302-0  shouldTakeFrame 154 False
1657058110403-0  shouldTakeFrame 155 False
1657058110503-0  shouldTakeFrame 156 False
1657058110604-0  shouldTakeFrame 157 False
Stopping camera.catndogs ... done
Stopping redis.catndogs  ... done
Removing camera.catndogs ... done
Removing app.catndogs    ... done
Removing redis.catndogs  ... done
Removing network catsndogs_default
dogs: OK

So, success !!! Thanks