From 0d59878c25d64a1bd2640b96eaf0b4e3f580827b Mon Sep 17 00:00:00 2001 From: RizwanMunawar Date: Wed, 4 Jun 2025 10:31:26 +0500 Subject: [PATCH 01/18] Add notebooks.yml --- .github/workflows/notebooks.yml | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/notebooks.yml diff --git a/.github/workflows/notebooks.yml b/.github/workflows/notebooks.yml new file mode 100644 index 0000000..aba8e96 --- /dev/null +++ b/.github/workflows/notebooks.yml @@ -0,0 +1,37 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +# Notebooks GitHub Actions tests + +name: Run Notebooks + +permissions: + contents: read + +on: + push: + branches: [main] + pull_request: + branches: [main] + schedule: + - cron: "0 8 * * *" # runs at 08:00 UTC every day + +jobs: + Notebooks: + name: Execute Notebooks + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: '3.11' + + - name: Install requirements + run: | + python -m pip install --upgrade pip + pip install jupyter nbconvert ipykernel + + - name: Test Ultralytics YOLO Notebooks + run: | + set -e + jupyter nbconvert --to notebook --inplace --execute notebooks/how-to-train-ultralytics-yolo-on-medical-pills-dataset.ipynb From 4f0d9961e97a87e589e5b49f3b7573b99e58e259 Mon Sep 17 00:00:00 2001 From: Muhammad Rizwan Munawar Date: Wed, 4 Jun 2025 10:39:01 +0500 Subject: [PATCH 02/18] Update how-to-train-ultralytics-yolo-on-medical-pills-dataset.ipynb Signed-off-by: Muhammad Rizwan Munawar --- ...how-to-train-ultralytics-yolo-on-medical-pills-dataset.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notebooks/how-to-train-ultralytics-yolo-on-medical-pills-dataset.ipynb b/notebooks/how-to-train-ultralytics-yolo-on-medical-pills-dataset.ipynb index 1d7f2c5..ee03d33 100644 --- a/notebooks/how-to-train-ultralytics-yolo-on-medical-pills-dataset.ipynb +++ b/notebooks/how-to-train-ultralytics-yolo-on-medical-pills-dataset.ipynb @@ -176,7 +176,7 @@ "model = YOLO(\"yolo11n.pt\") # load a pretrained model (recommended for training)\n", "\n", "# Train the model\n", - "results = model.train(data=\"medical-pills.yaml\", epochs=20, imgsz=640)" + "results = model.train(data=\"medical-pills.yaml\", epochs=3, imgsz=640)" ], "metadata": { "colab": { From c72c91603a02dbe3a6dcce69b1e16ca9ef7c4ea8 Mon Sep 17 00:00:00 2001 From: RizwanMunawar Date: Wed, 4 Jun 2025 10:40:33 +0500 Subject: [PATCH 03/18] update --- .github/workflows/notebooks.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/notebooks.yml b/.github/workflows/notebooks.yml index aba8e96..a7ebe3a 100644 --- a/.github/workflows/notebooks.yml +++ b/.github/workflows/notebooks.yml @@ -17,7 +17,7 @@ on: jobs: Notebooks: - name: Execute Notebooks + name: Ultralytics Notebooks runs-on: ubuntu-latest steps: @@ -31,7 +31,7 @@ jobs: python -m pip install --upgrade pip pip install jupyter nbconvert ipykernel - - name: Test Ultralytics YOLO Notebooks + - name: Test Ultralytics YOLO run: | set -e jupyter nbconvert --to notebook --inplace --execute notebooks/how-to-train-ultralytics-yolo-on-medical-pills-dataset.ipynb From 4fc47a624423793359283c795e074847da91aa56 Mon Sep 17 00:00:00 2001 From: Muhammad Rizwan Munawar Date: Tue, 1 Jul 2025 12:32:08 +0500 Subject: [PATCH 04/18] Update how-to-train-ultralytics-yolo-on-medical-pills-dataset.ipynb Signed-off-by: Muhammad Rizwan Munawar --- ...how-to-train-ultralytics-yolo-on-medical-pills-dataset.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notebooks/how-to-train-ultralytics-yolo-on-medical-pills-dataset.ipynb b/notebooks/how-to-train-ultralytics-yolo-on-medical-pills-dataset.ipynb index 6ada4a4..3a051c5 100644 --- a/notebooks/how-to-train-ultralytics-yolo-on-medical-pills-dataset.ipynb +++ b/notebooks/how-to-train-ultralytics-yolo-on-medical-pills-dataset.ipynb @@ -176,7 +176,7 @@ "model = YOLO(\"yolo11n.pt\") # load a pretrained model (recommended for training)\n", "\n", "# Train the model\n", - "results = model.train(data=\"medical-pills.yaml\", epochs=3, imgsz=640)" + "results = model.train(data=\"medical-pills.yaml\", epochs=20, imgsz=640)" ], "metadata": { "colab": { From f2251a9dc2808063e6db14341c2b5e89d5b8de52 Mon Sep 17 00:00:00 2001 From: Muhammad Rizwan Munawar Date: Tue, 1 Jul 2025 12:54:11 +0500 Subject: [PATCH 05/18] update --- .github/workflows/notebooks.yml | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/.github/workflows/notebooks.yml b/.github/workflows/notebooks.yml index a7ebe3a..d70586a 100644 --- a/.github/workflows/notebooks.yml +++ b/.github/workflows/notebooks.yml @@ -1,7 +1,3 @@ -# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license - -# Notebooks GitHub Actions tests - name: Run Notebooks permissions: @@ -13,25 +9,34 @@ on: pull_request: branches: [main] schedule: - - cron: "0 8 * * *" # runs at 08:00 UTC every day + - cron: "0 8 * * *" # Daily at 08:00 UTC jobs: - Notebooks: - name: Ultralytics Notebooks + notebooks: + name: Tests runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 with: python-version: '3.11' - - name: Install requirements + - name: Install dependencies run: | python -m pip install --upgrade pip - pip install jupyter nbconvert ipykernel + pip install -r requirements.txt + pip install jupyter nbconvert ipykernel pytest - - name: Test Ultralytics YOLO + - name: Run notebook tests run: | - set -e - jupyter nbconvert --to notebook --inplace --execute notebooks/how-to-train-ultralytics-yolo-on-medical-pills-dataset.ipynb + if [ "${{ github.event_name }}" = "schedule" ]; then + echo "Running full test suite including @slow tests" + pytest tests/test_notebooks.py + else + echo "Running fast tests only (excluding @slow)" + pytest -m "not slow" tests/test_notebooks.py + fi From 60fe788839e43ebab4458ee8f5ef081b5ed8b897 Mon Sep 17 00:00:00 2001 From: Muhammad Rizwan Munawar Date: Tue, 1 Jul 2025 12:55:08 +0500 Subject: [PATCH 06/18] update --- .github/workflows/notebooks.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/notebooks.yml b/.github/workflows/notebooks.yml index d70586a..6ec5a80 100644 --- a/.github/workflows/notebooks.yml +++ b/.github/workflows/notebooks.yml @@ -28,8 +28,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -r requirements.txt - pip install jupyter nbconvert ipykernel pytest + pip install -r ultralytics pytest pytest - name: Run notebook tests run: | From 9a348f9f792767d153432621dd8b861b2aef60d3 Mon Sep 17 00:00:00 2001 From: Muhammad Rizwan Munawar Date: Tue, 1 Jul 2025 12:56:13 +0500 Subject: [PATCH 07/18] update --- .github/workflows/notebooks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/notebooks.yml b/.github/workflows/notebooks.yml index 6ec5a80..a483796 100644 --- a/.github/workflows/notebooks.yml +++ b/.github/workflows/notebooks.yml @@ -28,7 +28,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -r ultralytics pytest pytest + pip install ultralytics pytest - name: Run notebook tests run: | From 2cf25a2d1cf382862e5f34aa27755c650ad37c19 Mon Sep 17 00:00:00 2001 From: Muhammad Rizwan Munawar Date: Tue, 1 Jul 2025 13:00:59 +0500 Subject: [PATCH 08/18] update --- .github/workflows/notebooks.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/notebooks.yml b/.github/workflows/notebooks.yml index a483796..2c58538 100644 --- a/.github/workflows/notebooks.yml +++ b/.github/workflows/notebooks.yml @@ -23,7 +23,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: '3.11' + python-version: '3.12' - name: Install dependencies run: | @@ -31,6 +31,7 @@ jobs: pip install ultralytics pytest - name: Run notebook tests + working-directory: ${{ github.workspace }} run: | if [ "${{ github.event_name }}" = "schedule" ]; then echo "Running full test suite including @slow tests" From 60e44df7dc6177a19659a92a06092fe12206bfe6 Mon Sep 17 00:00:00 2001 From: Muhammad Rizwan Munawar Date: Tue, 1 Jul 2025 13:06:15 +0500 Subject: [PATCH 09/18] update --- .github/workflows/notebooks.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/notebooks.yml b/.github/workflows/notebooks.yml index 2c58538..8f26b0e 100644 --- a/.github/workflows/notebooks.yml +++ b/.github/workflows/notebooks.yml @@ -25,14 +25,15 @@ jobs: with: python-version: '3.12' - - name: Install dependencies + - name: Install dependencies # Transformer dependency for Florence-2 run: | python -m pip install --upgrade pip - pip install ultralytics pytest + pip install ultralytics pytest transformers==4.49.0 - name: Run notebook tests - working-directory: ${{ github.workspace }} run: | + echo "CI event: ${{ github.event_name }}" + cd $GITHUB_WORKSPACE # now we're in /home/runner/work/notebooks/notebooks if [ "${{ github.event_name }}" = "schedule" ]; then echo "Running full test suite including @slow tests" pytest tests/test_notebooks.py From 9a4dfd7e7eda3db2e9079fef074e33141816e1f8 Mon Sep 17 00:00:00 2001 From: Muhammad Rizwan Munawar Date: Tue, 1 Jul 2025 13:08:07 +0500 Subject: [PATCH 10/18] update --- .github/workflows/notebooks.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/notebooks.yml b/.github/workflows/notebooks.yml index 8f26b0e..6a09b17 100644 --- a/.github/workflows/notebooks.yml +++ b/.github/workflows/notebooks.yml @@ -19,6 +19,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 + with: + path: . # checkout to rootdir - name: Set up Python uses: actions/setup-python@v4 @@ -33,7 +35,6 @@ jobs: - name: Run notebook tests run: | echo "CI event: ${{ github.event_name }}" - cd $GITHUB_WORKSPACE # now we're in /home/runner/work/notebooks/notebooks if [ "${{ github.event_name }}" = "schedule" ]; then echo "Running full test suite including @slow tests" pytest tests/test_notebooks.py From 41f27332f49c77c6e9d093408b0021c89085f46c Mon Sep 17 00:00:00 2001 From: Muhammad Rizwan Munawar Date: Tue, 1 Jul 2025 13:14:11 +0500 Subject: [PATCH 11/18] update --- .github/workflows/notebooks.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/notebooks.yml b/.github/workflows/notebooks.yml index 6a09b17..e5dfeb5 100644 --- a/.github/workflows/notebooks.yml +++ b/.github/workflows/notebooks.yml @@ -19,9 +19,6 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 - with: - path: . # checkout to rootdir - - name: Set up Python uses: actions/setup-python@v4 with: @@ -33,6 +30,7 @@ jobs: pip install ultralytics pytest transformers==4.49.0 - name: Run notebook tests + working-directory: ../ # rootdir run: | echo "CI event: ${{ github.event_name }}" if [ "${{ github.event_name }}" = "schedule" ]; then From 7ad90480a75080fbf93b6afe9a767fa3effc12f9 Mon Sep 17 00:00:00 2001 From: Muhammad Rizwan Munawar Date: Tue, 1 Jul 2025 13:16:58 +0500 Subject: [PATCH 12/18] update --- .github/workflows/notebooks.yml | 1 - tests/test_notebooks.py | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 tests/test_notebooks.py diff --git a/.github/workflows/notebooks.yml b/.github/workflows/notebooks.yml index e5dfeb5..cef7e94 100644 --- a/.github/workflows/notebooks.yml +++ b/.github/workflows/notebooks.yml @@ -30,7 +30,6 @@ jobs: pip install ultralytics pytest transformers==4.49.0 - name: Run notebook tests - working-directory: ../ # rootdir run: | echo "CI event: ${{ github.event_name }}" if [ "${{ github.event_name }}" = "schedule" ]; then diff --git a/tests/test_notebooks.py b/tests/test_notebooks.py new file mode 100644 index 0000000..47b44dd --- /dev/null +++ b/tests/test_notebooks.py @@ -0,0 +1,45 @@ +import pytest +from ultralytics import YOLO, SAM, ASSETS + +# Test: notebooks/how-to-export-the-validation-results-into-dataframe-csv-sql-and-other-formats.ipynb +def export_val_results(): + model = YOLO("yolo11n.pt") + metrics = model.val(data="coco8.yaml", verbose=True) + metrics.to_df() + metrics.to_csv() + metrics.to_html() + metrics.to_sql() + metrics.to_json() + metrics.confusion_matrix.to_df() + metrics.confusion_matrix.to_html() + metrics.confusion_matrix.to_sql() + metrics.confusion_matrix.to_xml() + metrics.confusion_matrix.to_json() + with open("validation_results.html", "w") as f: + f.write(metrics.to_xml()) + with open("confusion_matrix.csv", "w") as f: + f.write(metrics.confusion_matrix.to_csv()) + + +# Test: notebooks/inference-with-meta-sam-and-sam2-using-ultralytics-python-package.ipynb +@pytest.mark.slow +def test_sam_inference(): + from ultralytics.data.annotator import auto_annotate + from ultralytics.utils.downloads import safe_download + + model = SAM("sam2.1_b.pt") + _ = model() # image. + _ = model("https://ultralytics.com/images/bus.jpg", # bbox prompt. + bboxes=[3.8328723907470703, 229.35601806640625, + 796.2098999023438, 728.4313354492188]) + _ = model("https://ultralytics.com/images/bus.jpg", points=[34, 714]) # Point prompt. + _ = model("https://ultralytics.com/images/bus.jpg", points=[[34, 714], [283, 634]]) # Multiple points prompt. + + for img in ["bus.jpg", "zidane.jpg"]: + safe_download(f"https://ultralytics.com/assets/{img}", dir="assets") + auto_annotate(data="/content/assets", # return the annotation in the Ultralytics YOLO segmentation format. + det_model="yolo11x.pt", + sam_model="sam_b.pt") + + +# Test: \ No newline at end of file From 977dd19c6ee359028dab898fe38e04c9a3e5f28f Mon Sep 17 00:00:00 2001 From: UltralyticsAssistant Date: Tue, 1 Jul 2025 08:17:19 +0000 Subject: [PATCH 13/18] Auto-format by https://ultralytics.com/actions --- tests/test_notebooks.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_notebooks.py b/tests/test_notebooks.py index 47b44dd..5142af0 100644 --- a/tests/test_notebooks.py +++ b/tests/test_notebooks.py @@ -1,3 +1,5 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + import pytest from ultralytics import YOLO, SAM, ASSETS From ec15c8af0cfba539f30daa14bb90f7f3aaa668cc Mon Sep 17 00:00:00 2001 From: Muhammad Rizwan Munawar Date: Tue, 1 Jul 2025 13:18:36 +0500 Subject: [PATCH 14/18] update --- .github/workflows/notebooks.yml | 4 ++++ tests/test_notebooks.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/.github/workflows/notebooks.yml b/.github/workflows/notebooks.yml index cef7e94..9d72a34 100644 --- a/.github/workflows/notebooks.yml +++ b/.github/workflows/notebooks.yml @@ -1,3 +1,7 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +# Notebooks (CI) GitHub Actions tests + name: Run Notebooks permissions: diff --git a/tests/test_notebooks.py b/tests/test_notebooks.py index 47b44dd..c9455ee 100644 --- a/tests/test_notebooks.py +++ b/tests/test_notebooks.py @@ -1,3 +1,7 @@ +# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license + +# Tests Ultralytics Notebooks: https://github.com/ultralytics/notebooks/ + import pytest from ultralytics import YOLO, SAM, ASSETS From 38785930f01396e22fdd907fbdba9c57fb77eaf0 Mon Sep 17 00:00:00 2001 From: Muhammad Rizwan Munawar Date: Tue, 1 Jul 2025 13:21:35 +0500 Subject: [PATCH 15/18] update --- .github/workflows/notebooks.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/notebooks.yml b/.github/workflows/notebooks.yml index 9d72a34..3e1e754 100644 --- a/.github/workflows/notebooks.yml +++ b/.github/workflows/notebooks.yml @@ -38,8 +38,8 @@ jobs: echo "CI event: ${{ github.event_name }}" if [ "${{ github.event_name }}" = "schedule" ]; then echo "Running full test suite including @slow tests" - pytest tests/test_notebooks.py + pytest tests/test_notebooks.py -p no:warnings else echo "Running fast tests only (excluding @slow)" - pytest -m "not slow" tests/test_notebooks.py - fi + pytest -m "not slow" tests/test_notebooks.py -p no:warnings + fi \ No newline at end of file From c5fd0230f74eb7fae82634037f665cb419a257f3 Mon Sep 17 00:00:00 2001 From: Muhammad Rizwan Munawar Date: Tue, 1 Jul 2025 13:27:02 +0500 Subject: [PATCH 16/18] update --- tests/test_notebooks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_notebooks.py b/tests/test_notebooks.py index c9455ee..bc92fa7 100644 --- a/tests/test_notebooks.py +++ b/tests/test_notebooks.py @@ -6,7 +6,7 @@ from ultralytics import YOLO, SAM, ASSETS # Test: notebooks/how-to-export-the-validation-results-into-dataframe-csv-sql-and-other-formats.ipynb -def export_val_results(): +def test_export_val_results(): model = YOLO("yolo11n.pt") metrics = model.val(data="coco8.yaml", verbose=True) metrics.to_df() From 2a2f94349d2855df9c8b1ce8c72d9881d736bbef Mon Sep 17 00:00:00 2001 From: Muhammad Rizwan Munawar Date: Tue, 1 Jul 2025 13:27:38 +0500 Subject: [PATCH 17/18] update --- tests/test_notebooks.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/test_notebooks.py b/tests/test_notebooks.py index bc92fa7..f8a6020 100644 --- a/tests/test_notebooks.py +++ b/tests/test_notebooks.py @@ -5,8 +5,9 @@ import pytest from ultralytics import YOLO, SAM, ASSETS -# Test: notebooks/how-to-export-the-validation-results-into-dataframe-csv-sql-and-other-formats.ipynb + def test_export_val_results(): + """Test: notebooks/how-to-export-the-validation-results-into-dataframe-csv-sql-and-other-formats.ipynb""" model = YOLO("yolo11n.pt") metrics = model.val(data="coco8.yaml", verbose=True) metrics.to_df() @@ -25,9 +26,10 @@ def test_export_val_results(): f.write(metrics.confusion_matrix.to_csv()) -# Test: notebooks/inference-with-meta-sam-and-sam2-using-ultralytics-python-package.ipynb + @pytest.mark.slow def test_sam_inference(): + """Test: notebooks/inference-with-meta-sam-and-sam2-using-ultralytics-python-package.ipynb""" from ultralytics.data.annotator import auto_annotate from ultralytics.utils.downloads import safe_download @@ -44,6 +46,3 @@ def test_sam_inference(): auto_annotate(data="/content/assets", # return the annotation in the Ultralytics YOLO segmentation format. det_model="yolo11x.pt", sam_model="sam_b.pt") - - -# Test: \ No newline at end of file From 376c67bf9df80fa541a524844736f2feec3beaa9 Mon Sep 17 00:00:00 2001 From: Muhammad Rizwan Munawar Date: Tue, 1 Jul 2025 13:51:43 +0500 Subject: [PATCH 18/18] update --- tests/test_notebooks.py | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/tests/test_notebooks.py b/tests/test_notebooks.py index f8a6020..def705c 100644 --- a/tests/test_notebooks.py +++ b/tests/test_notebooks.py @@ -2,8 +2,37 @@ # Tests Ultralytics Notebooks: https://github.com/ultralytics/notebooks/ +import cv2 import pytest from ultralytics import YOLO, SAM, ASSETS +from ultralytics.utils.downloads import safe_download +from ultralytics.utils import ROOT +from ultralytics.solutions import ObjectCounter, TrackZone, Heatmap, AIGym + +TMP = (ROOT / "../tests/tmp").resolve() # temp directory for test files + +DEMO_VIDEO = "https://github.com/ultralytics/notebooks/releases/download/v0.0.0/solutions-ci-demo.mp4" +WORKOUT_VIDEO = "https://github.com/ultralytics/assets/releases/download/v0.0.0/Legextension.demo.video.mp4" + +@pytest.mark.parametrize("solution_class, solution_kwargs, video_source", [ + (ObjectCounter, {"region": [(20, 400), (1080, 400), (1080, 360), (20, 360)]}, DEMO_VIDEO), + (TrackZone, {"region": [(20, 400), (1080, 400), (1080, 360), (20, 360)]}, DEMO_VIDEO), + (Heatmap, {"colormap": cv2.COLORMAP_PARULA}, DEMO_VIDEO), + (AIGym, {"kpts": [12, 14, 16]}, WORKOUT_VIDEO) +]) +def test_solution_inference(solution_class, solution_kwargs, video_source): + """Parameterized test for multiple Ultralytics solution demos.""" + safe_download(video_source) + source = "Legextension.demo.video.mp4" if solution_class=="AIGym" else "solutions-ci-demo.mp4" + cap = cv2.VideoCapture(source) + solution = solution_class(**solution_kwargs) + + while cap.isOpened(): + success, frame = cap.read() + if not success: + break + _ = solution(frame) # Run inference + cap.release() def test_export_val_results(): @@ -26,20 +55,16 @@ def test_export_val_results(): f.write(metrics.confusion_matrix.to_csv()) - @pytest.mark.slow def test_sam_inference(): """Test: notebooks/inference-with-meta-sam-and-sam2-using-ultralytics-python-package.ipynb""" from ultralytics.data.annotator import auto_annotate - from ultralytics.utils.downloads import safe_download model = SAM("sam2.1_b.pt") - _ = model() # image. - _ = model("https://ultralytics.com/images/bus.jpg", # bbox prompt. - bboxes=[3.8328723907470703, 229.35601806640625, - 796.2098999023438, 728.4313354492188]) - _ = model("https://ultralytics.com/images/bus.jpg", points=[34, 714]) # Point prompt. - _ = model("https://ultralytics.com/images/bus.jpg", points=[[34, 714], [283, 634]]) # Multiple points prompt. + _ = model(ASSETS/"bus.jpg") # image. + _ = model(ASSETS/"bus.jpg", points=[34, 714]) # point prompt. + _ = model(ASSETS/"bus.jpg", points=[[34, 714], [283, 634]]) # multiple points prompt. + _ = model(ASSETS / "bus.jpg", bboxes=[3.83287, 229.3560, 796.2098, 728.4313]) # bbox prompt. for img in ["bus.jpg", "zidane.jpg"]: safe_download(f"https://ultralytics.com/assets/{img}", dir="assets")