Skip to content

Commit

Permalink
Support Ultralytics YOLO models and TIMM models (#2)
Browse files Browse the repository at this point in the history
* add yolo

* add timm and ultralytics

* add yolov11

* add yolov10

* update

* move model list into its own module

* update req to pass test

* add limit to list models

* streamline all transformers models

* update

* update
  • Loading branch information
dnth authored Oct 11, 2024
1 parent c8006ad commit 56599c6
Show file tree
Hide file tree
Showing 18 changed files with 1,972 additions and 91 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# pytorch related
*.pt
*.pth


# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
312 changes: 271 additions & 41 deletions nbs/demo.ipynb

Large diffs are not rendered by default.

159 changes: 159 additions & 0 deletions nbs/timm.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-style: italic\"> Available Models </span>\n",
"┏━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┓\n",
"┃<span style=\"font-weight: bold\"> Backend </span>┃<span style=\"font-weight: bold\"> Model ID </span>┃<span style=\"font-weight: bold\"> Input --&gt; Output </span>┃\n",
"┡━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━┩\n",
"│<span style=\"color: #008080; text-decoration-color: #008080\"> timm </span>│<span style=\"color: #800080; text-decoration-color: #800080\"> vit_huge_patch14_clip_336.laion2b_ft_in12k_in1k </span>│<span style=\"color: #008000; text-decoration-color: #008000\"> image --&gt; class </span>│\n",
"│<span style=\"color: #008080; text-decoration-color: #008080\"> timm </span>│<span style=\"color: #800080; text-decoration-color: #800080\"> maxvit_xlarge_tf_512.in21k_ft_in1k </span>│<span style=\"color: #008000; text-decoration-color: #008000\"> image --&gt; class </span>│\n",
"│<span style=\"color: #008080; text-decoration-color: #008080\"> timm </span>│<span style=\"color: #800080; text-decoration-color: #800080\"> maxvit_xlarge_tf_384.in21k_ft_in1k </span>│<span style=\"color: #008000; text-decoration-color: #008000\"> image --&gt; class </span>│\n",
"│<span style=\"color: #008080; text-decoration-color: #008080\"> ... </span>│<span style=\"color: #800080; text-decoration-color: #800080\"> ... </span>│<span style=\"color: #008000; text-decoration-color: #008000\"> ... </span>│\n",
"│<span style=\"color: #008080; text-decoration-color: #008080\"> ... </span>│<span style=\"color: #800080; text-decoration-color: #800080\"> ... </span>│<span style=\"color: #008000; text-decoration-color: #008000\"> ... </span>│\n",
"└─────────┴─────────────────────────────────────────────────┴──────────────────┘\n",
"</pre>\n"
],
"text/plain": [
"\u001b[3m Available Models \u001b[0m\n",
"┏━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┓\n",
"\u001b[1m \u001b[0m\u001b[1mBackend\u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mModel ID \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mInput --> Output\u001b[0m\u001b[1m \u001b[0m┃\n",
"┡━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━┩\n",
"\u001b[36m \u001b[0m\u001b[36mtimm \u001b[0m\u001b[36m \u001b[0m│\u001b[35m \u001b[0m\u001b[35mvit_huge_patch14_clip_336.laion2b_ft_in12k_in1k\u001b[0m\u001b[35m \u001b[0m│\u001b[32m \u001b[0m\u001b[32mimage --> class \u001b[0m\u001b[32m \u001b[0m│\n",
"\u001b[36m \u001b[0m\u001b[36mtimm \u001b[0m\u001b[36m \u001b[0m│\u001b[35m \u001b[0m\u001b[35mmaxvit_xlarge_tf_512.in21k_ft_in1k \u001b[0m\u001b[35m \u001b[0m│\u001b[32m \u001b[0m\u001b[32mimage --> class \u001b[0m\u001b[32m \u001b[0m│\n",
"\u001b[36m \u001b[0m\u001b[36mtimm \u001b[0m\u001b[36m \u001b[0m│\u001b[35m \u001b[0m\u001b[35mmaxvit_xlarge_tf_384.in21k_ft_in1k \u001b[0m\u001b[35m \u001b[0m│\u001b[32m \u001b[0m\u001b[32mimage --> class \u001b[0m\u001b[32m \u001b[0m│\n",
"\u001b[36m \u001b[0m\u001b[36m... \u001b[0m\u001b[36m \u001b[0m│\u001b[35m \u001b[0m\u001b[35m... \u001b[0m\u001b[35m \u001b[0m│\u001b[32m \u001b[0m\u001b[32m... \u001b[0m\u001b[32m \u001b[0m│\n",
"\u001b[36m \u001b[0m\u001b[36m... \u001b[0m\u001b[36m \u001b[0m│\u001b[35m \u001b[0m\u001b[35m... \u001b[0m\u001b[35m \u001b[0m│\u001b[32m \u001b[0m\u001b[32m... \u001b[0m\u001b[32m \u001b[0m│\n",
"└─────────┴─────────────────────────────────────────────────┴──────────────────┘\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import xinfer\n",
"\n",
"xinfer.list_models(\"vit\", limit=3)\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m2024-10-11 23:43:39.344\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36mxinfer.timm.timm_model\u001b[0m:\u001b[36m__init__\u001b[0m:\u001b[36m17\u001b[0m - \u001b[1mLoading model: mobilenetv2_050.lamb_in1k\u001b[0m\n",
"\u001b[32m2024-10-11 23:43:39.345\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36mxinfer.timm.timm_model\u001b[0m:\u001b[36mload_model\u001b[0m:\u001b[36m21\u001b[0m - \u001b[1mLoading model: mobilenetv2_050.lamb_in1k\u001b[0m\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "128884c6909b4ebb9a4f3881fdaff671",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"model.safetensors: 0%| | 0.00/7.98M [00:00<?, ?B/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m2024-10-11 23:43:40.408\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36mxinfer.timm.timm_model\u001b[0m:\u001b[36minference\u001b[0m:\u001b[36m27\u001b[0m - \u001b[1mRunning inference on https://ultralytics.com/images/bus.jpg\u001b[0m\n"
]
}
],
"source": [
"model = xinfer.create_model(\"mobilenetv2_050.lamb_in1k\", \"timm\")\n",
"\n",
"result = model.inference(\"https://ultralytics.com/images/bus.jpg\", top_k=10)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'class': 'minibus', 'id': 654, 'confidence': 62.94279098510742},\n",
" {'class': 'police van, police wagon, paddy wagon, patrol wagon, wagon, black Maria',\n",
" 'id': 734,\n",
" 'confidence': 8.970001220703125},\n",
" {'class': 'trolleybus, trolley coach, trackless trolley',\n",
" 'id': 874,\n",
" 'confidence': 4.9347052574157715},\n",
" {'class': 'ambulance', 'id': 407, 'confidence': 2.7388036251068115},\n",
" {'class': 'streetcar, tram, tramcar, trolley, trolley car',\n",
" 'id': 829,\n",
" 'confidence': 1.687123417854309},\n",
" {'class': 'jinrikisha, ricksha, rickshaw',\n",
" 'id': 612,\n",
" 'confidence': 1.6692038774490356},\n",
" {'class': 'passenger car, coach, carriage',\n",
" 'id': 705,\n",
" 'confidence': 1.348435401916504},\n",
" {'class': 'recreational vehicle, RV, R.V.',\n",
" 'id': 757,\n",
" 'confidence': 1.2413547039031982},\n",
" {'class': 'minivan', 'id': 656, 'confidence': 0.5516668558120728},\n",
" {'class': 'amphibian, amphibious vehicle',\n",
" 'id': 408,\n",
" 'confidence': 0.4996110796928406}]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"result"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "xinfer",
"language": "python",
"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.15"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 56599c6

Please sign in to comment.