From 1e7b430ae096bb972d57a8d33751bcaf6ed3c23a Mon Sep 17 00:00:00 2001 From: samfreund Date: Fri, 11 Jul 2025 15:12:25 -0500 Subject: [PATCH 01/13] add rubik conversion notebook --- scripts/Rubik-Tflite-Conversion.ipynb | 91 +++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 scripts/Rubik-Tflite-Conversion.ipynb diff --git a/scripts/Rubik-Tflite-Conversion.ipynb b/scripts/Rubik-Tflite-Conversion.ipynb new file mode 100644 index 0000000000..4ba87f5038 --- /dev/null +++ b/scripts/Rubik-Tflite-Conversion.ipynb @@ -0,0 +1,91 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Convert PyTorch Model to Modified TFlite for Rubik Pi 3\n", + "\n", + "If you're running this notebook on google colab, you'll need to upload your model file to the colab environment. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# This installs Python package\n", + "!pip install qai-hub-models[yolov8-det-quantized]\n", + "# sets up AI Hub enviroment \n", + "!qai-hub configure --api_token \n", + "# Converts the model to be ran on RB3Gen2\n", + "!python -m qai_hub_models.models.yolov8_det_quantized.export --device=\"RB3 Gen 2 (Proxy)\" --ckpt-name /YOUR/WEIGHTS/FILE\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To retrieve the quanatization parameters from the model the easiest way is the following:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import tensorflow as tf\n", + "\n", + "# Load the TFLite model\n", + "interpreter = tf.lite.Interpreter(model_path=\"PATH_TO_FILE_FROM_AIHUB\")\n", + "interpreter.allocate_tensors()\n", + "\n", + "# Get output tensor details\n", + "output_details = interpreter.get_output_details()\n", + "\n", + "q_scales = []\n", + "q_zero_points = []\n", + "\n", + "for output in output_details:\n", + " params = output['quantization_parameters']\n", + "\n", + " # Check if the tensor is quantized\n", + " if output['quantization_parameters']['quantized_dimension'] == 0: # Per-tensor quantization\n", + " scale = params['scales'][0] if params['scales'].size > 0 else 1.0\n", + " zero_point = params['zero_points'][0] if params['zero_points'].size > 0 else 0.0\n", + " else:\n", + " # Handle per-channel quantization (unlikely for YOLOv8)\n", + " scale = 1.0\n", + " zero_point = 0.0\n", + "\n", + " q_scales.append(scale)\n", + " q_zero_points.append(float(zero_point))\n", + "\n", + "# Format the constants\n", + "print(f'YOLOv8,q-offsets=<{\", \".join(map(str, q_zero_points))}>, q-scales=<{\", \".join(map(str, q_scales))}>')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Modified from https://github.com/ramalamadingdong/yolo-rb3gen2-trainer/blob/main/AI_Hub_Quanitization_RB3Gen2.ipynb" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "name": "python", + "version": "3.11.7" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 5721f84eae90f9caa439578586a45606689f7f0f Mon Sep 17 00:00:00 2001 From: Sam948-byte Date: Mon, 14 Jul 2025 00:45:34 -0500 Subject: [PATCH 02/13] new and improved script --- scripts/AI_Hub_Quanitization_RB3Gen2.ipynb | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 scripts/AI_Hub_Quanitization_RB3Gen2.ipynb diff --git a/scripts/AI_Hub_Quanitization_RB3Gen2.ipynb b/scripts/AI_Hub_Quanitization_RB3Gen2.ipynb new file mode 100644 index 0000000000..1f78d01e35 --- /dev/null +++ b/scripts/AI_Hub_Quanitization_RB3Gen2.ipynb @@ -0,0 +1,63 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "L-D9dgnL4c-Q" + }, + "source": [ + "## YOLO to Rubik TFlite Conversion\n", + "This notebook can be run on colab.\n", + "\n", + "Prior to running the notebook, it is necessary to make an account on [Qualcomm's AI Hub](https://app.aihub.qualcomm.com/account/), and obtain your API key.\n", + "\n", + "You should also have a PyTorch model (ending in `.pt`) that's been uploaded to the runtime that you intend to convert.\n", + "\n", + "Please note that your API key will be listed in the output, and should therefore be redacted if the output is shared." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "id": "4id9hP_l4c-R", + "outputId": "2da3e1de-3376-496a-e508-8d45e9b3038b" + }, + "outputs": [], + "source": [ + "AIHUB_API_KEY = \"hplrp9s6eecuvvk8vvu7ngsgdwe62n7ofn0svw7b\"\n", + "PATH_TO_WEIGHTS = \"/content/best.pt\"\n", + "# Options are yolov8, yolov11\n", + "YOLO_VERSION = \"yolov11\"\n", + "# This installs Python package\n", + "!pip install \"qai-hub-models[{YOLO_VERSION}-det-quantized]\"\n", + "!pip install fiftyone\n", + "!pip install ultralytics\n", + "# sets up AI Hub enviroment\n", + "!qai-hub configure --api_token {AIHUB_API_KEY}\n", + "\n", + "# Converts the model to be ran on RB3Gen2\n", + "!python -m \"qai_hub_models.models.{YOLO_VERSION}_det.export\" --quantize w8a8 --device=\"RB3 Gen 2 (Proxy)\" --ckpt-name {PATH_TO_WEIGHTS} --device-os linux --target-runtime tflite" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python", + "version": "3.11.7" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} From 37f847f31ff13865d0cb2d0455f22ef763a6d34e Mon Sep 17 00:00:00 2001 From: Sam948-byte Date: Mon, 14 Jul 2025 16:50:44 -0500 Subject: [PATCH 03/13] RKNN conversion --- scripts/yolo_to_rknn.ipynb | 156 +++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 scripts/yolo_to_rknn.ipynb diff --git a/scripts/yolo_to_rknn.ipynb b/scripts/yolo_to_rknn.ipynb new file mode 100644 index 0000000000..8daa8419da --- /dev/null +++ b/scripts/yolo_to_rknn.ipynb @@ -0,0 +1,156 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "578NGV7h3aNh" + }, + "source": [ + "#YOLO to RKNN" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "axJXpbXE3aNi" + }, + "outputs": [], + "source": [ + "PATH_TO_MODEL=\"PATH TO MODEL\"\n", + "# Options are yolov5, yolov8, or yolo11\n", + "YOLO_VERSION = \"yolov8\"\n", + "\n", + "root_path = '/content'\n", + "%cd {root_path}\n", + "import os\n", + "root_path = os.getcwd()\n", + "\n", + "!git clone https://github.com/airockchip/ultralytics_{YOLO_VERSION}\n", + "%cd ultralytics_{YOLO_VERSION}\n", + "\n", + "!pip install -e .\n", + "\n", + "from IPython import display\n", + "display.clear_output()\n", + "\n", + "import ultralytics\n", + "ultralytics.checks()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "aCc2dQtQ3aNl" + }, + "source": [ + "### Install RKNN Toolkit 2\n", + "\n", + "Note: it may be necessary to download a different wheel depending on your python version." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "6ElrnSYH3aNl" + }, + "outputs": [], + "source": [ + "!wget https://github.com/rockchip-linux/rknn-toolkit2/raw/1f4415eafe8f578787822fc836f38df3ef3b5627/rknn-toolkit2/packages/rknn_toolkit2-1.6.0+81f21f4d-cp311-cp311-linux_x86_64.whl\n", + "!pip install rknn_toolkit2-1.6.0+81f21f4d-cp311-cp311-linux_x86_64.whl" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "5kjkeL-k3aNl" + }, + "source": [ + "## Export to ONNX\n", + "This is an intermediate step between the PyTorch model and the RKNN model." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "3S6xT1vJ3aNl" + }, + "outputs": [], + "source": [ + "%cd {root_path}\n", + "!yolo mode=export format=rknn model={PATH_TO_MODEL}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "qEYZWCr43aNl" + }, + "outputs": [], + "source": [ + "%cd {root_path}\n", + "!git clone https://github.com/airockchip/rknn_model_zoo/\n", + "%cd rknn_model_zoo\n", + "!git checkout bad6c73" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "2Xo3XJaB3aNl" + }, + "source": [ + "## Export to RKNN" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "H13l4tVO3aNl" + }, + "outputs": [], + "source": [ + "%cd {root_path}/rknn_model_zoo/examples/{YOLO_VERSION}/python\n", + "onnx_path = PATH_TO_MODEL.replace('.pt', '.onnx')\n", + "!python convert.py {onnx_path} rk3588 i8 {root_path}/out.rknn" + ] + } + ], + "metadata": { + "accelerator": "GPU", + "colab": { + "gpuType": "T4", + "provenance": [] + }, + "kaggle": { + "accelerator": "nvidiaTeslaT4", + "dataSources": [], + "isGpuEnabled": true, + "isInternetEnabled": true, + "language": "python", + "sourceType": "notebook" + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.12" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} From d1a87950313127eb27856ea7c88bdc9bbb0221b4 Mon Sep 17 00:00:00 2001 From: Sam948-byte Date: Tue, 22 Jul 2025 18:01:05 -0500 Subject: [PATCH 04/13] update conversion scripts --- scripts/AI_Hub_Quanitization_RB3Gen2.ipynb | 63 ---------------------- scripts/Rubik-Tflite-Conversion.ipynb | 53 +++--------------- 2 files changed, 7 insertions(+), 109 deletions(-) delete mode 100644 scripts/AI_Hub_Quanitization_RB3Gen2.ipynb diff --git a/scripts/AI_Hub_Quanitization_RB3Gen2.ipynb b/scripts/AI_Hub_Quanitization_RB3Gen2.ipynb deleted file mode 100644 index 1f78d01e35..0000000000 --- a/scripts/AI_Hub_Quanitization_RB3Gen2.ipynb +++ /dev/null @@ -1,63 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "id": "L-D9dgnL4c-Q" - }, - "source": [ - "## YOLO to Rubik TFlite Conversion\n", - "This notebook can be run on colab.\n", - "\n", - "Prior to running the notebook, it is necessary to make an account on [Qualcomm's AI Hub](https://app.aihub.qualcomm.com/account/), and obtain your API key.\n", - "\n", - "You should also have a PyTorch model (ending in `.pt`) that's been uploaded to the runtime that you intend to convert.\n", - "\n", - "Please note that your API key will be listed in the output, and should therefore be redacted if the output is shared." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/", - "height": 1000 - }, - "id": "4id9hP_l4c-R", - "outputId": "2da3e1de-3376-496a-e508-8d45e9b3038b" - }, - "outputs": [], - "source": [ - "AIHUB_API_KEY = \"hplrp9s6eecuvvk8vvu7ngsgdwe62n7ofn0svw7b\"\n", - "PATH_TO_WEIGHTS = \"/content/best.pt\"\n", - "# Options are yolov8, yolov11\n", - "YOLO_VERSION = \"yolov11\"\n", - "# This installs Python package\n", - "!pip install \"qai-hub-models[{YOLO_VERSION}-det-quantized]\"\n", - "!pip install fiftyone\n", - "!pip install ultralytics\n", - "# sets up AI Hub enviroment\n", - "!qai-hub configure --api_token {AIHUB_API_KEY}\n", - "\n", - "# Converts the model to be ran on RB3Gen2\n", - "!python -m \"qai_hub_models.models.{YOLO_VERSION}_det.export\" --quantize w8a8 --device=\"RB3 Gen 2 (Proxy)\" --ckpt-name {PATH_TO_WEIGHTS} --device-os linux --target-runtime tflite" - ] - } - ], - "metadata": { - "colab": { - "provenance": [] - }, - "kernelspec": { - "display_name": "Python 3", - "name": "python3" - }, - "language_info": { - "name": "python", - "version": "3.11.7" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} diff --git a/scripts/Rubik-Tflite-Conversion.ipynb b/scripts/Rubik-Tflite-Conversion.ipynb index 4ba87f5038..d08858fa2a 100644 --- a/scripts/Rubik-Tflite-Conversion.ipynb +++ b/scripts/Rubik-Tflite-Conversion.ipynb @@ -4,9 +4,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Convert PyTorch Model to Modified TFlite for Rubik Pi 3\n", + "## YOLO to Rubik TFlite Conversion\n", + "This notebook can be run on colab.\n", "\n", - "If you're running this notebook on google colab, you'll need to upload your model file to the colab environment. " + "Prior to running the notebook, it is necessary to make an account on [Qualcomm's AI Hub](https://app.aihub.qualcomm.com/account/), and obtain your API key.\n", + "\n", + "You should also have a PyTorch model (ending in `.pt`) that's been uploaded to the runtime that you intend to convert.\n", + "\n", + "Please note that your API key will be listed in the output, and should therefore be redacted if the output is shared." ] }, { @@ -23,50 +28,6 @@ "!python -m qai_hub_models.models.yolov8_det_quantized.export --device=\"RB3 Gen 2 (Proxy)\" --ckpt-name /YOUR/WEIGHTS/FILE\n" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "To retrieve the quanatization parameters from the model the easiest way is the following:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import tensorflow as tf\n", - "\n", - "# Load the TFLite model\n", - "interpreter = tf.lite.Interpreter(model_path=\"PATH_TO_FILE_FROM_AIHUB\")\n", - "interpreter.allocate_tensors()\n", - "\n", - "# Get output tensor details\n", - "output_details = interpreter.get_output_details()\n", - "\n", - "q_scales = []\n", - "q_zero_points = []\n", - "\n", - "for output in output_details:\n", - " params = output['quantization_parameters']\n", - "\n", - " # Check if the tensor is quantized\n", - " if output['quantization_parameters']['quantized_dimension'] == 0: # Per-tensor quantization\n", - " scale = params['scales'][0] if params['scales'].size > 0 else 1.0\n", - " zero_point = params['zero_points'][0] if params['zero_points'].size > 0 else 0.0\n", - " else:\n", - " # Handle per-channel quantization (unlikely for YOLOv8)\n", - " scale = 1.0\n", - " zero_point = 0.0\n", - "\n", - " q_scales.append(scale)\n", - " q_zero_points.append(float(zero_point))\n", - "\n", - "# Format the constants\n", - "print(f'YOLOv8,q-offsets=<{\", \".join(map(str, q_zero_points))}>, q-scales=<{\", \".join(map(str, q_scales))}>')" - ] - }, { "cell_type": "markdown", "metadata": {}, From e059b88174fdc81d56db8b71c9fb6334bf031a94 Mon Sep 17 00:00:00 2001 From: Sam948-byte Date: Sat, 26 Jul 2025 23:57:23 -0500 Subject: [PATCH 05/13] add numpy fix --- scripts/Rubik-Tflite-Conversion.ipynb | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/scripts/Rubik-Tflite-Conversion.ipynb b/scripts/Rubik-Tflite-Conversion.ipynb index d08858fa2a..2f4922faa4 100644 --- a/scripts/Rubik-Tflite-Conversion.ipynb +++ b/scripts/Rubik-Tflite-Conversion.ipynb @@ -4,7 +4,34 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## YOLO to Rubik TFlite Conversion\n", + "## YOLO to Rubik TFlite Conversion" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### For Colab users only\n", + "\n", + "Google Colab comes with an incompatible version of Numpy installed. To fix this, please run the following cells below and **restart your session** when prompted." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%pip uninstall numpy -y\n", + "%pip install numpy>=1.23.0,<2.0.0" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Requirements\n", + "\n", "This notebook can be run on colab.\n", "\n", "Prior to running the notebook, it is necessary to make an account on [Qualcomm's AI Hub](https://app.aihub.qualcomm.com/account/), and obtain your API key.\n", From cc8a61b5e61013816d516ff059abb880572c5c87 Mon Sep 17 00:00:00 2001 From: samfreund Date: Tue, 5 Aug 2025 18:52:24 -0500 Subject: [PATCH 06/13] rename --- ...onversion.ipynb => rubik_conversion.ipynb} | 0 scripts/yolo_to_rknn.ipynb | 156 ------------------ 2 files changed, 156 deletions(-) rename scripts/{Rubik-Tflite-Conversion.ipynb => rubik_conversion.ipynb} (100%) delete mode 100644 scripts/yolo_to_rknn.ipynb diff --git a/scripts/Rubik-Tflite-Conversion.ipynb b/scripts/rubik_conversion.ipynb similarity index 100% rename from scripts/Rubik-Tflite-Conversion.ipynb rename to scripts/rubik_conversion.ipynb diff --git a/scripts/yolo_to_rknn.ipynb b/scripts/yolo_to_rknn.ipynb deleted file mode 100644 index 8daa8419da..0000000000 --- a/scripts/yolo_to_rknn.ipynb +++ /dev/null @@ -1,156 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "id": "578NGV7h3aNh" - }, - "source": [ - "#YOLO to RKNN" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "axJXpbXE3aNi" - }, - "outputs": [], - "source": [ - "PATH_TO_MODEL=\"PATH TO MODEL\"\n", - "# Options are yolov5, yolov8, or yolo11\n", - "YOLO_VERSION = \"yolov8\"\n", - "\n", - "root_path = '/content'\n", - "%cd {root_path}\n", - "import os\n", - "root_path = os.getcwd()\n", - "\n", - "!git clone https://github.com/airockchip/ultralytics_{YOLO_VERSION}\n", - "%cd ultralytics_{YOLO_VERSION}\n", - "\n", - "!pip install -e .\n", - "\n", - "from IPython import display\n", - "display.clear_output()\n", - "\n", - "import ultralytics\n", - "ultralytics.checks()" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "aCc2dQtQ3aNl" - }, - "source": [ - "### Install RKNN Toolkit 2\n", - "\n", - "Note: it may be necessary to download a different wheel depending on your python version." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "6ElrnSYH3aNl" - }, - "outputs": [], - "source": [ - "!wget https://github.com/rockchip-linux/rknn-toolkit2/raw/1f4415eafe8f578787822fc836f38df3ef3b5627/rknn-toolkit2/packages/rknn_toolkit2-1.6.0+81f21f4d-cp311-cp311-linux_x86_64.whl\n", - "!pip install rknn_toolkit2-1.6.0+81f21f4d-cp311-cp311-linux_x86_64.whl" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "5kjkeL-k3aNl" - }, - "source": [ - "## Export to ONNX\n", - "This is an intermediate step between the PyTorch model and the RKNN model." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "3S6xT1vJ3aNl" - }, - "outputs": [], - "source": [ - "%cd {root_path}\n", - "!yolo mode=export format=rknn model={PATH_TO_MODEL}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "qEYZWCr43aNl" - }, - "outputs": [], - "source": [ - "%cd {root_path}\n", - "!git clone https://github.com/airockchip/rknn_model_zoo/\n", - "%cd rknn_model_zoo\n", - "!git checkout bad6c73" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "2Xo3XJaB3aNl" - }, - "source": [ - "## Export to RKNN" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "H13l4tVO3aNl" - }, - "outputs": [], - "source": [ - "%cd {root_path}/rknn_model_zoo/examples/{YOLO_VERSION}/python\n", - "onnx_path = PATH_TO_MODEL.replace('.pt', '.onnx')\n", - "!python convert.py {onnx_path} rk3588 i8 {root_path}/out.rknn" - ] - } - ], - "metadata": { - "accelerator": "GPU", - "colab": { - "gpuType": "T4", - "provenance": [] - }, - "kaggle": { - "accelerator": "nvidiaTeslaT4", - "dataSources": [], - "isGpuEnabled": true, - "isInternetEnabled": true, - "language": "python", - "sourceType": "notebook" - }, - "kernelspec": { - "display_name": "Python 3", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.12" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} From 77aa3358c8a45979355bfefd3ef158e3d39f8efb Mon Sep 17 00:00:00 2001 From: Sam Freund Date: Tue, 5 Aug 2025 19:03:36 -0500 Subject: [PATCH 07/13] Update rubik notebook for latest QC script --- scripts/rubik_conversion.ipynb | 177 +++++++++++++++++++-------------- 1 file changed, 101 insertions(+), 76 deletions(-) diff --git a/scripts/rubik_conversion.ipynb b/scripts/rubik_conversion.ipynb index 2f4922faa4..0c2b357b22 100644 --- a/scripts/rubik_conversion.ipynb +++ b/scripts/rubik_conversion.ipynb @@ -1,79 +1,104 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## YOLO to Rubik TFlite Conversion" - ] + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "1tMAqVl4p58r" + }, + "source": [ + "## YOLO to Rubik TFlite Conversion" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "19sCXrDSp58s" + }, + "source": [ + "#### For Colab users only\n", + "\n", + "Google Colab comes with an incompatible version of Numpy installed. To fix this, please run the following cells below and **restart your session** when prompted." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 359 + }, + "id": "DJdbSRRjp58s", + "outputId": "d5e14694-d18d-4ad2-c596-89cc19e2333e" + }, + "outputs": [], + "source": [ + "%pip uninstall numpy -y\n", + "%pip install \"numpy>=1.23.0,<2.0.0\"" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "nAbygyUYp58s" + }, + "source": [ + "#### Requirements\n", + "\n", + "This notebook can be run on colab.\n", + "\n", + "Prior to running the notebook, it is necessary to make an account on [Qualcomm's AI Hub](https://app.aihub.qualcomm.com/account/), and obtain your API key.\n", + "\n", + "You should also have a PyTorch model (ending in `.pt`) that's been uploaded to the runtime that you intend to convert.\n", + "\n", + "Please note that your API key will be listed in the output, and should therefore be redacted if the output is shared." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "id": "aX3JcSFKp58s", + "outputId": "f2cdadd2-c448-4d8c-c681-c19decef7f3e" + }, + "outputs": [], + "source": [ + "# This installs Python package\n", + "!pip install qai-hub-models[yolov8_det]\n", + "# sets up AI Hub enviroment\n", + "!qai-hub configure --api_token \n", + "# Converts the model to be ran on RB3Gen2\n", + "!python -m qai_hub_models.models.yolov8_det.export --quantize w8a8 --device=\"RB3 Gen 2 (Proxy)\" --ckpt-name /PATH/TO/WEIGHTS --device-os linux --target-runtime tflite\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "0I2cXQO4p58s" + }, + "source": [ + "Modified from https://github.com/ramalamadingdong/yolo-rb3gen2-trainer/blob/main/AI_Hub_Quanitization_RB3Gen2.ipynb" + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "name": "python", + "version": "3.11.7" + } }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### For Colab users only\n", - "\n", - "Google Colab comes with an incompatible version of Numpy installed. To fix this, please run the following cells below and **restart your session** when prompted." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "%pip uninstall numpy -y\n", - "%pip install numpy>=1.23.0,<2.0.0" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Requirements\n", - "\n", - "This notebook can be run on colab.\n", - "\n", - "Prior to running the notebook, it is necessary to make an account on [Qualcomm's AI Hub](https://app.aihub.qualcomm.com/account/), and obtain your API key.\n", - "\n", - "You should also have a PyTorch model (ending in `.pt`) that's been uploaded to the runtime that you intend to convert.\n", - "\n", - "Please note that your API key will be listed in the output, and should therefore be redacted if the output is shared." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# This installs Python package\n", - "!pip install qai-hub-models[yolov8-det-quantized]\n", - "# sets up AI Hub enviroment \n", - "!qai-hub configure --api_token \n", - "# Converts the model to be ran on RB3Gen2\n", - "!python -m qai_hub_models.models.yolov8_det_quantized.export --device=\"RB3 Gen 2 (Proxy)\" --ckpt-name /YOUR/WEIGHTS/FILE\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Modified from https://github.com/ramalamadingdong/yolo-rb3gen2-trainer/blob/main/AI_Hub_Quanitization_RB3Gen2.ipynb" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "name": "python", - "version": "3.11.7" - } - }, - "nbformat": 4, - "nbformat_minor": 2 + "nbformat": 4, + "nbformat_minor": 0 } From ddefafd17ffe88944890532c3cb571e5c03b2534 Mon Sep 17 00:00:00 2001 From: samfreund Date: Wed, 6 Aug 2025 19:11:05 -0500 Subject: [PATCH 08/13] remove numpy fix --- scripts/rubik_conversion.ipynb | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/scripts/rubik_conversion.ipynb b/scripts/rubik_conversion.ipynb index 0c2b357b22..d868433199 100644 --- a/scripts/rubik_conversion.ipynb +++ b/scripts/rubik_conversion.ipynb @@ -9,34 +9,6 @@ "## YOLO to Rubik TFlite Conversion" ] }, - { - "cell_type": "markdown", - "metadata": { - "id": "19sCXrDSp58s" - }, - "source": [ - "#### For Colab users only\n", - "\n", - "Google Colab comes with an incompatible version of Numpy installed. To fix this, please run the following cells below and **restart your session** when prompted." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/", - "height": 359 - }, - "id": "DJdbSRRjp58s", - "outputId": "d5e14694-d18d-4ad2-c596-89cc19e2333e" - }, - "outputs": [], - "source": [ - "%pip uninstall numpy -y\n", - "%pip install \"numpy>=1.23.0,<2.0.0\"" - ] - }, { "cell_type": "markdown", "metadata": { From b7fc83aca4fd642ffe625402fbe1ffe500890397 Mon Sep 17 00:00:00 2001 From: samfreund Date: Wed, 6 Aug 2025 19:15:38 -0500 Subject: [PATCH 09/13] address text box --- scripts/rubik_conversion.ipynb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/rubik_conversion.ipynb b/scripts/rubik_conversion.ipynb index d868433199..725402bc8f 100644 --- a/scripts/rubik_conversion.ipynb +++ b/scripts/rubik_conversion.ipynb @@ -23,7 +23,9 @@ "\n", "You should also have a PyTorch model (ending in `.pt`) that's been uploaded to the runtime that you intend to convert.\n", "\n", - "Please note that your API key will be listed in the output, and should therefore be redacted if the output is shared." + "Please note that your API key will be listed in the output, and should therefore be redacted if the output is shared.\n", + "\n", + "At some point during the run of this cell, it will prompt you to choose whether to clone a repo. You should click on the text box next to the prompt, and answer *y/yes*." ] }, { From bde5e0ea3d4adc4f097dea6c7bf5db8353ab6f29 Mon Sep 17 00:00:00 2001 From: samfreund Date: Wed, 6 Aug 2025 19:40:33 -0500 Subject: [PATCH 10/13] update instructions to be more explantory --- scripts/rubik_conversion.ipynb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/rubik_conversion.ipynb b/scripts/rubik_conversion.ipynb index 725402bc8f..d362dd7462 100644 --- a/scripts/rubik_conversion.ipynb +++ b/scripts/rubik_conversion.ipynb @@ -21,11 +21,15 @@ "\n", "Prior to running the notebook, it is necessary to make an account on [Qualcomm's AI Hub](https://app.aihub.qualcomm.com/account/), and obtain your API key.\n", "\n", + "Documentation for the Qualcomm AI Hub can be found [here](https://app.aihub.qualcomm.com/docs/index.html).\n", + "\n", "You should also have a PyTorch model (ending in `.pt`) that's been uploaded to the runtime that you intend to convert.\n", "\n", "Please note that your API key will be listed in the output, and should therefore be redacted if the output is shared.\n", "\n", - "At some point during the run of this cell, it will prompt you to choose whether to clone a repo. You should click on the text box next to the prompt, and answer *y/yes*." + "At some point during the run of this cell, it will prompt you to choose whether to clone a repo. You should click on the text box next to the prompt, and answer *y/yes*.\n", + "\n", + "Once the run has finished, open the AI Hub link, and download the tflite model for the job you just ran." ] }, { @@ -46,7 +50,7 @@ "# sets up AI Hub enviroment\n", "!qai-hub configure --api_token \n", "# Converts the model to be ran on RB3Gen2\n", - "!python -m qai_hub_models.models.yolov8_det.export --quantize w8a8 --device=\"RB3 Gen 2 (Proxy)\" --ckpt-name /PATH/TO/WEIGHTS --device-os linux --target-runtime tflite\n" + "!python -m qai_hub_models.models.yolov8_det.export --name=\"MyModel\" --quantize w8a8 --device=\"RB3 Gen 2 (Proxy)\" --ckpt-name /PATH/TO/WEIGHTS --device-os linux --target-runtime tflite\n" ] }, { From 64d3eb80a02abdf3c6603ae00ad61ecfbd15c7cb Mon Sep 17 00:00:00 2001 From: samfreund Date: Wed, 6 Aug 2025 21:03:50 -0500 Subject: [PATCH 11/13] remove name param --- scripts/rubik_conversion.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/rubik_conversion.ipynb b/scripts/rubik_conversion.ipynb index d362dd7462..1bf6a54907 100644 --- a/scripts/rubik_conversion.ipynb +++ b/scripts/rubik_conversion.ipynb @@ -50,7 +50,7 @@ "# sets up AI Hub enviroment\n", "!qai-hub configure --api_token \n", "# Converts the model to be ran on RB3Gen2\n", - "!python -m qai_hub_models.models.yolov8_det.export --name=\"MyModel\" --quantize w8a8 --device=\"RB3 Gen 2 (Proxy)\" --ckpt-name /PATH/TO/WEIGHTS --device-os linux --target-runtime tflite\n" + "!python -m qai_hub_models.models.yolov8_det.export --quantize w8a8 --device=\"RB3 Gen 2 (Proxy)\" --ckpt-name /PATH/TO/WEIGHTS --device-os linux --target-runtime tflite\n" ] }, { From 3d8c47c03c232ec02f7b442f7c6b3f8f1b7d61bf Mon Sep 17 00:00:00 2001 From: samfreund Date: Wed, 6 Aug 2025 21:35:16 -0500 Subject: [PATCH 12/13] add output dir arg --- scripts/rubik_conversion.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/rubik_conversion.ipynb b/scripts/rubik_conversion.ipynb index 1bf6a54907..37f9cb35f2 100644 --- a/scripts/rubik_conversion.ipynb +++ b/scripts/rubik_conversion.ipynb @@ -50,7 +50,7 @@ "# sets up AI Hub enviroment\n", "!qai-hub configure --api_token \n", "# Converts the model to be ran on RB3Gen2\n", - "!python -m qai_hub_models.models.yolov8_det.export --quantize w8a8 --device=\"RB3 Gen 2 (Proxy)\" --ckpt-name /PATH/TO/WEIGHTS --device-os linux --target-runtime tflite\n" + "!python -m qai_hub_models.models.yolov8_det.export --quantize w8a8 --device=\"RB3 Gen 2 (Proxy)\" --ckpt-name /PATH/TO/WEIGHTS --device-os linux --target-runtime tflite --output-dir .\n" ] }, { From 47ef806ae1a0f4300ae160fee009ff69bcc12689 Mon Sep 17 00:00:00 2001 From: samfreund Date: Wed, 6 Aug 2025 23:47:28 -0500 Subject: [PATCH 13/13] make variables more clear --- scripts/rubik_conversion.ipynb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/rubik_conversion.ipynb b/scripts/rubik_conversion.ipynb index 37f9cb35f2..f1fef0fe43 100644 --- a/scripts/rubik_conversion.ipynb +++ b/scripts/rubik_conversion.ipynb @@ -17,19 +17,21 @@ "source": [ "#### Requirements\n", "\n", - "This notebook can be run on colab.\n", + "This notebook can be run on Colab. However, Colab has some incompatibility issues that result in needing to restart the notebook in the middle of the run. This is normal, and after restarting you should rerun the below cell.\n", "\n", - "Prior to running the notebook, it is necessary to make an account on [Qualcomm's AI Hub](https://app.aihub.qualcomm.com/account/), and obtain your API key.\n", + "Prior to running the notebook, it is necessary to make an account on [Qualcomm's AI Hub](https://app.aihub.qualcomm.com/account/), and obtain your API token. Then, replace with your API token in the cell below.\n", "\n", "Documentation for the Qualcomm AI Hub can be found [here](https://app.aihub.qualcomm.com/docs/index.html).\n", "\n", - "You should also have a PyTorch model (ending in `.pt`) that's been uploaded to the runtime that you intend to convert.\n", + "You should also have a PyTorch model (ending in `.pt`) that's been uploaded to the runtime that you intend to convert. After uploading, copy it's absolute path by right-clicking on the file, and replace /PATH/TO/WEIGHTS.\n", "\n", - "Please note that your API key will be listed in the output, and should therefore be redacted if the output is shared.\n", + "**NOTE: your API key will be listed in the output, and should therefore be redacted if the output is shared.**\n", "\n", "At some point during the run of this cell, it will prompt you to choose whether to clone a repo. You should click on the text box next to the prompt, and answer *y/yes*.\n", "\n", - "Once the run has finished, open the AI Hub link, and download the tflite model for the job you just ran." + "Once the run has finished, open the AI Hub link, and download the tflite model for the job you just ran.\n", + "\n", + "If you want to use this notebook to convert a yolo11 model, you'll need to replace all instances of `yolov8` in the cell below with `yolov11`." ] }, {