ultralytics 8.3.50__py3-none-any.whl → 8.3.51__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ultralytics/__init__.py +1 -1
- ultralytics/cfg/solutions/default.yaml +3 -0
- ultralytics/engine/tuner.py +1 -1
- ultralytics/solutions/__init__.py +2 -0
- ultralytics/solutions/security_alarm.py +141 -0
- ultralytics/utils/autobatch.py +13 -5
- {ultralytics-8.3.50.dist-info → ultralytics-8.3.51.dist-info}/METADATA +1 -1
- {ultralytics-8.3.50.dist-info → ultralytics-8.3.51.dist-info}/RECORD +12 -11
- {ultralytics-8.3.50.dist-info → ultralytics-8.3.51.dist-info}/LICENSE +0 -0
- {ultralytics-8.3.50.dist-info → ultralytics-8.3.51.dist-info}/WHEEL +0 -0
- {ultralytics-8.3.50.dist-info → ultralytics-8.3.51.dist-info}/entry_points.txt +0 -0
- {ultralytics-8.3.50.dist-info → ultralytics-8.3.51.dist-info}/top_level.txt +0 -0
ultralytics/__init__.py
CHANGED
@@ -17,3 +17,6 @@ kpts: [6, 8, 10] # Keypoints for workouts monitoring, i.e. If you want to consid
|
|
17
17
|
# Analytics settings
|
18
18
|
analytics_type: "line" # Analytics type i.e "line", "pie", "bar" or "area" charts. By default, "line" analytics will be used for processing.
|
19
19
|
json_file: # parking system regions file path.
|
20
|
+
|
21
|
+
# Security alarm system
|
22
|
+
records: 5 # Total detections count to send an email about security
|
ultralytics/engine/tuner.py
CHANGED
@@ -191,7 +191,7 @@ class Tuner:
|
|
191
191
|
try:
|
192
192
|
# Train YOLO model with mutated hyperparameters (run in subprocess to avoid dataloader hang)
|
193
193
|
cmd = ["yolo", "train", *(f"{k}={v}" for k, v in train_args.items())]
|
194
|
-
return_code = subprocess.run(cmd, check=True).returncode
|
194
|
+
return_code = subprocess.run(" ".join(cmd), check=True, shell=True).returncode
|
195
195
|
ckpt_file = weights_dir / ("best.pt" if (weights_dir / "best.pt").exists() else "last.pt")
|
196
196
|
metrics = torch.load(ckpt_file)["train_metrics"]
|
197
197
|
assert return_code == 0, "training failed"
|
@@ -8,6 +8,7 @@ from .object_counter import ObjectCounter
|
|
8
8
|
from .parking_management import ParkingManagement, ParkingPtsSelection
|
9
9
|
from .queue_management import QueueManager
|
10
10
|
from .region_counter import RegionCounter
|
11
|
+
from .security_alarm import SecurityAlarm
|
11
12
|
from .speed_estimation import SpeedEstimator
|
12
13
|
from .streamlit_inference import inference
|
13
14
|
from .trackzone import TrackZone
|
@@ -25,4 +26,5 @@ __all__ = (
|
|
25
26
|
"inference",
|
26
27
|
"RegionCounter",
|
27
28
|
"TrackZone",
|
29
|
+
"SecurityAlarm",
|
28
30
|
)
|
@@ -0,0 +1,141 @@
|
|
1
|
+
# Ultralytics YOLO 🚀, AGPL-3.0 license
|
2
|
+
|
3
|
+
from ultralytics.solutions.solutions import LOGGER, BaseSolution
|
4
|
+
from ultralytics.utils.plotting import Annotator, colors
|
5
|
+
|
6
|
+
|
7
|
+
class SecurityAlarm(BaseSolution):
|
8
|
+
"""
|
9
|
+
A class to manage security alarm functionalities for real-time monitoring.
|
10
|
+
|
11
|
+
This class extends the BaseSolution class and provides features to monitor
|
12
|
+
objects in a frame, send email notifications when specific thresholds are
|
13
|
+
exceeded for total detections, and annotate the output frame for visualization.
|
14
|
+
|
15
|
+
Attributes:
|
16
|
+
email_sent (bool): Flag to track if an email has already been sent for the current event.
|
17
|
+
records (int): Threshold for the number of detected objects to trigger an alert.
|
18
|
+
|
19
|
+
Methods:
|
20
|
+
authenticate: Sets up email server authentication for sending alerts.
|
21
|
+
send_email: Sends an email notification with details and an image attachment.
|
22
|
+
monitor: Monitors the frame, processes detections, and triggers alerts if thresholds are crossed.
|
23
|
+
|
24
|
+
Examples:
|
25
|
+
>>> security = SecurityAlarm()
|
26
|
+
>>> security.authenticate("abc@gmail.com", "1111222233334444", "xyz@gmail.com")
|
27
|
+
>>> frame = cv2.imread("frame.jpg")
|
28
|
+
>>> processed_frame = security.monitor(frame)
|
29
|
+
"""
|
30
|
+
|
31
|
+
def __init__(self, **kwargs):
|
32
|
+
"""Initializes the SecurityAlarm class with parameters for real-time object monitoring."""
|
33
|
+
super().__init__(**kwargs)
|
34
|
+
self.email_sent = False
|
35
|
+
self.records = self.CFG["records"]
|
36
|
+
|
37
|
+
def authenticate(self, from_email, password, to_email):
|
38
|
+
"""
|
39
|
+
Authenticates the email server for sending alert notifications.
|
40
|
+
|
41
|
+
Args:
|
42
|
+
from_email (str): Sender's email address.
|
43
|
+
password (str): Password for the sender's email account.
|
44
|
+
to_email (str): Recipient's email address.
|
45
|
+
|
46
|
+
This method initializes a secure connection with the SMTP server
|
47
|
+
and logs in using the provided credentials.
|
48
|
+
|
49
|
+
Examples:
|
50
|
+
>>> alarm = SecurityAlarm()
|
51
|
+
>>> alarm.authenticate("sender@example.com", "password123", "recipient@example.com")
|
52
|
+
"""
|
53
|
+
import smtplib
|
54
|
+
|
55
|
+
self.server = smtplib.SMTP("smtp.gmail.com: 587")
|
56
|
+
self.server.starttls()
|
57
|
+
self.server.login(from_email, password)
|
58
|
+
self.to_email = to_email
|
59
|
+
self.from_email = from_email
|
60
|
+
|
61
|
+
def send_email(self, im0, records=5):
|
62
|
+
"""
|
63
|
+
Sends an email notification with an image attachment indicating the number of objects detected.
|
64
|
+
|
65
|
+
Args:
|
66
|
+
im0 (numpy.ndarray): The input image or frame to be attached to the email.
|
67
|
+
records (int): The number of detected objects to be included in the email message.
|
68
|
+
|
69
|
+
This method encodes the input image, composes the email message with
|
70
|
+
details about the detection, and sends it to the specified recipient.
|
71
|
+
|
72
|
+
Examples:
|
73
|
+
>>> alarm = SecurityAlarm()
|
74
|
+
>>> frame = cv2.imread("path/to/image.jpg")
|
75
|
+
>>> alarm.send_email(frame, records=10)
|
76
|
+
"""
|
77
|
+
from email.mime.image import MIMEImage
|
78
|
+
from email.mime.multipart import MIMEMultipart
|
79
|
+
from email.mime.text import MIMEText
|
80
|
+
|
81
|
+
import cv2
|
82
|
+
|
83
|
+
img_bytes = cv2.imencode(".jpg", im0)[1].tobytes() # Encode the image as JPEG
|
84
|
+
|
85
|
+
# Create the email
|
86
|
+
message = MIMEMultipart()
|
87
|
+
message["From"] = self.from_email
|
88
|
+
message["To"] = self.to_email
|
89
|
+
message["Subject"] = "Security Alert"
|
90
|
+
|
91
|
+
# Add the text message body
|
92
|
+
message_body = f"Ultralytics ALERT!!! " f"{records} objects have been detected!!"
|
93
|
+
message.attach(MIMEText(message_body, "plain"))
|
94
|
+
|
95
|
+
# Attach the image
|
96
|
+
image_attachment = MIMEImage(img_bytes, name="ultralytics.jpg")
|
97
|
+
message.attach(image_attachment)
|
98
|
+
|
99
|
+
# Send the email
|
100
|
+
try:
|
101
|
+
self.server.send_message(message)
|
102
|
+
LOGGER.info("✅ Email sent successfully!")
|
103
|
+
except Exception as e:
|
104
|
+
print(f"❌ Failed to send email: {e}")
|
105
|
+
|
106
|
+
def monitor(self, im0):
|
107
|
+
"""
|
108
|
+
Monitors the frame, processes object detections, and triggers alerts if thresholds are exceeded.
|
109
|
+
|
110
|
+
Args:
|
111
|
+
im0 (numpy.ndarray): The input image or frame to be processed and annotated.
|
112
|
+
|
113
|
+
This method processes the input frame, extracts detections, annotates the frame
|
114
|
+
with bounding boxes, and sends an email notification if the number of detected objects
|
115
|
+
surpasses the specified threshold and an alert has not already been sent.
|
116
|
+
|
117
|
+
Returns:
|
118
|
+
(numpy.ndarray): The processed frame with annotations.
|
119
|
+
|
120
|
+
Examples:
|
121
|
+
>>> alarm = SecurityAlarm()
|
122
|
+
>>> frame = cv2.imread("path/to/image.jpg")
|
123
|
+
>>> processed_frame = alarm.monitor(frame)
|
124
|
+
"""
|
125
|
+
self.annotator = Annotator(im0, line_width=self.line_width) # Initialize annotator
|
126
|
+
self.extract_tracks(im0) # Extract tracks
|
127
|
+
|
128
|
+
# Iterate over bounding boxes, track ids and classes index
|
129
|
+
for box, cls in zip(self.boxes, self.clss):
|
130
|
+
# Draw bounding box
|
131
|
+
self.annotator.box_label(box, label=self.names[cls], color=colors(cls, True))
|
132
|
+
|
133
|
+
total_det = len(self.clss)
|
134
|
+
if total_det > self.records: # Only send email If not sent before
|
135
|
+
if not self.email_sent:
|
136
|
+
self.send_email(im0, total_det)
|
137
|
+
self.email_sent = True
|
138
|
+
|
139
|
+
self.display_output(im0) # display output with base class function
|
140
|
+
|
141
|
+
return im0 # return output image for more usage
|
ultralytics/utils/autobatch.py
CHANGED
@@ -77,18 +77,26 @@ def autobatch(model, imgsz=640, fraction=0.60, batch_size=DEFAULT_CFG.batch, max
|
|
77
77
|
results = profile(img, model, n=1, device=device, max_num_obj=max_num_obj)
|
78
78
|
|
79
79
|
# Fit a solution
|
80
|
-
|
81
|
-
|
82
|
-
|
80
|
+
xy = [
|
81
|
+
[x, y[2]]
|
82
|
+
for i, (x, y) in enumerate(zip(batch_sizes, results))
|
83
|
+
if y # valid result
|
84
|
+
and isinstance(y[2], (int, float)) # is numeric
|
85
|
+
and 0 < y[2] < t # between 0 and GPU limit
|
86
|
+
and (i == 0 or not results[i - 1] or y[2] > results[i - 1][2]) # first item or increasing memory
|
87
|
+
]
|
88
|
+
fit_x, fit_y = zip(*xy) if xy else ([], [])
|
89
|
+
p = np.polyfit(np.log(fit_x), np.log(fit_y), deg=1) # first-degree polynomial fit in log space
|
90
|
+
b = int(round(np.exp((np.log(f * fraction) - p[1]) / p[0]))) # y intercept (optimal batch size)
|
83
91
|
if None in results: # some sizes failed
|
84
92
|
i = results.index(None) # first fail index
|
85
93
|
if b >= batch_sizes[i]: # y intercept above failure point
|
86
94
|
b = batch_sizes[max(i - 1, 0)] # select prior safe point
|
87
95
|
if b < 1 or b > 1024: # b outside of safe range
|
96
|
+
LOGGER.info(f"{prefix}WARNING ⚠️ batch={b} outside safe range, using default batch-size {batch_size}.")
|
88
97
|
b = batch_size
|
89
|
-
LOGGER.info(f"{prefix}WARNING ⚠️ CUDA anomaly detected, using default batch-size {batch_size}.")
|
90
98
|
|
91
|
-
fraction = (np.polyval(p, b) + r + a) / t #
|
99
|
+
fraction = (np.exp(np.polyval(p, np.log(b))) + r + a) / t # predicted fraction
|
92
100
|
LOGGER.info(f"{prefix}Using batch-size {b} for {d} {t * fraction:.2f}G/{t:.2f}G ({fraction * 100:.0f}%) ✅")
|
93
101
|
return b
|
94
102
|
except Exception as e:
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: ultralytics
|
3
|
-
Version: 8.3.
|
3
|
+
Version: 8.3.51
|
4
4
|
Summary: Ultralytics YOLO 🚀 for SOTA object detection, multi-object tracking, instance segmentation, pose estimation and image classification.
|
5
5
|
Author-email: Glenn Jocher <glenn.jocher@ultralytics.com>, Jing Qiu <jing.qiu@ultralytics.com>
|
6
6
|
Maintainer-email: Ultralytics <hello@ultralytics.com>
|
@@ -7,7 +7,7 @@ tests/test_exports.py,sha256=1MvhcQ2qHdbJImHII-bFarcaIcm-kPlEK-OdFLxnj7o,8769
|
|
7
7
|
tests/test_integrations.py,sha256=f5-QCUk1SU_-qn4mBCZwS3GN3tXEBIIXo4z2EhExbHw,6126
|
8
8
|
tests/test_python.py,sha256=IfHAXqilpYxWNmIE6rAWWUSeIYS6SBO9AkXGHDGZTvA,23182
|
9
9
|
tests/test_solutions.py,sha256=HlDe-XOgBX0k1cLhRTAhhawMHk6p-5dg5xl2AIRjfdk,3790
|
10
|
-
ultralytics/__init__.py,sha256=
|
10
|
+
ultralytics/__init__.py,sha256=N_1YdKbgbRhGjif32J6eXAFEks3rnGA2wmIqlcWYx84,681
|
11
11
|
ultralytics/assets/bus.jpg,sha256=wCAZxJecGR63Od3ZRERe9Aja1Weayrb9Ug751DS_vGM,137419
|
12
12
|
ultralytics/assets/zidane.jpg,sha256=Ftc4aeMmen1O0A3o6GCDO9FlfBslLpTAw0gnetx7bts,50427
|
13
13
|
ultralytics/cfg/__init__.py,sha256=etGrRb8t9r6R-n-00qFAmOZHXNriXEUe0zvEzCPi5oc,38921
|
@@ -86,7 +86,7 @@ ultralytics/cfg/models/v9/yolov9e.yaml,sha256=dhaR47WxuLOrZWDCceS4bQG00sQdrMc8FQ
|
|
86
86
|
ultralytics/cfg/models/v9/yolov9m.yaml,sha256=l6CmivzNu44sRVmkQXk4-tXflbV1nWnk5MSc8su2vhs,1311
|
87
87
|
ultralytics/cfg/models/v9/yolov9s.yaml,sha256=lPWcu-6ub1kCBD6zIDFwthYZ3RvdJfODWKy3vEQWRjo,1291
|
88
88
|
ultralytics/cfg/models/v9/yolov9t.yaml,sha256=qL__kr6GoefpQWP4jV0jdzwTp46bdFUcqtPRnfDbkY8,1275
|
89
|
-
ultralytics/cfg/solutions/default.yaml,sha256=
|
89
|
+
ultralytics/cfg/solutions/default.yaml,sha256=YaCj0YRRfkwJGf7bRN0idUJrWROq3T6lJE-IR14D5_c,1332
|
90
90
|
ultralytics/cfg/trackers/botsort.yaml,sha256=FDIrZ3hAhRtMfDl654pt1HIexmPqlFQK-3lQ4D0tF84,918
|
91
91
|
ultralytics/cfg/trackers/bytetrack.yaml,sha256=rBWY4RjjX6PTO2o6TUJFYHVgXNZHCN5TuBuzwuPYVjA,723
|
92
92
|
ultralytics/data/__init__.py,sha256=VGe-ATG7j35F4A4r8Jmzffjlhve4JAJPgRa5ahKTU18,616
|
@@ -105,7 +105,7 @@ ultralytics/engine/model.py,sha256=l5UiXGBa4ox9BXq0dc6eUsOvd85Q4KHUxGCwY2dfXQE,5
|
|
105
105
|
ultralytics/engine/predictor.py,sha256=o1RYMFH3_uVOMCIXXakpRYpNzoD-6Bdsxryt5fuBni0,17712
|
106
106
|
ultralytics/engine/results.py,sha256=a1XFZRPwqgKDBOEAibHuT9nP2xefLiWVsMoBJbcr4iA,75058
|
107
107
|
ultralytics/engine/trainer.py,sha256=Cd95QLJ3C4fncoOX1YgauLA9aWVYRd1G6x0Au2xX86k,37335
|
108
|
-
ultralytics/engine/tuner.py,sha256=
|
108
|
+
ultralytics/engine/tuner.py,sha256=0E0I3wOj1egLs-fwCB32_a6USVLUuDk_g6RaBhs0mJw,11860
|
109
109
|
ultralytics/engine/validator.py,sha256=fCBTYHwXAT6u4Pq-UYYZDZCwHjjB9ZWzFUdsENDt_Is,14888
|
110
110
|
ultralytics/hub/__init__.py,sha256=c6Me4E8V-P7mtzTggyPYz9FnVkqWRyPp9F-fMcyFNQ0,5632
|
111
111
|
ultralytics/hub/auth.py,sha256=pj_2NijotQpyG4_VJ6EAzNWGD93L6t-34J60yfiNZPc,5541
|
@@ -179,7 +179,7 @@ ultralytics/nn/modules/conv.py,sha256=DPLZCRno_ZOjsuajAXIq-GbJdOh2jp1WayRXfDEd8z
|
|
179
179
|
ultralytics/nn/modules/head.py,sha256=yZdDr71pWm-vB18XrNkbX35o3q4o4mhzrfJz6yVh9m4,27934
|
180
180
|
ultralytics/nn/modules/transformer.py,sha256=tGiK8NmPfswwW1rbF21r5ILUkkZQ6Nk4s8j16vFBmps,18069
|
181
181
|
ultralytics/nn/modules/utils.py,sha256=a88cKl2wz1nMVSEBiajtvaCbDBQIkESWOKTZ_WAJy90,3195
|
182
|
-
ultralytics/solutions/__init__.py,sha256=
|
182
|
+
ultralytics/solutions/__init__.py,sha256=zsW-vYzuKM6QGfpEPACcK4RYx-MmoDiW1GjyHCQ_a64,824
|
183
183
|
ultralytics/solutions/ai_gym.py,sha256=Jv8ERJqcSjQeFh78zCAH2XnXoTIngCK7X_7XOQ6cPzs,5255
|
184
184
|
ultralytics/solutions/analytics.py,sha256=C57pIghXeKN8hul8QOV7W9YDMpfFfSfPTBb-lE9HeAc,11535
|
185
185
|
ultralytics/solutions/distance_calculation.py,sha256=KN3CC-dm2dTQylj79IrifCJT8ZhE7hc2EweH3KK31mE,5461
|
@@ -188,6 +188,7 @@ ultralytics/solutions/object_counter.py,sha256=MuxQG4a22458WwciAB96m5AxVXwH98AIW
|
|
188
188
|
ultralytics/solutions/parking_management.py,sha256=Hh28FTuP_TaO7x5RadYm-JSVJuEu1M2SSgHqgdYYtr8,11198
|
189
189
|
ultralytics/solutions/queue_management.py,sha256=lIHBgdMSKmGGPrICY2HC01_Ofad-vu4AnaGAqH-DxMs,4931
|
190
190
|
ultralytics/solutions/region_counter.py,sha256=w0c0Sz9XG6rwzr5nA6nb1zFW8IVkTQuatfZNBtOik68,4947
|
191
|
+
ultralytics/solutions/security_alarm.py,sha256=NgOt5qcz9RrzUw9RDuXKyYxYfJM_XDZ0trizbJ1Y8v4,5588
|
191
192
|
ultralytics/solutions/solutions.py,sha256=BqkMDAq9A8kqL4TkjHLkMYXrJAdZPK-VAdNSObS1kNQ,7502
|
192
193
|
ultralytics/solutions/speed_estimation.py,sha256=A10DmuZlGkoZUyfHhZWcDRjj1-9GXiDhEjyBbAzfaDs,4936
|
193
194
|
ultralytics/solutions/streamlit_inference.py,sha256=w4dnvSv2FOrpji9W1Ir86phka3OXc7jd_38-OCbQdZw,5701
|
@@ -202,7 +203,7 @@ ultralytics/trackers/utils/gmc.py,sha256=VcURuY041qGCeWUGMxHZBr10T16LtcMqyv7AmTf
|
|
202
203
|
ultralytics/trackers/utils/kalman_filter.py,sha256=cH9zD3fwkuezP97H9mw8cSBN7a8hHKx_Sx1j7t3oYGs,21349
|
203
204
|
ultralytics/trackers/utils/matching.py,sha256=Y94cMwo9TLd-IWFqHKp8dHSDyguS1qtOeebBMalWnJQ,7078
|
204
205
|
ultralytics/utils/__init__.py,sha256=_KUqXbKcFgN11_ZLGrpQuPNOdSbIGhuv_IBGUPw9jX0,49203
|
205
|
-
ultralytics/utils/autobatch.py,sha256=
|
206
|
+
ultralytics/utils/autobatch.py,sha256=yBkojvLhZofwwKnaA8BnEIFXp3UWt7rVmyuh-dl1Ymk,5020
|
206
207
|
ultralytics/utils/benchmarks.py,sha256=Ub--iTq2hL_oHkG2R3HXmZXQ6qcBC-P9MabUv60bMLE,25625
|
207
208
|
ultralytics/utils/checks.py,sha256=1Cu8k2qg_pFaoHvkiE07Ab5ZGLyZHZxFAg1IMM63CBQ,30145
|
208
209
|
ultralytics/utils/dist.py,sha256=NDFga-uKxkBX2zLxFHSene_cCiGQJoyOeCXcN9JIOIk,2358
|
@@ -230,9 +231,9 @@ ultralytics/utils/callbacks/neptune.py,sha256=IbGQfEltamUKXJt93uSLQFn8c2rYh3DMTg
|
|
230
231
|
ultralytics/utils/callbacks/raytune.py,sha256=Ck_yFzg7UZXiDWrLHaltjQybzVWSFDfzpdrx9ZYTRfI,700
|
231
232
|
ultralytics/utils/callbacks/tensorboard.py,sha256=SHlE58Fb-sg-uZKtgy-ybIO3SAIfK55aj8kTYGA0Cyg,4167
|
232
233
|
ultralytics/utils/callbacks/wb.py,sha256=sizfTa-xI9k2pnDSP_Q9pHZEFwcl__gSFM0AcneuRpY,7058
|
233
|
-
ultralytics-8.3.
|
234
|
-
ultralytics-8.3.
|
235
|
-
ultralytics-8.3.
|
236
|
-
ultralytics-8.3.
|
237
|
-
ultralytics-8.3.
|
238
|
-
ultralytics-8.3.
|
234
|
+
ultralytics-8.3.51.dist-info/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
|
235
|
+
ultralytics-8.3.51.dist-info/METADATA,sha256=q5i3qgmMzgn2vLxSqF_NwhKgiOrxSFjfUnuaJvm8inQ,35332
|
236
|
+
ultralytics-8.3.51.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
237
|
+
ultralytics-8.3.51.dist-info/entry_points.txt,sha256=YM_wiKyTe9yRrsEfqvYolNO5ngwfoL4-NwgKzc8_7sI,93
|
238
|
+
ultralytics-8.3.51.dist-info/top_level.txt,sha256=XP49TwiMw4QGsvTLSYiJhz1xF_k7ev5mQ8jJXaXi45Q,12
|
239
|
+
ultralytics-8.3.51.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|