Skip to content

Commit

Permalink
Update SAHI notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
RizwanMunawar committed Feb 19, 2025
1 parent b4d92f1 commit ec7b4c8
Showing 1 changed file with 72 additions and 14 deletions.
86 changes: 72 additions & 14 deletions notebooks/how-to-use-ultralytics-yolo-with-sahi.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,25 @@
"cell_type": "code",
"metadata": {
"id": "wbvMlHd_QwMG",
"outputId": "b301c893-bdc3-46c0-d777-ea58238d7676",
"outputId": "50a3d03c-2c78-407d-d1e4-55550e5f7fc1",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"source": [
"%pip install ultralytics sahi\n",
"import ultralytics\n",
"from ultralytics.utils.downloads import safe_download\n",
"ultralytics.checks()"
],
"execution_count": null,
"execution_count": 1,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Ultralytics 8.3.61 πŸš€ Python-3.10.12 torch-2.5.1+cu121 CUDA:0 (Tesla T4, 15102MiB)\n",
"Setup complete βœ… (2 CPUs, 12.7 GB RAM, 32.5/112.6 GB disk)\n"
"Ultralytics 8.3.76 πŸš€ Python-3.11.11 torch-2.5.1+cu124 CUDA:0 (Tesla T4, 15095MiB)\n",
"Setup complete βœ… (2 CPUs, 12.7 GB RAM, 33.4/112.6 GB disk)\n"
]
}
]
Expand All @@ -116,17 +117,74 @@
"# Clone ultralytics repo\n",
"!git clone https://github.com/ultralytics/ultralytics\n",
"\n",
"# Install dependencies\n",
"!pip install -U sahi ultralytics\n",
"\n",
"# cd to local directory\n",
"%cd ultralytics/examples/YOLOv8-SAHI-Inference-Video"
],
"metadata": {
"id": "fNX-Ymha0HY6"
"id": "fNX-Ymha0HY6",
"outputId": "a4e52059-afe2-44f1-c77e-aaa48463ceb4",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"execution_count": null,
"outputs": []
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Cloning into 'ultralytics'...\n",
"remote: Enumerating objects: 51467, done.\u001b[K\n",
"remote: Counting objects: 100% (123/123), done.\u001b[K\n",
"remote: Compressing objects: 100% (63/63), done.\u001b[K\n",
"remote: Total 51467 (delta 92), reused 67 (delta 60), pack-reused 51344 (from 3)\u001b[K\n",
"Receiving objects: 100% (51467/51467), 29.28 MiB | 10.04 MiB/s, done.\n",
"Resolving deltas: 100% (38066/38066), done.\n",
"/content/ultralytics/examples/YOLOv8-SAHI-Inference-Video\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"### Download the Sample Video\n",
"\n",
"- If you want to use your own video, you can skip this step."
],
"metadata": {
"id": "mWszyoifxOtR"
}
},
{
"cell_type": "code",
"source": [
"safe_download(f\"https://github.com/ultralytics/assets/releases/download/v0.0.0/sahi.demo.video.mp4\", dir=\"/content\")"
],
"metadata": {
"id": "Kkef3pklxVKP",
"outputId": "58aec662-7870-4172-c1d1-4924e19254fc",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"execution_count": 5,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Downloading https://ultralytics.com/assets/sahi.demo.video.mp4 to '/content/sahi.demo.video.mp4'...\n"
]
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 15.3M/15.3M [00:00<00:00, 272MB/s]\n"
]
}
]
},
{
"cell_type": "markdown",
Expand All @@ -143,7 +201,7 @@
"cell_type": "code",
"source": [
"#inference (default latest model will be selected i.e yolo11n.pt)\n",
"!python yolov8_sahi.py --source \"path/to/video.mp4\""
"!python yolov8_sahi.py --source \"/content/sahi.demo.video.mp4\""
],
"metadata": {
"id": "B1YbLnvG1WAS"
Expand Down Expand Up @@ -191,9 +249,9 @@
"source": [
"### Additional Arguments\n",
"\n",
"- `--source`: Specifies the path to the video file you want to run inference on.\n",
"- `--save-img`: Flag to save the detection results as images.\n",
"- `--weights`: Specifies a different YOLO11 model file (e.g., yolo11n.pt, yolov8s.pt, yolo11m.pt, yolo11l.pt, yolo11x.pt)."
"- `--source`: Defines the file path of the video on which inference will be performed. \n",
"- `--save-img`: Enables saving the detection results as a video file. \n",
"- `--weights`: Allows specifying a different YOLO11 model file (e.g., yolo11n.pt, yolov8s.pt, yolo11m.pt, yolo11l.pt, yolo11x.pt)."
],
"metadata": {
"id": "UTcl_tpK18XM"
Expand Down

0 comments on commit ec7b4c8

Please sign in to comment.