From d10147f478b621cbd0c1a3c51431b793a95a99be Mon Sep 17 00:00:00 2001 From: yoni13 Date: Sat, 11 Jan 2025 15:19:53 +0800 Subject: [PATCH] Handling Import and file not found Error for non-arm devices. --- machine-learning/rknn/rknnpool.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/machine-learning/rknn/rknnpool.py b/machine-learning/rknn/rknnpool.py index 7963139760..cedbec4dd2 100644 --- a/machine-learning/rknn/rknnpool.py +++ b/machine-learning/rknn/rknnpool.py @@ -2,22 +2,24 @@ # Following Apache License 2.0 from queue import Queue -from rknnlite.api import RKNNLite from concurrent.futures import ThreadPoolExecutor, as_completed supported_socs = ["rk3566","rk3568","rk3588"] -with open('/proc/device-tree/compatible') as f: - # Keep in mind that this is not in container by default. - # and this way of checking can't check if the rknpu driver is running or not. - device_compatible_str = f.read() - for soc in supported_socs: - if soc in device_compatible_str: - is_available = True - break - else: - is_available = False - +try: + from rknn.api import RKNNLite + with open('/proc/device-tree/compatible') as f: + # Keep in mind that this is not in container by default. + # and this way of checking can't check if the rknpu driver is running or not. + device_compatible_str = f.read() + for soc in supported_socs: + if soc in device_compatible_str: + is_available = True + break + else: + is_available = False +except (FileNotFoundError, ImportError): + is_available = False def initRKNN(rknnModel="./rknnModel/yolov5s.rknn", id=0):