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 3.7 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
82
83
84
85
  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) # Test object counter
  16. heatmap = solutions.Heatmap(colormap=cv2.COLORMAP_PARULA, model="yolo11n.pt", show=False) # Test heatmaps
  17. speed = solutions.SpeedEstimator(region=region_points, model="yolo11n.pt", show=False) # Test queue manager
  18. queue = solutions.QueueManager(region=region_points, model="yolo11n.pt", show=False) # Test speed estimation
  19. line_analytics = solutions.Analytics(analytics_type="line", model="yolo11n.pt", show=False) # line analytics
  20. pie_analytics = solutions.Analytics(analytics_type="pie", model="yolo11n.pt", show=False) # line analytics
  21. bar_analytics = solutions.Analytics(analytics_type="bar", model="yolo11n.pt", show=False) # line analytics
  22. area_analytics = solutions.Analytics(analytics_type="area", model="yolo11n.pt", show=False) # line analytics
  23. frame_count = 0 # Required for analytics
  24. while cap.isOpened():
  25. success, im0 = cap.read()
  26. if not success:
  27. break
  28. original_im0 = im0.copy()
  29. _ = counter.count(original_im0.copy())
  30. _ = heatmap.generate_heatmap(original_im0.copy())
  31. _ = speed.estimate_speed(original_im0.copy())
  32. _ = queue.process_queue(original_im0.copy())
  33. _ = line_analytics.process_data(original_im0.copy(), frame_count)
  34. _ = pie_analytics.process_data(original_im0.copy(), frame_count)
  35. _ = bar_analytics.process_data(original_im0.copy(), frame_count)
  36. _ = area_analytics.process_data(original_im0.copy(), frame_count)
  37. cap.release()
  38. # Test workouts monitoring
  39. safe_download(url=WORKOUTS_SOLUTION_DEMO)
  40. cap1 = cv2.VideoCapture("solution_ci_pose_demo.mp4")
  41. assert cap1.isOpened(), "Error reading video file"
  42. gym = solutions.AIGym(line_width=2, kpts=[5, 11, 13], show=False)
  43. while cap1.isOpened():
  44. success, im0 = cap1.read()
  45. if not success:
  46. break
  47. _ = gym.monitor(im0)
  48. cap1.release()
  49. @pytest.mark.slow
  50. def test_instance_segmentation():
  51. """Test the instance segmentation solution."""
  52. from ultralytics.utils.plotting import Annotator, colors
  53. model = YOLO("yolo11n-seg.pt")
  54. names = model.names
  55. cap = cv2.VideoCapture("solutions_ci_demo.mp4")
  56. assert cap.isOpened(), "Error reading video file"
  57. while cap.isOpened():
  58. success, im0 = cap.read()
  59. if not success:
  60. break
  61. results = model.predict(im0)
  62. annotator = Annotator(im0, line_width=2)
  63. if results[0].masks is not None:
  64. clss = results[0].boxes.cls.cpu().tolist()
  65. masks = results[0].masks.xy
  66. for mask, cls in zip(masks, clss):
  67. color = colors(int(cls), True)
  68. annotator.seg_bbox(mask=mask, mask_color=color, label=names[int(cls)])
  69. cap.release()
  70. cv2.destroyAllWindows()
  71. @pytest.mark.slow
  72. def test_streamlit_predict():
  73. """Test streamlit predict live inference solution."""
  74. solutions.inference()
Tip!

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

Comments

Loading...