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_solutions.py 2.9 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
  1. # Ultralytics YOLO 🚀, AGPL-3.0 license
  2. import cv2
  3. import pytest
  4. from ultralytics import YOLO, solutions
  5. from ultralytics.utils.downloads import safe_download
  6. MAJOR_SOLUTIONS_DEMO = "https://github.com/ultralytics/assets/releases/download/v0.0.0/solutions_ci_demo.mp4"
  7. WORKOUTS_SOLUTION_DEMO = "https://github.com/ultralytics/assets/releases/download/v0.0.0/solution_ci_pose_demo.mp4"
  8. @pytest.mark.slow
  9. def test_major_solutions():
  10. """Test the object counting, heatmap, speed estimation and queue management solution."""
  11. safe_download(url=MAJOR_SOLUTIONS_DEMO)
  12. cap = cv2.VideoCapture("solutions_ci_demo.mp4")
  13. assert cap.isOpened(), "Error reading video file"
  14. region_points = [(20, 400), (1080, 404), (1080, 360), (20, 360)]
  15. counter = solutions.ObjectCounter(region=region_points, model="yolo11n.pt", show=False)
  16. heatmap = solutions.Heatmap(colormap=cv2.COLORMAP_PARULA, model="yolo11n.pt", show=False)
  17. speed = solutions.SpeedEstimator(region=region_points, model="yolo11n.pt", show=False)
  18. queue = solutions.QueueManager(region=region_points, model="yolo11n.pt", show=False)
  19. while cap.isOpened():
  20. success, im0 = cap.read()
  21. if not success:
  22. break
  23. original_im0 = im0.copy()
  24. _ = counter.count(original_im0.copy())
  25. _ = heatmap.generate_heatmap(original_im0.copy())
  26. _ = speed.estimate_speed(original_im0.copy())
  27. _ = queue.process_queue(original_im0.copy())
  28. cap.release()
  29. cv2.destroyAllWindows()
  30. @pytest.mark.slow
  31. def test_aigym():
  32. """Test the workouts monitoring solution."""
  33. safe_download(url=WORKOUTS_SOLUTION_DEMO)
  34. cap = cv2.VideoCapture("solution_ci_pose_demo.mp4")
  35. assert cap.isOpened(), "Error reading video file"
  36. gym = solutions.AIGym(line_width=2, kpts=[5, 11, 13])
  37. while cap.isOpened():
  38. success, im0 = cap.read()
  39. if not success:
  40. break
  41. _ = gym.monitor(im0)
  42. cap.release()
  43. cv2.destroyAllWindows()
  44. @pytest.mark.slow
  45. def test_instance_segmentation():
  46. """Test the instance segmentation solution."""
  47. from ultralytics.utils.plotting import Annotator, colors
  48. model = YOLO("yolo11n-seg.pt")
  49. names = model.names
  50. cap = cv2.VideoCapture("solutions_ci_demo.mp4")
  51. assert cap.isOpened(), "Error reading video file"
  52. while cap.isOpened():
  53. success, im0 = cap.read()
  54. if not success:
  55. break
  56. results = model.predict(im0)
  57. annotator = Annotator(im0, line_width=2)
  58. if results[0].masks is not None:
  59. clss = results[0].boxes.cls.cpu().tolist()
  60. masks = results[0].masks.xy
  61. for mask, cls in zip(masks, clss):
  62. color = colors(int(cls), True)
  63. annotator.seg_bbox(mask=mask, mask_color=color, label=names[int(cls)])
  64. cap.release()
  65. cv2.destroyAllWindows()
  66. @pytest.mark.slow
  67. def test_streamlit_predict():
  68. """Test streamlit predict live inference solution."""
  69. solutions.inference()
Tip!

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

Comments

Loading...