From a6ad4ab185dad17134d3d2b1106c7a6ca57ec1bb Mon Sep 17 00:00:00 2001 From: Byeongman Lee Date: Wed, 31 Jul 2024 18:57:15 +0900 Subject: [PATCH] #306 Add onnx to dlc convert & Samsung Galaxy S24 Ultra device (#311) Co-authored-by: soyoung.ko --- .../converter & benchmarker/v2/onnx2dlc.py | 56 +++++++++++++++++++ netspresso/enums/device.py | 8 ++- netspresso/enums/model.py | 2 + netspresso/utils/file.py | 1 + 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 examples/converter & benchmarker/v2/onnx2dlc.py diff --git a/examples/converter & benchmarker/v2/onnx2dlc.py b/examples/converter & benchmarker/v2/onnx2dlc.py new file mode 100644 index 00000000..99526032 --- /dev/null +++ b/examples/converter & benchmarker/v2/onnx2dlc.py @@ -0,0 +1,56 @@ +from netspresso import NetsPresso +from netspresso.enums import DeviceName, Framework, DataType, SoftwareVersion + +### +# Available target frameworks for conversion with onnx models +# +# Framework.TENSORRT <-- For NVIDIA Devices +# Framework.OPENVINO <-- For Intel CPUs +# Framework.TENSORFLOW_LITE <-- For the devices like Raspberry Pi devices +# Framework.DRPAI <-- For Renesas Devices like RZ/V2M, RZ/V2L +# Framework.DLC <-- For GALAXY_S24_ULTRA +# + +### +# Available devices for Framework.DLC (target_framework) +# +# DeviceName.GALAXY_S24_ULTRA +# + +EMAIL = "YOUR_EMAIL" +PASSWORD = "YOUR_PASSWORD" + +netspresso = NetsPresso(email=EMAIL, password=PASSWORD) + +# 1. Declare converter +converter = netspresso.converter_v2() + +# 2. Set variables for convert +INPUT_MODEL_PATH = "./examples/sample_models/yolo-fastest.onnx" +OUTPUT_DIR = "./outputs/converted/DLC_GALAXY_S24_ULTRA" +TARGET_FRAMEWORK = Framework.DLC +TARGET_DEVICE_NAME = DeviceName.GALAXY_S24_ULTRA +TARGET_DATA_TYPE = DataType.FP32 +TARGET_SOFTWARE_VERSION = SoftwareVersion.SNPE_2_20 + +# 3. Run convert +conversion_task = converter.convert_model( + input_model_path=INPUT_MODEL_PATH, + output_dir=OUTPUT_DIR, + target_framework=TARGET_FRAMEWORK, + target_device_name=TARGET_DEVICE_NAME, + target_data_type=TARGET_DATA_TYPE, + target_software_version=TARGET_SOFTWARE_VERSION, +) +print(conversion_task) + +# 4. Declare benchmarker +benchmarker = netspresso.benchmarker_v2() + +# 5. Run benchmark +benchmark_task = benchmarker.benchmark_model( + input_model_path=conversion_task.converted_model_path, + target_device_name=TARGET_DEVICE_NAME, + target_software_version=TARGET_SOFTWARE_VERSION, +) +print(f"model inference latency: {benchmark_task.benchmark_result.latency} ms") diff --git a/netspresso/enums/device.py b/netspresso/enums/device.py index e5a24dc1..b3a2485a 100644 --- a/netspresso/enums/device.py +++ b/netspresso/enums/device.py @@ -27,6 +27,7 @@ class DeviceName(str, Enum): ARM_ETHOS_U_SERIES = "Arm Virtual Hardware Ethos-U Series" NXP_iMX93 = "nxp_imx93_ethos_u65" ARDUINO_NICLA_VISION = "arduino_nicla_vision" + GALAXY_S24_ULTRA = "Samsung_Galaxy-S24-Ultra_Snapdragon-8-Gen3" @classmethod def create_literal(cls): @@ -52,7 +53,8 @@ def create_literal(cls): "Ensemble-E7-DevKit-Gen2", "Arm Virtual Hardware Ethos-U Series", "nxp_imx93_ethos_u65", - "arduino_nicla_vision" + "arduino_nicla_vision", + "Samsung_Galaxy-S24-Ultra_Snapdragon-8-Gen3" ] JETSON_DEVICES = [ @@ -98,10 +100,11 @@ class SoftwareVersion(str, Enum): JETPACK_5_0_1 = "5.0.1-b118" JETPACK_5_0_2 = "5.0.2-b231" JETPACK_6_0 = "6.0-b52" + SNPE_2_20 = "2.20.0" @classmethod def create_literal(cls): - return Literal["4.4.1-b50", "4.6-b199", "5.0.1-b118", "5.0.2-b231", "6.0-b52"] + return Literal["4.4.1-b50", "4.6-b199", "5.0.1-b118", "5.0.2-b231", "6.0-b52", "2.20.0"] class DisplaySoftwareVersion(str, Enum): @@ -110,6 +113,7 @@ class DisplaySoftwareVersion(str, Enum): JETPACK_5_0_1 = "Jetpack 5.0.1" JETPACK_5_0_2 = "Jetpack 5.0.2" JETPACK_6_0 = "Jetpack 6.0" + SNPE_2_20 = "SNPE 2.20.0" class HardwareType(str, Enum): diff --git a/netspresso/enums/model.py b/netspresso/enums/model.py index 2ac039a7..812214de 100644 --- a/netspresso/enums/model.py +++ b/netspresso/enums/model.py @@ -11,6 +11,7 @@ class Framework(str, Enum): OPENVINO = "openvino" TENSORFLOW_LITE = "tensorflow_lite" DRPAI = "drpai" + DLC = "dlc" @classmethod def create_compressor_literal(cls): @@ -26,6 +27,7 @@ def create_launcher_literal(cls): "drpai", "keras", "saved_model", + "dlc" ] diff --git a/netspresso/utils/file.py b/netspresso/utils/file.py index b62a5129..7e0abbee 100644 --- a/netspresso/utils/file.py +++ b/netspresso/utils/file.py @@ -15,6 +15,7 @@ "drpai": ".zip", "openvino": ".zip", "tensorrt": ".trt", + "dlc": ".dlc" }