From 65c214ac2d2b374ef328a813f8e3d58ac1fd81a4 Mon Sep 17 00:00:00 2001 From: Sam Freund Date: Thu, 7 Aug 2025 11:11:35 -0500 Subject: [PATCH] Add notebook for Rubik Model conversion (#2006) --- scripts/rubik_conversion.ipynb | 84 ++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 scripts/rubik_conversion.ipynb diff --git a/scripts/rubik_conversion.ipynb b/scripts/rubik_conversion.ipynb new file mode 100644 index 000000000..f1fef0fe4 --- /dev/null +++ b/scripts/rubik_conversion.ipynb @@ -0,0 +1,84 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "1tMAqVl4p58r" + }, + "source": [ + "## YOLO to Rubik TFlite Conversion" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "nAbygyUYp58s" + }, + "source": [ + "#### Requirements\n", + "\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 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. After uploading, copy it's absolute path by right-clicking on the file, and replace /PATH/TO/WEIGHTS.\n", + "\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.\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`." + ] + }, + { + "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 --output-dir .\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" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +}