From 6de99a29e6d8e754d3f1738a6775632385f3ecb0 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 23 Mar 2024 18:39:22 +0100 Subject: [PATCH] `ultralytics 8.1.32` fix CLIP backwards compatibility (#9253) Signed-off-by: Glenn Jocher --- tests/test_cli.py | 2 +- tests/test_python.py | 7 +++++++ ultralytics/__init__.py | 2 +- ultralytics/nn/tasks.py | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index fe257952e1d..eeeab0727d9 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -69,7 +69,7 @@ def test_rtdetr(task="detect", model="yolov8n-rtdetr.yaml", data="coco8.yaml"): run(f"yolo predict {task} model={model} source={ASSETS / 'bus.jpg'} imgsz=160 save save_crop save_txt") -@pytest.mark.skipif(checks.IS_PYTHON_3_12, reason="MobileSAM Clip is not supported in Python 3.12") +@pytest.mark.skipif(checks.IS_PYTHON_3_12, reason="MobileSAM with CLIP is not supported in Python 3.12") def test_fastsam(task="segment", model=WEIGHTS_DIR / "FastSAM-s.pt", data="coco8-seg.yaml"): """Test FastSAM segmentation functionality within Ultralytics.""" source = ASSETS / "bus.jpg" diff --git a/tests/test_python.py b/tests/test_python.py index 2a72b417cb6..4301f72e8ac 100644 --- a/tests/test_python.py +++ b/tests/test_python.py @@ -636,3 +636,10 @@ def test_model_embeddings(): for batch in [SOURCE], [SOURCE, SOURCE]: # test batch size 1 and 2 assert len(model_detect.embed(source=batch, imgsz=32)) == len(batch) assert len(model_segment.embed(source=batch, imgsz=32)) == len(batch) + + +@pytest.mark.skipif(checks.IS_PYTHON_3_12, reason="YOLOWorld with CLIP is not supported in Python 3.12") +def test_yolo_world(): + model = YOLO("yolov8s-world.pt") # no YOLOv8n-world model yet + model.set_classes(["tree", "window"]) + model(ASSETS / "bus.jpg", conf=0.01) diff --git a/ultralytics/__init__.py b/ultralytics/__init__.py index 8e442f85090..5673168cd3a 100644 --- a/ultralytics/__init__.py +++ b/ultralytics/__init__.py @@ -1,6 +1,6 @@ # Ultralytics YOLO 🚀, AGPL-3.0 license -__version__ = "8.1.31" +__version__ = "8.1.32" from ultralytics.data.explorer.explorer import Explorer from ultralytics.models import RTDETR, SAM, YOLO, YOLOWorld diff --git a/ultralytics/nn/tasks.py b/ultralytics/nn/tasks.py index bb1732fd872..f116ed2cf57 100644 --- a/ultralytics/nn/tasks.py +++ b/ultralytics/nn/tasks.py @@ -572,7 +572,7 @@ def set_classes(self, text): check_requirements("git+https://github.com/openai/CLIP.git") import clip - if not self.clip_model: + if not getattr(self, "clip_model", None): # for backwards compatibility of models lacking clip_model attribute self.clip_model = clip.load("ViT-B/32")[0] device = next(self.clip_model.parameters()).device text_token = clip.tokenize(text).to(device)