From 1f6a876bdc9ca9ec311fa520627118558b921185 Mon Sep 17 00:00:00 2001 From: Zheng-Bicheng Date: Wed, 13 Nov 2024 10:40:51 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20FP32=20=E5=88=86?= =?UTF-8?q?=E7=B1=BB=E6=A8=A1=E5=9E=8B=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- configs/LZ-MobileNetV3_fp32.yaml | 27 ++++++++++++ .../python/test_classification.py | 42 ++++++++++++------- 2 files changed, 55 insertions(+), 14 deletions(-) create mode 100644 configs/LZ-MobileNetV3_fp32.yaml diff --git a/configs/LZ-MobileNetV3_fp32.yaml b/configs/LZ-MobileNetV3_fp32.yaml new file mode 100644 index 0000000..42ef5ac --- /dev/null +++ b/configs/LZ-MobileNetV3_fp32.yaml @@ -0,0 +1,27 @@ +load_onnx: + inputs: + - x + input_size_list: + - + - 1 + - 3 + - 224 + - 224 + outputs: + - Add.53 + +config: + # BGR + mean: + - 0.406 + - 0.456 + - 0.485 + std: + - 0.225 + - 0.224 + - 0.229 + type: "fp32" + +build: + do_quantization: True + dataset: ./dataset.txt \ No newline at end of file diff --git a/example/vision/classification/python/test_classification.py b/example/vision/classification/python/test_classification.py index 78a2fa0..8199e86 100644 --- a/example/vision/classification/python/test_classification.py +++ b/example/vision/classification/python/test_classification.py @@ -1,21 +1,10 @@ -from lockzhiner_vision_module.cv2 import VideoCapture +from lockzhiner_vision_module.cv2 import VideoCapture, imread from lockzhiner_vision_module.vision import PaddleClas import time import sys -if __name__ == "__main__": - args = sys.argv - if len(args) != 2: - print( - "Need model path. Example: python test_classification.py LZ-MobileNetV3.rknn" - ) - exit(1) - - model = PaddleClas() - if model.initialize(args[1]) is False: - print("Failed to initialize PaddleClas") - exit(1) +def predict_video(cls_model): video_capture = VideoCapture() if video_capture.open(0) is False: print("Failed to open capture") @@ -30,9 +19,34 @@ if __name__ == "__main__": continue start_time = time.time() - result = model.predict(mat) + result = cls_model.predict(mat) end_time = time.time() total_time_ms += end_time - start_time read_index += 1 print(result.label_id, result.score) print(f"FPS is {1.0 / (total_time_ms/read_index)}") + + +def predict_image(cls_model, image_path): + image = imread(image_path) + result = cls_model.predict(image) + print(result.label_id, result.score) + + +if __name__ == "__main__": + args = sys.argv + if len(args) < 2: + print( + "Need model path. Example: python test_classification.py LZ-MobileNetV3.rknn" + ) + exit(1) + + model = PaddleClas() + if model.initialize(args[1]) is False: + print("Failed to initialize PaddleClas") + exit(1) + + if len(args) == 2: + predict_video(model) + elif len(args) == 3: + predict_image(model, args[2]) \ No newline at end of file -- Gitee From b0bea24f75d2fd61148d488f0284865727e9d3a6 Mon Sep 17 00:00:00 2001 From: Zheng-Bicheng Date: Wed, 13 Nov 2024 10:48:30 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BD=BF=E7=94=A8=20RKNN?= =?UTF-8?q?=20Toolkit2=20=E8=BD=AC=E6=8D=A2=E6=A8=A1=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- configs/LZ-MobileNetV3.yaml | 6 +++--- configs/LZ-MobileNetV3_fp32.yaml | 27 ------------------------- configs/LZ-Picodet.yaml | 20 +++++++++---------- configs/LZ-Picodet_fp32.yaml | 34 -------------------------------- 4 files changed, 13 insertions(+), 74 deletions(-) delete mode 100644 configs/LZ-MobileNetV3_fp32.yaml delete mode 100644 configs/LZ-Picodet_fp32.yaml diff --git a/configs/LZ-MobileNetV3.yaml b/configs/LZ-MobileNetV3.yaml index 563dca5..42ef5ac 100644 --- a/configs/LZ-MobileNetV3.yaml +++ b/configs/LZ-MobileNetV3.yaml @@ -8,7 +8,7 @@ load_onnx: - 224 - 224 outputs: - - DequantizeLinear.881 + - Add.53 config: # BGR @@ -23,5 +23,5 @@ config: type: "fp32" build: - do_quantization: false - dataset: \ No newline at end of file + do_quantization: True + dataset: ./dataset.txt \ No newline at end of file diff --git a/configs/LZ-MobileNetV3_fp32.yaml b/configs/LZ-MobileNetV3_fp32.yaml deleted file mode 100644 index 42ef5ac..0000000 --- a/configs/LZ-MobileNetV3_fp32.yaml +++ /dev/null @@ -1,27 +0,0 @@ -load_onnx: - inputs: - - x - input_size_list: - - - - 1 - - 3 - - 224 - - 224 - outputs: - - Add.53 - -config: - # BGR - mean: - - 0.406 - - 0.456 - - 0.485 - std: - - 0.225 - - 0.224 - - 0.229 - type: "fp32" - -build: - do_quantization: True - dataset: ./dataset.txt \ No newline at end of file diff --git a/configs/LZ-Picodet.yaml b/configs/LZ-Picodet.yaml index e7ac15f..6eaa42a 100644 --- a/configs/LZ-Picodet.yaml +++ b/configs/LZ-Picodet.yaml @@ -8,14 +8,14 @@ load_onnx: - 320 - 320 outputs: - - DequantizeLinear.1705 - - DequantizeLinear.1707 - - DequantizeLinear.1619 - - DequantizeLinear.1621 - - DequantizeLinear.1533 - - DequantizeLinear.1535 - - DequantizeLinear.1445 - - DequantizeLinear.1447 + - sigmoid_0.tmp_0 + - split_0.tmp_1 + - sigmoid_1.tmp_0 + - split_1.tmp_1 + - sigmoid_2.tmp_0 + - split_2.tmp_1 + - sigmoid_3.tmp_0 + - split_3.tmp_1 config: # BGR @@ -30,5 +30,5 @@ config: type: "fp32" build: - do_quantization: false - dataset: \ No newline at end of file + do_quantization: True + dataset: ./dataset.txt \ No newline at end of file diff --git a/configs/LZ-Picodet_fp32.yaml b/configs/LZ-Picodet_fp32.yaml deleted file mode 100644 index 4cd21d4..0000000 --- a/configs/LZ-Picodet_fp32.yaml +++ /dev/null @@ -1,34 +0,0 @@ -load_onnx: - inputs: - - image - input_size_list: - - - - 1 - - 3 - - 320 - - 320 - outputs: - - sigmoid_0.tmp_0 - - split_0.tmp_1 - - sigmoid_1.tmp_0 - - split_1.tmp_1 - - sigmoid_2.tmp_0 - - split_2.tmp_1 - - sigmoid_3.tmp_0 - - split_3.tmp_1 - -config: - # BGR - mean: - - 0.406 - - 0.456 - - 0.485 - std: - - 0.225 - - 0.224 - - 0.229 - type: "fp32" - -build: - do_quantization: True - dataset: ./dataset.txt \ No newline at end of file -- Gitee