Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 29 additions & 11 deletions conversion/nvidia_tao_conversion.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -145,9 +145,8 @@
"metadata": {},
"outputs": [],
"source": [
"%pip install -q pillow onnx onnxruntime modelconv==0.4.5 -U\n",
"%pip install -q depthai==3.0.0 -U\n",
"%pip install -q depthai-nodes==0.3.0 -U"
"%pip install -q pillow luxonis-ml==0.8.5 onnx==1.21.0 onnxruntime==1.23.2 modelconv==0.5.5 depthai==3.7.1 depthai-nodes==0.5.1\n",
"%pip install -q numpy==2.0.2"
]
},
{
Expand Down Expand Up @@ -243,10 +242,10 @@
}
],
"source": [
"import os\n",
"import onnxruntime as ort\n",
"import numpy as np\n",
"import cv2\n",
"from scipy.spatial.distance import cosine\n",
"import matplotlib.pyplot as plt\n",
"\n",
"# Load ONNX model\n",
Expand Down Expand Up @@ -285,8 +284,15 @@
" embeddings[img_path] = normalize_embedding(output.flatten()) # Flatten to 1D vector\n",
"\n",
"# Compute cosine similarity between pairs\n",
"def cosine_similarity(emb1, emb2):\n",
" return 1 - cosine(emb1, emb2) # Higher value = more similar\n",
"def cosine_similarity(emb1, emb2, eps=1e-12):\n",
" emb1 = np.asarray(emb1, dtype=np.float32).ravel()\n",
" emb2 = np.asarray(emb2, dtype=np.float32).ravel()\n",
"\n",
" denom = np.linalg.norm(emb1) * np.linalg.norm(emb2)\n",
" if denom < eps:\n",
" return 0.0\n",
"\n",
" return float(np.dot(emb1, emb2) / denom)\n",
"\n",
"pairs = [\n",
" (\"person_0_0.png\", \"person_0_1.png\"), # Same person\n",
Expand Down Expand Up @@ -442,7 +448,7 @@
"metadata": {},
"outputs": [],
"source": [
"%pip install -q hubai-sdk"
"%pip install -q -U hubai-sdk"
]
},
{
Expand All @@ -458,7 +464,13 @@
"metadata": {},
"outputs": [],
"source": [
"HUBAI_API_KEY = \"<YOUR_HUBAI_API_KEY>\""
"import os\n",
"import getpass\n",
"\n",
"if not os.environ.get(\"HUBAI_API_KEY\"):\n",
" os.environ[\"HUBAI_API_KEY\"] = getpass.getpass(\"Enter your HubAI API key: \")\n",
"\n",
"print(\"HUBAI_API_KEY is set:\", bool(os.environ.get(\"HUBAI_API_KEY\")))"
]
},
{
Expand All @@ -467,19 +479,25 @@
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path\n",
"from hubai_sdk import HubAIClient\n",
"\n",
"client = HubAIClient(api_key=HUBAI_API_KEY)\n",
"client = HubAIClient(api_key=os.environ[\"HUBAI_API_KEY\"])\n",
"\n",
"ARTIFACT_DIR = Path(\"reidentification-nvidia-tao-exported-to-rvc4\")\n",
"ARTIFACT_DIR.mkdir(parents=True, exist_ok=True)\n",
"\n",
"response = client.convert.RVC4(\n",
" path=\"resnet50_market1501_aicity156.tar.xz\",\n",
" name=\"ReIdentification NVIDIA TAO\",\n",
" description_short=\"ReIdentificationNet takes cropped images of a person from different perspectives as network input and outputs the embedding features for that person.\",\n",
" license_type=\"MIT\",\n",
" is_public=False,\n",
" output_dir=str(ARTIFACT_DIR),\n",
")\n",
"\n",
"model_path = response.downloaded_path\n",
"MODEL_PATH = Path(response.downloaded_path)\n",
"print(\"Model artifact:\", MODEL_PATH)\n",
"\n",
"# =============================================================================\n",
"# RVC4 conversion\n",
Expand Down
288 changes: 199 additions & 89 deletions conversion/onnx_conversion.ipynb

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same nitpicks as mentioned in the "pytorch_conversion.ipynb"

Large diffs are not rendered by default.

Loading