Closed boxofrox closed 3 days ago
Attempted to troubleshoot. Round 1.
docker exec -it ai-server /bin/bash
.cd /app/modules/ObjectDetectionYoloRKNN/bin/linux/python39/venv/
.site-packages
of python environment. ls lib/python3.9/site-packages
a. codeproject_ai_sdk
appears to be version 0.0.21
b. numpy
appears to be version 2.0.2source bin/activate
.python3.9 -i
.codeproject_ai_sdk
. import codeproject_ai_sdk
a. This caused the same AttributeError
shown in the logs above.>>> import codeproject_ai_sdk
Unable to read module info in /app/modules/ObjectDetectionYoloRKNN/bin/linux/python39/venv
A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.2 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.
If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.
Traceback (most recent call last): File "<stdin>", line 1, in <module>
File "/app/modules/ObjectDetectionYoloRKNN/bin/linux/python39/venv/lib/python3.9/site-packages/codeproject_ai_sdk/__init__.py", line 4, in <module>
from .module_runner import ModuleRunner
File "/app/modules/ObjectDetectionYoloRKNN/bin/linux/python39/venv/lib/python3.9/site-packages/codeproject_ai_sdk/module_runner.py", line 36, in <module>
from .request_data import RequestData
File "/app/modules/ObjectDetectionYoloRKNN/bin/linux/python39/venv/lib/python3.9/site-packages/codeproject_ai_sdk/request_data.py", line 15, in <module>
import cv2 as cv
File "/app/modules/ObjectDetectionYoloRKNN/bin/linux/python39/venv/lib/python3.9/site-packages/cv2/__init__.py", line 5, in <module>
from .cv2 import *
AttributeError: _ARRAY_API not found
Info: Using PIL for image manipulation (Either OpenCV or numpy not available for this module)
It would appear that the Object Detection Yolov5 RKNN module is not compatible with numpy 2.
So... downgrade numpy to 1.x, or rebuild module to use numpy 2?
No idea how to do either one, yet.
With the module's python environment active, I decided to check out the requirements.txt
for the module, found it had a numpy<2
version requirement (which begs the question, "why didn't numpy 1.x install?"). Then tried to do a pip install -r requirements.txt
and pip installed numpy
1.26 and removed numpy
2.0.2.
Q. Was the requirements.txt not used to set up the python environment?
(venv) root@857ed486c15c:/app/modules/ObjectDetectionYoloRKNN# cat requirements.txt
#! Python3.9
# Note that this wheel was built on, and for, an Orange Pi. It will not run on a Raspberry Pi
https://github.com/MikeLud/CodeProject.AI-Custom-IPcam-Models/raw/main/RKNN_Models/fastdeploy_python-1.4.2b0-cp39-cp39-linux_aarch64.whl # Installing the RK NPU specific FastDeploy 1.4
# numpy>=1.16.0 # Installing NumPy, the fundamental package for array computing with Python.
numpy<2.0 # Installing NumPy, a package for scientific computing
Pillow>=4.0.0,<10.0 # Installing Pillow, a Python Image Library
#OpenCV-Python # Installing OpenCV, the Open source Computer Vision library
# See https://raspberrypi-guide.github.io/programming/install-opencv
opencv-python==4.5.3.56 # Installing OpenCV, the Open source Computer Vision library
CodeProject-AI-SDK # Installing the CodeProject.AI SDK
# last line empty test(venv) root@857ed486c15c:/app/modules/ObjectDetectionYoloRKNN# pip -r requirements.txt
Usage:
pip <command> [options]
no such option: -r
(venv) root@857ed486c15c:/app/modules/ObjectDetectionYoloRKNN# pip install -r requirements.txt
Collecting fastdeploy-python==1.4.2b0 (from -r requirements.txt (line 4))
Using cached https://github.com/MikeLud/CodeProject.AI-Custom-IPcam-Models/raw/main/RKNN_Models/fastdeploy_python-1.4.2b0-cp39-cp39-linux_aarch64.whl (29.2 MB)
Collecting numpy<2.0 (from -r requirements.txt (line 7))
Downloading numpy-1.26.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.metadata (62 kB)
Collecting Pillow<10.0,>=4.0.0 (from -r requirements.txt (line 8))
Downloading Pillow-9.5.0-cp39-cp39-manylinux_2_28_aarch64.whl.metadata (9.5 kB)
Requirement already satisfied: opencv-python==4.5.3.56 in ./bin/linux/python39/venv/lib/python3.9/site-packages (from -r requirements.txt (line 12)) (4.5.3.56)
Requirement already satisfied: CodeProject-AI-SDK in ./bin/linux/python39/venv/lib/python3.9/site-packages (from -r requirements.txt (line 14)) (0.0.21)
Requirement already satisfied: fastapi in ./bin/linux/python39/venv/lib/python3.9/site-packages (from fastdeploy-python==1.4.2b0->-r requirements.txt (line 4)) (0.115.0)
Requirement already satisfied: fastdeploy-tools>=0.0.5 in ./bin/linux/python39/venv/lib/python3.9/site-packages (from fastdeploy-python==1.4.2b0->-r requirements.txt (line 4)) (0.0.5)
Requirement already satisfied: pyyaml in ./bin/linux/python39/venv/lib/python3.9/site-packages (from fastdeploy-python==1.4.2b0->-r requirements.txt (line 4)) (6.0.2)
Requirement already satisfied: requests in ./bin/linux/python39/venv/lib/python3.9/site-packages (from fastdeploy-python==1.4.2b0->-r requirements.txt (line 4)) (2.32.3)
Requirement already satisfied: tqdm in ./bin/linux/python39/venv/lib/python3.9/site-packages (from fastdeploy-python==1.4.2b0->-r requirements.txt (line 4)) (4.66.5)
Requirement already satisfied: wheel in ./bin/linux/python39/venv/lib/python3.9/site-packages (from fastdeploy-python==1.4.2b0->-r requirements.txt (line 4)) (0.44.0)
Requirement already satisfied: charset-normalizer in ./bin/linux/python39/venv/lib/python3.9/site-packages (from CodeProject-AI-SDK->-r requirements.txt (line 14)) (3.3.2)
Requirement already satisfied: commentjson in ./bin/linux/python39/venv/lib/python3.9/site-packages (from CodeProject-AI-SDK->-r requirements.txt (line 14)) (0.9.0)
Requirement already satisfied: aiohttp in ./bin/linux/python39/venv/lib/python3.9/site-packages (from CodeProject-AI-SDK->-r requirements.txt (line 14)) (3.10.5)
Requirement already satisfied: aiofiles in ./bin/linux/python39/venv/lib/python3.9/site-packages (from CodeProject-AI-SDK->-r requirements.txt (line 14)) (24.1.0)
Requirement already satisfied: py-cpuinfo in ./bin/linux/python39/venv/lib/python3.9/site-packages (from CodeProject-AI-SDK->-r requirements.txt (line 14)) (9.0.0)
Requirement already satisfied: uvicorn==0.16.0 in ./bin/linux/python39/venv/lib/python3.9/site-packages (from fastdeploy-tools>=0.0.5->fastdeploy-python==1.4.2b0->-r requirements.txt (line 4)) (0.16.0)
Requirement already satisfied: asgiref>=3.4.0 in ./bin/linux/python39/venv/lib/python3.9/site-packages (from uvicorn==0.16.0->fastdeploy-tools>=0.0.5->fastdeploy-python==1.4.2b0->-r requirements.txt (line 4)) (3.8.1)
Requirement already satisfied: click>=7.0 in ./bin/linux/python39/venv/lib/python3.9/site-packages (from uvicorn==0.16.0->fastdeploy-tools>=0.0.5->fastdeploy-python==1.4.2b0->-r requirements.txt (line 4)) (8.1.7)
Requirement already satisfied: h11>=0.8 in ./bin/linux/python39/venv/lib/python3.9/site-packages (from uvicorn==0.16.0->fastdeploy-tools>=0.0.5->fastdeploy-python==1.4.2b0->-r requirements.txt (line 4)) (0.14.0)
Requirement already satisfied: aiohappyeyeballs>=2.3.0 in ./bin/linux/python39/venv/lib/python3.9/site-packages (from aiohttp->CodeProject-AI-SDK->-r requirements.txt (line 14)) (2.4.0)
Requirement already satisfied: aiosignal>=1.1.2 in ./bin/linux/python39/venv/lib/python3.9/site-packages (from aiohttp->CodeProject-AI-SDK->-r requirements.txt (line 14)) (1.3.1)
Requirement already satisfied: attrs>=17.3.0 in ./bin/linux/python39/venv/lib/python3.9/site-packages (from aiohttp->CodeProject-AI-SDK->-r requirements.txt (line 14)) (24.2.0)
Requirement already satisfied: frozenlist>=1.1.1 in ./bin/linux/python39/venv/lib/python3.9/site-packages (from aiohttp->CodeProject-AI-SDK->-r requirements.txt (line 14)) (1.4.1)
Requirement already satisfied: multidict<7.0,>=4.5 in ./bin/linux/python39/venv/lib/python3.9/site-packages (from aiohttp->CodeProject-AI-SDK->-r requirements.txt (line 14)) (6.1.0)
Requirement already satisfied: yarl<2.0,>=1.0 in ./bin/linux/python39/venv/lib/python3.9/site-packages (from aiohttp->CodeProject-AI-SDK->-r requirements.txt (line 14)) (1.11.1)
Requirement already satisfied: async-timeout<5.0,>=4.0 in ./bin/linux/python39/venv/lib/python3.9/site-packages (from aiohttp->CodeProject-AI-SDK->-r requirements.txt (line 14)) (4.0.3)
Requirement already satisfied: lark-parser<0.8.0,>=0.7.1 in ./bin/linux/python39/venv/lib/python3.9/site-packages (from commentjson->CodeProject-AI-SDK->-r requirements.txt (line 14)) (0.7.8)
Requirement already satisfied: starlette<0.39.0,>=0.37.2 in ./bin/linux/python39/venv/lib/python3.9/site-packages (from fastapi->fastdeploy-python==1.4.2b0->-r requirements.txt (line 4)) (0.38.5)
Requirement already satisfied: pydantic!=1.8,!=1.8.1,!=2.0.0,!=2.0.1,!=2.1.0,<3.0.0,>=1.7.4 in ./bin/linux/python39/venv/lib/python3.9/site-packages (from fastapi->fastdeploy-python==1.4.2b0->-r requirements.txt (line 4)) (2.9.2)
Requirement already satisfied: typing-extensions>=4.8.0 in ./bin/linux/python39/venv/lib/python3.9/site-packages (from fastapi->fastdeploy-python==1.4.2b0->-r requirements.txt (line 4)) (4.12.2)
Requirement already satisfied: idna<4,>=2.5 in ./bin/linux/python39/venv/lib/python3.9/site-packages (from requests->fastdeploy-python==1.4.2b0->-r requirements.txt (line 4)) (3.10)
Requirement already satisfied: urllib3<3,>=1.21.1 in ./bin/linux/python39/venv/lib/python3.9/site-packages (from requests->fastdeploy-python==1.4.2b0->-r requirements.txt (line 4)) (2.2.3)
Requirement already satisfied: certifi>=2017.4.17 in ./bin/linux/python39/venv/lib/python3.9/site-packages (from requests->fastdeploy-python==1.4.2b0->-r requirements.txt (line 4)) (2024.8.30)
Requirement already satisfied: annotated-types>=0.6.0 in ./bin/linux/python39/venv/lib/python3.9/site-packages (from pydantic!=1.8,!=1.8.1,!=2.0.0,!=2.0.1,!=2.1.0,<3.0.0,>=1.7.4->fastapi->fastdeploy-python==1.4.2b0->-r requirements.txt (line 4)) (0.7.0)
Requirement already satisfied: pydantic-core==2.23.4 in ./bin/linux/python39/venv/lib/python3.9/site-packages (from pydantic!=1.8,!=1.8.1,!=2.0.0,!=2.0.1,!=2.1.0,<3.0.0,>=1.7.4->fastapi->fastdeploy-python==1.4.2b0->-r requirements.txt (line 4)) (2.23.4)
Requirement already satisfied: anyio<5,>=3.4.0 in ./bin/linux/python39/venv/lib/python3.9/site-packages (from starlette<0.39.0,>=0.37.2->fastapi->fastdeploy-python==1.4.2b0->-r requirements.txt (line 4)) (4.6.0)
Requirement already satisfied: sniffio>=1.1 in ./bin/linux/python39/venv/lib/python3.9/site-packages (from anyio<5,>=3.4.0->starlette<0.39.0,>=0.37.2->fastapi->fastdeploy-python==1.4.2b0->-r requirements.txt (line 4)) (1.3.1)
Requirement already satisfied: exceptiongroup>=1.0.2 in ./bin/linux/python39/venv/lib/python3.9/site-packages (from anyio<5,>=3.4.0->starlette<0.39.0,>=0.37.2->fastapi->fastdeploy-python==1.4.2b0->-r requirements.txt (line 4)) (1.2.2)
Downloading numpy-1.26.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (14.2 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 14.2/14.2 MB 11.1 MB/s eta 0:00:00
Downloading Pillow-9.5.0-cp39-cp39-manylinux_2_28_aarch64.whl (3.2 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.2/3.2 MB 11.4 MB/s eta 0:00:00
Installing collected packages: Pillow, numpy
Attempting uninstall: Pillow
Found existing installation: pillow 10.4.0
Uninstalling pillow-10.4.0:
Successfully uninstalled pillow-10.4.0
Attempting uninstall: numpy
Found existing installation: numpy 2.0.2
Uninstalling numpy-2.0.2:
Successfully uninstalled numpy-2.0.2
Successfully installed Pillow-9.5.0 numpy-1.26.4
AttributeError
appears to be fixed by manually running pip install -r requirements.txt
in the module's python environment.
Still getting the ModuleNotFoundError.
Some playing in the python repl and it seems the method for importing from module_logging must change.
(venv) root@857ed486c15c:/app/modules/ObjectDetectionYoloRKNN# python -i
Python 3.9.19 (main, Apr 6 2024, 17:57:55)
[GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import codeproject_ai_sdk
>>> import module_logging
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'module_logging'
>>>
(venv) root@857ed486c15c:/app/modules/ObjectDetectionYoloRKNN# python -i
Python 3.9.19 (main, Apr 6 2024, 17:57:55)
[GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from codeproject_ai_sdk.module_logging import LogMethod
>>> LogMethod
<enum 'LogMethod'>
>>>
And I'm assuming that this python virtual environment is important and actively used by the CPAI server to run the module in a sane/compatible python environment. If it's not, then the effort thus far is wasted.
My docker container bind mounts the modules
folder to a host folder /srv/ai-server/modules
. With this I can edit the code with the following patch, restart the module, and no error appear in the log.
--- objectdetection_fd_rknn.py.old 2024-09-24 00:54:33.836210697 +0000
+++ objectdetection_fd_rknn.py 2024-09-24 00:52:28.538719973 +0000
@@ -23,7 +23,7 @@
from numpy import array
from PIL import UnidentifiedImageError
-from module_logging import LogMethod
+from codeproject_ai_sdk.module_logging import LogMethod
from options import Options
# import fastdeploy as fd # rknn
Then used the CodeProject.AI Explorer link to test the RKNN Object Detection module. And it seems to work now. Logs from CPAI server.
21:08:54:Object Detection (YOLOv5 RKNN): Detecting using ipcam-dark-small
21:08:54:Response rec'd from Object Detection (YOLOv5 RKNN) command 'custom' (...1b6942) ['Found Person'] took 88ms
21:08:56:Object Detection (YOLOv5 RKNN): Detecting using ipcam-dark-small
21:08:56:Response rec'd from Object Detection (YOLOv5 RKNN) command 'custom' (...5df34e) ['Found Person'] took 82ms
21:08:58:Object Detection (YOLOv5 RKNN): Detecting using ipcam-dark-small
21:08:58:Response rec'd from Object Detection (YOLOv5 RKNN) command 'custom' (...3c47e9) ['Found Person'] took 60ms
Not sure whether the numpy
2.0.2 issue is a problem with the CPAI server install process. I haven't found any code in the module that tries to run pip install -r requirements.txt
and the changelog for the last release of CPAI server updates the docs for module installation, and it seems from there that the CPAI server will determine which requirements file to use if one better suited to the platform is available.
@ChrisMaunder should I be looking at the CPAI server code for module installation to figure out why the wrong version of numpy was installed?
The ModuleNotFoundError seems to be an issue with the module. Will follow up in it's issue tracker later.
Looking through SDK/Scripts/utils.sh
, it appears that the function installRequiredPythonPackages
only uses pip install -r requirements.txt
when the flag $oneStepPIP
is true
, otherwise, the packages are installed individually by the script to (I assume) facilitate logging of the progress of each python package installed.
The problem with this is the lack of version resolution among transitive dependencies. Take this log snippet from a recent reinstall of the RKNN Object Detector.
10:24:10:ObjectDetectionYoloRKNN: - Installing OpenCV, the Open source Computer Vision library... package name = 'opencv-python==4.5.3.56'Checking ...Check done...Installing opencv-python==4.5.3.56...Collecting opencv-python==4.5.3.56
10:24:10:ObjectDetectionYoloRKNN: Using cached opencv_python-4.5.3.56-cp39-cp39-manylinux2014_aarch64.whl.metadata (17 kB)
10:24:11:ObjectDetectionYoloRKNN: Collecting numpy>=1.19.3 (from opencv-python==4.5.3.56)
10:24:11:ObjectDetectionYoloRKNN: Using cached numpy-2.0.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.metadata (62 kB)
When the opencv_python
package is installed, it requires numpy>=1.19.3
(which numpy-2.0.2
satisfies) and immediately installs numpy-2.0.2
instead of a) recognizing that a later version requirement will require numpy<2
, b) recognizing there is a numpy
version (1.26) that satisfies both version restrictions, and c) installing the correct version of numpy
.
This would be an example of a "roll your own" solution failing to achieve the correct behavior already implemented by an existing tool.
Current work around for numpy<2
in CPAI Server Docker arm64.
--- setup.sh.orig 2024-09-26 15:47:54.805517844 +0000
+++ setup.sh 2024-09-26 15:48:08.531988124 +0000
@@ -677,7 +677,7 @@
# bad (and potentially unnneeded) module. Turning one-step off means you get a
# more granular set of error messages should things go wrong, and a nicer UX.
if [ "$inDocker" = true ]; then
- oneStepPIP=false
+ oneStepPIP=true
elif [ "$os" = "linux" ] || [ "$os" = "macos" ]; then
oneStepPIP=false
elif [ "$os" = "windows" ]; then
Note: still need to resolve the import error in the RKNN module wrt module_logging
separately.
There are two options here:
set oneStepPIP=true
at the start of the install.sh install script in the RKNN YOLO project and/orTurning on one-step will allow proper version resolution (but if one pacakge fails they all fail), or making the numpy package the first item with onestep=false means numpy<2 will be installed first, then everything else should follow. Except if a subsequent package has forced a 'numpy > 2' which I've not seen yet.
I'll try get a new release out in the next few days.
Area of Concern
Describe the bug Clicked install for module Object Detection Yolo v5 RKNN. Install proceeded, but failed to start module. Python runtime reports a traceback error (see below).
Expected behavior Expected Object Detection Yolo v5 RKNN to start and remain running and operational.
Screenshots If applicable, add screenshots to help explain your problem.
Your System (please complete the following information):
Additional context Logs for module installation. Python traceback is at the end of the logs. Reports two errors: AttributeError and ModuleNotFoundError.