Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

test_explorer.py 2.2 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  1. # Ultralytics YOLO 🚀, AGPL-3.0 license
  2. import PIL
  3. import pytest
  4. from ultralytics import Explorer
  5. from ultralytics.utils import ASSETS
  6. @pytest.mark.slow
  7. def test_similarity():
  8. """Test the correctness and response length of similarity calculations and SQL queries in the Explorer."""
  9. exp = Explorer(data="coco8.yaml")
  10. exp.create_embeddings_table()
  11. similar = exp.get_similar(idx=1)
  12. assert len(similar) == 4
  13. similar = exp.get_similar(img=ASSETS / "bus.jpg")
  14. assert len(similar) == 4
  15. similar = exp.get_similar(idx=[1, 2], limit=2)
  16. assert len(similar) == 2
  17. sim_idx = exp.similarity_index()
  18. assert len(sim_idx) == 4
  19. sql = exp.sql_query("WHERE labels LIKE '%zebra%'")
  20. assert len(sql) == 1
  21. @pytest.mark.slow
  22. def test_det():
  23. """Test detection functionalities and verify embedding table includes bounding boxes."""
  24. exp = Explorer(data="coco8.yaml", model="yolov8n.pt")
  25. exp.create_embeddings_table(force=True)
  26. assert len(exp.table.head()["bboxes"]) > 0
  27. similar = exp.get_similar(idx=[1, 2], limit=10)
  28. assert len(similar) > 0
  29. # This is a loose test, just checks errors not correctness
  30. similar = exp.plot_similar(idx=[1, 2], limit=10)
  31. assert isinstance(similar, PIL.Image.Image)
  32. @pytest.mark.slow
  33. def test_seg():
  34. """Test segmentation functionalities and ensure the embedding table includes segmentation masks."""
  35. exp = Explorer(data="coco8-seg.yaml", model="yolov8n-seg.pt")
  36. exp.create_embeddings_table(force=True)
  37. assert len(exp.table.head()["masks"]) > 0
  38. similar = exp.get_similar(idx=[1, 2], limit=10)
  39. assert len(similar) > 0
  40. similar = exp.plot_similar(idx=[1, 2], limit=10)
  41. assert isinstance(similar, PIL.Image.Image)
  42. @pytest.mark.slow
  43. def test_pose():
  44. """Test pose estimation functionality and verify the embedding table includes keypoints."""
  45. exp = Explorer(data="coco8-pose.yaml", model="yolov8n-pose.pt")
  46. exp.create_embeddings_table(force=True)
  47. assert len(exp.table.head()["keypoints"]) > 0
  48. similar = exp.get_similar(idx=[1, 2], limit=10)
  49. assert len(similar) > 0
  50. similar = exp.plot_similar(idx=[1, 2], limit=10)
  51. assert isinstance(similar, PIL.Image.Image)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...