ultralytics 8.2.95__py3-none-any.whl → 8.2.97__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.
Potentially problematic release.
This version of ultralytics might be problematic. Click here for more details.
- tests/test_python.py +4 -1
- ultralytics/__init__.py +1 -1
- ultralytics/cfg/__init__.py +1 -0
- ultralytics/engine/model.py +5 -17
- ultralytics/engine/results.py +85 -1
- ultralytics/engine/validator.py +2 -1
- ultralytics/hub/session.py +22 -28
- ultralytics/solutions/parking_management.py +81 -111
- ultralytics/utils/checks.py +3 -2
- {ultralytics-8.2.95.dist-info → ultralytics-8.2.97.dist-info}/METADATA +1 -1
- {ultralytics-8.2.95.dist-info → ultralytics-8.2.97.dist-info}/RECORD +15 -15
- {ultralytics-8.2.95.dist-info → ultralytics-8.2.97.dist-info}/LICENSE +0 -0
- {ultralytics-8.2.95.dist-info → ultralytics-8.2.97.dist-info}/WHEEL +0 -0
- {ultralytics-8.2.95.dist-info → ultralytics-8.2.97.dist-info}/entry_points.txt +0 -0
- {ultralytics-8.2.95.dist-info → ultralytics-8.2.97.dist-info}/top_level.txt +0 -0
tests/test_python.py
CHANGED
|
@@ -269,7 +269,10 @@ def test_results(model):
|
|
|
269
269
|
r = r.to(device="cpu", dtype=torch.float32)
|
|
270
270
|
r.save_txt(txt_file=TMP / "runs/tests/label.txt", save_conf=True)
|
|
271
271
|
r.save_crop(save_dir=TMP / "runs/tests/crops/")
|
|
272
|
-
r.
|
|
272
|
+
r.to_json(normalize=True)
|
|
273
|
+
r.to_df(decimals=3)
|
|
274
|
+
r.to_csv()
|
|
275
|
+
r.to_xml()
|
|
273
276
|
r.plot(pil=True)
|
|
274
277
|
r.plot(conf=True, boxes=True)
|
|
275
278
|
print(r, len(r), r.path) # print after methods
|
ultralytics/__init__.py
CHANGED
ultralytics/cfg/__init__.py
CHANGED
|
@@ -712,6 +712,7 @@ def entrypoint(debug=""):
|
|
|
712
712
|
"cfg": lambda: yaml_print(DEFAULT_CFG_PATH),
|
|
713
713
|
"hub": lambda: handle_yolo_hub(args[1:]),
|
|
714
714
|
"login": lambda: handle_yolo_hub(args),
|
|
715
|
+
"logout": lambda: handle_yolo_hub(args),
|
|
715
716
|
"copy-cfg": copy_default_cfg,
|
|
716
717
|
"explorer": lambda: handle_explorer(args[1:]),
|
|
717
718
|
"streamlit-predict": lambda: handle_streamlit_inference(),
|
ultralytics/engine/model.py
CHANGED
|
@@ -206,33 +206,21 @@ class Model(nn.Module):
|
|
|
206
206
|
Check if the provided model is an Ultralytics HUB model.
|
|
207
207
|
|
|
208
208
|
This static method determines whether the given model string represents a valid Ultralytics HUB model
|
|
209
|
-
identifier.
|
|
210
|
-
or a standalone model ID.
|
|
209
|
+
identifier.
|
|
211
210
|
|
|
212
211
|
Args:
|
|
213
|
-
model (str): The model
|
|
214
|
-
combination, or a standalone model ID.
|
|
212
|
+
model (str): The model string to check.
|
|
215
213
|
|
|
216
214
|
Returns:
|
|
217
215
|
(bool): True if the model is a valid Ultralytics HUB model, False otherwise.
|
|
218
216
|
|
|
219
217
|
Examples:
|
|
220
|
-
>>> Model.is_hub_model("https://hub.ultralytics.com/models/
|
|
218
|
+
>>> Model.is_hub_model("https://hub.ultralytics.com/models/MODEL")
|
|
221
219
|
True
|
|
222
|
-
>>> Model.is_hub_model("
|
|
223
|
-
True
|
|
224
|
-
>>> Model.is_hub_model("example_model_id")
|
|
225
|
-
True
|
|
226
|
-
>>> Model.is_hub_model("not_a_hub_model.pt")
|
|
220
|
+
>>> Model.is_hub_model("yolov8n.pt")
|
|
227
221
|
False
|
|
228
222
|
"""
|
|
229
|
-
return
|
|
230
|
-
(
|
|
231
|
-
model.startswith(f"{HUB_WEB_ROOT}/models/"), # i.e. https://hub.ultralytics.com/models/MODEL_ID
|
|
232
|
-
[len(x) for x in model.split("_")] == [42, 20], # APIKEY_MODEL
|
|
233
|
-
len(model) == 20 and not Path(model).exists() and all(x not in model for x in "./\\"), # MODEL
|
|
234
|
-
)
|
|
235
|
-
)
|
|
223
|
+
return model.startswith(f"{HUB_WEB_ROOT}/models/")
|
|
236
224
|
|
|
237
225
|
def _new(self, cfg: str, task=None, model=None, verbose=False) -> None:
|
|
238
226
|
"""
|
ultralytics/engine/results.py
CHANGED
|
@@ -14,6 +14,7 @@ import torch
|
|
|
14
14
|
|
|
15
15
|
from ultralytics.data.augment import LetterBox
|
|
16
16
|
from ultralytics.utils import LOGGER, SimpleClass, ops
|
|
17
|
+
from ultralytics.utils.checks import check_requirements
|
|
17
18
|
from ultralytics.utils.plotting import Annotator, colors, save_one_box
|
|
18
19
|
from ultralytics.utils.torch_utils import smart_inference_mode
|
|
19
20
|
|
|
@@ -818,7 +819,90 @@ class Results(SimpleClass):
|
|
|
818
819
|
|
|
819
820
|
return results
|
|
820
821
|
|
|
822
|
+
def to_df(self, normalize=False, decimals=5):
|
|
823
|
+
"""
|
|
824
|
+
Converts detection results to a Pandas Dataframe.
|
|
825
|
+
|
|
826
|
+
This method converts the detection results into Pandas Dataframe format. It includes information
|
|
827
|
+
about detected objects such as bounding boxes, class names, confidence scores, and optionally
|
|
828
|
+
segmentation masks and keypoints.
|
|
829
|
+
|
|
830
|
+
Args:
|
|
831
|
+
normalize (bool): Whether to normalize the bounding box coordinates by the image dimensions.
|
|
832
|
+
If True, coordinates will be returned as float values between 0 and 1. Defaults to False.
|
|
833
|
+
decimals (int): Number of decimal places to round the output values to. Defaults to 5.
|
|
834
|
+
|
|
835
|
+
Returns:
|
|
836
|
+
(DataFrame): A Pandas Dataframe containing all the information in results in an organized way.
|
|
837
|
+
|
|
838
|
+
Examples:
|
|
839
|
+
>>> results = model("path/to/image.jpg")
|
|
840
|
+
>>> df_result = results[0].to_df()
|
|
841
|
+
>>> print(df_result)
|
|
842
|
+
"""
|
|
843
|
+
import pandas as pd
|
|
844
|
+
|
|
845
|
+
return pd.DataFrame(self.summary(normalize=normalize, decimals=decimals))
|
|
846
|
+
|
|
847
|
+
def to_csv(self, normalize=False, decimals=5, *args, **kwargs):
|
|
848
|
+
"""
|
|
849
|
+
Converts detection results to a CSV format.
|
|
850
|
+
|
|
851
|
+
This method serializes the detection results into a CSV format. It includes information
|
|
852
|
+
about detected objects such as bounding boxes, class names, confidence scores, and optionally
|
|
853
|
+
segmentation masks and keypoints.
|
|
854
|
+
|
|
855
|
+
Args:
|
|
856
|
+
normalize (bool): Whether to normalize the bounding box coordinates by the image dimensions.
|
|
857
|
+
If True, coordinates will be returned as float values between 0 and 1. Defaults to False.
|
|
858
|
+
decimals (int): Number of decimal places to round the output values to. Defaults to 5.
|
|
859
|
+
*args (Any): Variable length argument list to be passed to pandas.DataFrame.to_csv().
|
|
860
|
+
**kwargs (Any): Arbitrary keyword arguments to be passed to pandas.DataFrame.to_csv().
|
|
861
|
+
|
|
862
|
+
|
|
863
|
+
Returns:
|
|
864
|
+
(str): CSV containing all the information in results in an organized way.
|
|
865
|
+
|
|
866
|
+
Examples:
|
|
867
|
+
>>> results = model("path/to/image.jpg")
|
|
868
|
+
>>> csv_result = results[0].to_csv()
|
|
869
|
+
>>> print(csv_result)
|
|
870
|
+
"""
|
|
871
|
+
return self.to_df(normalize=normalize, decimals=decimals).to_csv(*args, **kwargs)
|
|
872
|
+
|
|
873
|
+
def to_xml(self, normalize=False, decimals=5, *args, **kwargs):
|
|
874
|
+
"""
|
|
875
|
+
Converts detection results to XML format.
|
|
876
|
+
|
|
877
|
+
This method serializes the detection results into an XML format. It includes information
|
|
878
|
+
about detected objects such as bounding boxes, class names, confidence scores, and optionally
|
|
879
|
+
segmentation masks and keypoints.
|
|
880
|
+
|
|
881
|
+
Args:
|
|
882
|
+
normalize (bool): Whether to normalize the bounding box coordinates by the image dimensions.
|
|
883
|
+
If True, coordinates will be returned as float values between 0 and 1. Defaults to False.
|
|
884
|
+
decimals (int): Number of decimal places to round the output values to. Defaults to 5.
|
|
885
|
+
*args (Any): Variable length argument list to be passed to pandas.DataFrame.to_xml().
|
|
886
|
+
**kwargs (Any): Arbitrary keyword arguments to be passed to pandas.DataFrame.to_xml().
|
|
887
|
+
|
|
888
|
+
Returns:
|
|
889
|
+
(str): An XML string containing all the information in results in an organized way.
|
|
890
|
+
|
|
891
|
+
Examples:
|
|
892
|
+
>>> results = model("path/to/image.jpg")
|
|
893
|
+
>>> xml_result = results[0].to_xml()
|
|
894
|
+
>>> print(xml_result)
|
|
895
|
+
"""
|
|
896
|
+
check_requirements("lxml")
|
|
897
|
+
df = self.to_df(normalize=normalize, decimals=decimals)
|
|
898
|
+
return '<?xml version="1.0" encoding="utf-8"?>\n<root></root>' if df.empty else df.to_xml(*args, **kwargs)
|
|
899
|
+
|
|
821
900
|
def tojson(self, normalize=False, decimals=5):
|
|
901
|
+
"""Deprecated version of to_json()."""
|
|
902
|
+
LOGGER.warning("WARNING ⚠️ 'result.tojson()' is deprecated, replace with 'result.to_json()'.")
|
|
903
|
+
return self.to_json(normalize, decimals)
|
|
904
|
+
|
|
905
|
+
def to_json(self, normalize=False, decimals=5):
|
|
822
906
|
"""
|
|
823
907
|
Converts detection results to JSON format.
|
|
824
908
|
|
|
@@ -836,7 +920,7 @@ class Results(SimpleClass):
|
|
|
836
920
|
|
|
837
921
|
Examples:
|
|
838
922
|
>>> results = model("path/to/image.jpg")
|
|
839
|
-
>>> json_result = results[0].
|
|
923
|
+
>>> json_result = results[0].to_json()
|
|
840
924
|
>>> print(json_result)
|
|
841
925
|
|
|
842
926
|
Notes:
|
ultralytics/engine/validator.py
CHANGED
|
@@ -110,7 +110,8 @@ class BaseValidator:
|
|
|
110
110
|
if self.training:
|
|
111
111
|
self.device = trainer.device
|
|
112
112
|
self.data = trainer.data
|
|
113
|
-
|
|
113
|
+
# force FP16 val during training
|
|
114
|
+
self.args.half = self.device.type != "cpu" and trainer.amp
|
|
114
115
|
model = trainer.ema.ema or trainer.model
|
|
115
116
|
model = model.half() if self.args.half else model.float()
|
|
116
117
|
# self.model = model
|
ultralytics/hub/session.py
CHANGED
|
@@ -5,6 +5,7 @@ import threading
|
|
|
5
5
|
import time
|
|
6
6
|
from http import HTTPStatus
|
|
7
7
|
from pathlib import Path
|
|
8
|
+
from urllib.parse import parse_qs, urlparse
|
|
8
9
|
|
|
9
10
|
import requests
|
|
10
11
|
|
|
@@ -77,7 +78,6 @@ class HUBTrainingSession:
|
|
|
77
78
|
if not session.client.authenticated:
|
|
78
79
|
if identifier.startswith(f"{HUB_WEB_ROOT}/models/"):
|
|
79
80
|
LOGGER.warning(f"{PREFIX}WARNING ⚠️ Login to Ultralytics HUB with 'yolo hub login API_KEY'.")
|
|
80
|
-
exit()
|
|
81
81
|
return None
|
|
82
82
|
if args and not identifier.startswith(f"{HUB_WEB_ROOT}/models/"): # not a HUB model URL
|
|
83
83
|
session.create_model(args)
|
|
@@ -96,7 +96,8 @@ class HUBTrainingSession:
|
|
|
96
96
|
self.model_url = f"{HUB_WEB_ROOT}/models/{self.model.id}"
|
|
97
97
|
if self.model.is_trained():
|
|
98
98
|
print(emojis(f"Loading trained HUB model {self.model_url} 🚀"))
|
|
99
|
-
|
|
99
|
+
url = self.model.get_weights_url("best") # download URL with auth
|
|
100
|
+
self.model_file = checks.check_file(url, download_dir=Path(SETTINGS["weights_dir"]) / "hub" / self.model.id)
|
|
100
101
|
return
|
|
101
102
|
|
|
102
103
|
# Set training args and start heartbeats for HUB to monitor agent
|
|
@@ -146,9 +147,8 @@ class HUBTrainingSession:
|
|
|
146
147
|
Parses the given identifier to determine the type of identifier and extract relevant components.
|
|
147
148
|
|
|
148
149
|
The method supports different identifier formats:
|
|
149
|
-
- A HUB URL
|
|
150
|
-
-
|
|
151
|
-
- An identifier that is solely a model ID of a fixed length
|
|
150
|
+
- A HUB model URL https://hub.ultralytics.com/models/MODEL
|
|
151
|
+
- A HUB model URL with API Key https://hub.ultralytics.com/models/MODEL?api_key=APIKEY
|
|
152
152
|
- A local filename that ends with '.pt' or '.yaml'
|
|
153
153
|
|
|
154
154
|
Args:
|
|
@@ -160,32 +160,26 @@ class HUBTrainingSession:
|
|
|
160
160
|
Raises:
|
|
161
161
|
HUBModelError: If the identifier format is not recognized.
|
|
162
162
|
"""
|
|
163
|
-
# Initialize variables
|
|
164
163
|
api_key, model_id, filename = None, None, None
|
|
165
164
|
|
|
166
|
-
#
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
165
|
+
# path = identifier.split(f"{HUB_WEB_ROOT}/models/")[-1]
|
|
166
|
+
# parts = path.split("_")
|
|
167
|
+
# if Path(path).suffix in {".pt", ".yaml"}:
|
|
168
|
+
# filename = path
|
|
169
|
+
# elif len(parts) == 2 and len(parts[0]) == 42 and len(parts[1]) == 20:
|
|
170
|
+
# api_key, model_id = parts
|
|
171
|
+
# elif len(path) == 20:
|
|
172
|
+
# model_id = path
|
|
173
|
+
|
|
174
|
+
if Path(identifier).suffix in {".pt", ".yaml"}:
|
|
175
|
+
filename = identifier
|
|
176
|
+
elif identifier.startswith(f"{HUB_WEB_ROOT}/models/"):
|
|
177
|
+
parsed_url = urlparse(identifier)
|
|
178
|
+
model_id = Path(parsed_url.path).stem # handle possible final backslash robustly
|
|
179
|
+
query_params = parse_qs(parsed_url.query) # dictionary, i.e. {"api_key": ["API_KEY_HERE"]}
|
|
180
|
+
api_key = query_params.get("api_key", [None])[0]
|
|
170
181
|
else:
|
|
171
|
-
|
|
172
|
-
parts = identifier.split("_")
|
|
173
|
-
|
|
174
|
-
# Check if identifier is in the format of API key and model ID
|
|
175
|
-
if len(parts) == 2 and len(parts[0]) == 42 and len(parts[1]) == 20:
|
|
176
|
-
api_key, model_id = parts
|
|
177
|
-
# Check if identifier is a single model ID
|
|
178
|
-
elif len(parts) == 1 and len(parts[0]) == 20:
|
|
179
|
-
model_id = parts[0]
|
|
180
|
-
# Check if identifier is a local filename
|
|
181
|
-
elif identifier.endswith(".pt") or identifier.endswith(".yaml"):
|
|
182
|
-
filename = identifier
|
|
183
|
-
else:
|
|
184
|
-
raise HUBModelError(
|
|
185
|
-
f"model='{identifier}' could not be parsed. Check format is correct. "
|
|
186
|
-
f"Supported formats are Ultralytics HUB URL, apiKey_modelId, modelId, local pt or yaml file."
|
|
187
|
-
)
|
|
188
|
-
|
|
182
|
+
raise HUBModelError(f"model='{identifier} invalid, correct format is {HUB_WEB_ROOT}/models/MODEL_ID")
|
|
189
183
|
return api_key, model_id, filename
|
|
190
184
|
|
|
191
185
|
def _set_train_args(self):
|
|
@@ -42,10 +42,10 @@ class ParkingPtsSelection:
|
|
|
42
42
|
self.image_path = None
|
|
43
43
|
self.image = None
|
|
44
44
|
self.canvas_image = None
|
|
45
|
-
self.
|
|
45
|
+
self.rg_data = [] # region coordinates
|
|
46
46
|
self.current_box = []
|
|
47
|
-
self.
|
|
48
|
-
self.
|
|
47
|
+
self.imgw = 0 # image width
|
|
48
|
+
self.imgh = 0 # image height
|
|
49
49
|
|
|
50
50
|
# Constants
|
|
51
51
|
self.canvas_max_width = 1280
|
|
@@ -64,17 +64,17 @@ class ParkingPtsSelection:
|
|
|
64
64
|
return
|
|
65
65
|
|
|
66
66
|
self.image = Image.open(self.image_path)
|
|
67
|
-
self.
|
|
67
|
+
self.imgw, self.imgh = self.image.size
|
|
68
68
|
|
|
69
69
|
# Calculate the aspect ratio and resize image
|
|
70
|
-
aspect_ratio = self.
|
|
70
|
+
aspect_ratio = self.imgw / self.imgh
|
|
71
71
|
if aspect_ratio > 1:
|
|
72
72
|
# Landscape orientation
|
|
73
|
-
canvas_width = min(self.canvas_max_width, self.
|
|
73
|
+
canvas_width = min(self.canvas_max_width, self.imgw)
|
|
74
74
|
canvas_height = int(canvas_width / aspect_ratio)
|
|
75
75
|
else:
|
|
76
76
|
# Portrait orientation
|
|
77
|
-
canvas_height = min(self.canvas_max_height, self.
|
|
77
|
+
canvas_height = min(self.canvas_max_height, self.imgh)
|
|
78
78
|
canvas_width = int(canvas_height * aspect_ratio)
|
|
79
79
|
|
|
80
80
|
# Check if canvas is already initialized
|
|
@@ -90,46 +90,34 @@ class ParkingPtsSelection:
|
|
|
90
90
|
self.canvas.bind("<Button-1>", self.on_canvas_click)
|
|
91
91
|
|
|
92
92
|
# Reset bounding boxes and current box
|
|
93
|
-
self.
|
|
93
|
+
self.rg_data = []
|
|
94
94
|
self.current_box = []
|
|
95
95
|
|
|
96
96
|
def on_canvas_click(self, event):
|
|
97
97
|
"""Handle mouse clicks on canvas to create points for bounding boxes."""
|
|
98
98
|
self.current_box.append((event.x, event.y))
|
|
99
|
-
|
|
100
|
-
x1, y1 = event.x + 3, event.y + 3
|
|
101
|
-
self.canvas.create_oval(x0, y0, x1, y1, fill="red")
|
|
99
|
+
self.canvas.create_oval(event.x - 3, event.y - 3, event.x + 3, event.y + 3, fill="red")
|
|
102
100
|
|
|
103
101
|
if len(self.current_box) == 4:
|
|
104
|
-
self.
|
|
105
|
-
|
|
102
|
+
self.rg_data.append(self.current_box)
|
|
103
|
+
[
|
|
104
|
+
self.canvas.create_line(self.current_box[i], self.current_box[(i + 1) % 4], fill="blue", width=2)
|
|
105
|
+
for i in range(4)
|
|
106
|
+
]
|
|
106
107
|
self.current_box = []
|
|
107
108
|
|
|
108
|
-
def draw_bounding_box(self, box):
|
|
109
|
-
"""
|
|
110
|
-
Draw bounding box on canvas.
|
|
111
|
-
|
|
112
|
-
Args:
|
|
113
|
-
box (list): Bounding box data
|
|
114
|
-
"""
|
|
115
|
-
for i in range(4):
|
|
116
|
-
x1, y1 = box[i]
|
|
117
|
-
x2, y2 = box[(i + 1) % 4]
|
|
118
|
-
self.canvas.create_line(x1, y1, x2, y2, fill="blue", width=2)
|
|
119
|
-
|
|
120
109
|
def remove_last_bounding_box(self):
|
|
121
110
|
"""Remove the last drawn bounding box from canvas."""
|
|
122
111
|
from tkinter import messagebox # scope for multi-environment compatibility
|
|
123
112
|
|
|
124
|
-
if self.
|
|
125
|
-
self.
|
|
113
|
+
if self.rg_data:
|
|
114
|
+
self.rg_data.pop() # Remove the last bounding box
|
|
126
115
|
self.canvas.delete("all") # Clear the canvas
|
|
127
116
|
self.canvas.create_image(0, 0, anchor=self.tk.NW, image=self.canvas_image) # Redraw the image
|
|
128
117
|
|
|
129
118
|
# Redraw all bounding boxes
|
|
130
|
-
for box in self.
|
|
131
|
-
self.
|
|
132
|
-
|
|
119
|
+
for box in self.rg_data:
|
|
120
|
+
[self.canvas.create_line(box[i], box[(i + 1) % 4], fill="blue", width=2) for i in range(4)]
|
|
133
121
|
messagebox.showinfo("Success", "Last bounding box removed.")
|
|
134
122
|
else:
|
|
135
123
|
messagebox.showwarning("Warning", "No bounding boxes to remove.")
|
|
@@ -138,19 +126,19 @@ class ParkingPtsSelection:
|
|
|
138
126
|
"""Saves rescaled bounding boxes to 'bounding_boxes.json' based on image-to-canvas size ratio."""
|
|
139
127
|
from tkinter import messagebox # scope for multi-environment compatibility
|
|
140
128
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
bounding_boxes_data = []
|
|
145
|
-
for box in self.bounding_boxes:
|
|
146
|
-
rescaled_box = []
|
|
129
|
+
rg_data = [] # regions data
|
|
130
|
+
for box in self.rg_data:
|
|
131
|
+
rs_box = [] # rescaled box list
|
|
147
132
|
for x, y in box:
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
133
|
+
rs_box.append(
|
|
134
|
+
(
|
|
135
|
+
int(x * self.imgw / self.canvas.winfo_width()), # width scaling
|
|
136
|
+
int(y * self.imgh / self.canvas.winfo_height()),
|
|
137
|
+
)
|
|
138
|
+
) # height scaling
|
|
139
|
+
rg_data.append({"points": rs_box})
|
|
152
140
|
with open("bounding_boxes.json", "w") as f:
|
|
153
|
-
json.dump(
|
|
141
|
+
json.dump(rg_data, f, indent=4)
|
|
154
142
|
|
|
155
143
|
messagebox.showinfo("Success", "Bounding boxes saved to bounding_boxes.json")
|
|
156
144
|
|
|
@@ -160,102 +148,85 @@ class ParkingManagement:
|
|
|
160
148
|
|
|
161
149
|
def __init__(
|
|
162
150
|
self,
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
available_region_color=(0, 0, 255),
|
|
168
|
-
margin=10,
|
|
151
|
+
model, # Ultralytics YOLO model file path
|
|
152
|
+
json_file, # Parking management annotation file created from Parking Annotator
|
|
153
|
+
occupied_region_color=(0, 0, 255), # occupied region color
|
|
154
|
+
available_region_color=(0, 255, 0), # available region color
|
|
169
155
|
):
|
|
170
156
|
"""
|
|
171
157
|
Initializes the parking management system with a YOLOv8 model and visualization settings.
|
|
172
158
|
|
|
173
159
|
Args:
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
bg_color (tuple): RGB color tuple for background.
|
|
160
|
+
model (str): Path to the YOLOv8 model.
|
|
161
|
+
json_file (str): file that have all parking slot points data
|
|
177
162
|
occupied_region_color (tuple): RGB color tuple for occupied regions.
|
|
178
163
|
available_region_color (tuple): RGB color tuple for available regions.
|
|
179
|
-
margin (int): Margin for text display.
|
|
180
164
|
"""
|
|
181
|
-
# Model
|
|
182
|
-
self.model_path = model_path
|
|
183
|
-
self.model = self.load_model()
|
|
184
|
-
|
|
185
|
-
# Labels dictionary
|
|
186
|
-
self.labels_dict = {"Occupancy": 0, "Available": 0}
|
|
187
|
-
|
|
188
|
-
# Visualization details
|
|
189
|
-
self.margin = margin
|
|
190
|
-
self.bg_color = bg_color
|
|
191
|
-
self.txt_color = txt_color
|
|
192
|
-
self.occupied_region_color = occupied_region_color
|
|
193
|
-
self.available_region_color = available_region_color
|
|
194
|
-
|
|
195
|
-
self.window_name = "Ultralytics YOLOv8 Parking Management System"
|
|
196
|
-
# Check if environment supports imshow
|
|
197
|
-
self.env_check = check_imshow(warn=True)
|
|
198
|
-
|
|
199
|
-
def load_model(self):
|
|
200
|
-
"""Load the Ultralytics YOLO model for inference and analytics."""
|
|
165
|
+
# Model initialization
|
|
201
166
|
from ultralytics import YOLO
|
|
202
167
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
@staticmethod
|
|
206
|
-
def parking_regions_extraction(json_file):
|
|
207
|
-
"""
|
|
208
|
-
Extract parking regions from json file.
|
|
168
|
+
self.model = YOLO(model)
|
|
209
169
|
|
|
210
|
-
|
|
211
|
-
json_file (str): file that have all parking slot points
|
|
212
|
-
"""
|
|
170
|
+
# Load JSON data
|
|
213
171
|
with open(json_file) as f:
|
|
214
|
-
|
|
172
|
+
self.json_data = json.load(f)
|
|
215
173
|
|
|
216
|
-
|
|
174
|
+
self.pr_info = {"Occupancy": 0, "Available": 0} # dictionary for parking information
|
|
175
|
+
|
|
176
|
+
self.occ = occupied_region_color
|
|
177
|
+
self.arc = available_region_color
|
|
178
|
+
|
|
179
|
+
self.env_check = check_imshow(warn=True) # check if environment supports imshow
|
|
180
|
+
|
|
181
|
+
def process_data(self, im0):
|
|
217
182
|
"""
|
|
218
183
|
Process the model data for parking lot management.
|
|
219
184
|
|
|
220
185
|
Args:
|
|
221
|
-
json_data (str): json data for parking lot management
|
|
222
186
|
im0 (ndarray): inference image
|
|
223
|
-
boxes (list): bounding boxes data
|
|
224
|
-
clss (list): bounding boxes classes list
|
|
225
|
-
|
|
226
|
-
Returns:
|
|
227
|
-
filled_slots (int): total slots that are filled in parking lot
|
|
228
|
-
empty_slots (int): total slots that are available in parking lot
|
|
229
187
|
"""
|
|
230
|
-
|
|
231
|
-
empty_slots, filled_slots = len(json_data), 0
|
|
232
|
-
for region in json_data:
|
|
233
|
-
points_array = np.array(region["points"], dtype=np.int32).reshape((-1, 1, 2))
|
|
234
|
-
region_occupied = False
|
|
188
|
+
results = self.model.track(im0, persist=True, show=False) # object tracking
|
|
235
189
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
y_center = int((box[1] + box[3]) / 2)
|
|
239
|
-
text = f"{self.model.names[int(cls)]}"
|
|
190
|
+
es, fs = len(self.json_data), 0 # empty slots, filled slots
|
|
191
|
+
annotator = Annotator(im0) # init annotator
|
|
240
192
|
|
|
193
|
+
# extract tracks data
|
|
194
|
+
if results[0].boxes.id is None:
|
|
195
|
+
self.display_frames(im0)
|
|
196
|
+
return im0
|
|
197
|
+
|
|
198
|
+
boxes = results[0].boxes.xyxy.cpu().tolist()
|
|
199
|
+
clss = results[0].boxes.cls.cpu().tolist()
|
|
200
|
+
|
|
201
|
+
for region in self.json_data:
|
|
202
|
+
# Convert points to a NumPy array with the correct dtype and reshape properly
|
|
203
|
+
pts_array = np.array(region["points"], dtype=np.int32).reshape((-1, 1, 2))
|
|
204
|
+
rg_occupied = False # occupied region initialization
|
|
205
|
+
for box, cls in zip(boxes, clss):
|
|
206
|
+
xc = int((box[0] + box[2]) / 2)
|
|
207
|
+
yc = int((box[1] + box[3]) / 2)
|
|
241
208
|
annotator.display_objects_labels(
|
|
242
|
-
im0,
|
|
209
|
+
im0, self.model.names[int(cls)], (104, 31, 17), (255, 255, 255), xc, yc, 10
|
|
243
210
|
)
|
|
244
|
-
dist = cv2.pointPolygonTest(
|
|
211
|
+
dist = cv2.pointPolygonTest(pts_array, (xc, yc), False)
|
|
245
212
|
if dist >= 0:
|
|
246
|
-
|
|
213
|
+
rg_occupied = True
|
|
247
214
|
break
|
|
215
|
+
if rg_occupied:
|
|
216
|
+
fs += 1
|
|
217
|
+
es -= 1
|
|
218
|
+
|
|
219
|
+
# Plotting regions
|
|
220
|
+
color = self.occ if rg_occupied else self.arc
|
|
221
|
+
cv2.polylines(im0, [pts_array], isClosed=True, color=color, thickness=2)
|
|
248
222
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
if region_occupied:
|
|
252
|
-
filled_slots += 1
|
|
253
|
-
empty_slots -= 1
|
|
223
|
+
self.pr_info["Occupancy"] = fs
|
|
224
|
+
self.pr_info["Available"] = es
|
|
254
225
|
|
|
255
|
-
self.
|
|
256
|
-
self.labels_dict["Available"] = empty_slots
|
|
226
|
+
annotator.display_analytics(im0, self.pr_info, (104, 31, 17), (255, 255, 255), 10)
|
|
257
227
|
|
|
258
|
-
|
|
228
|
+
self.display_frames(im0)
|
|
229
|
+
return im0
|
|
259
230
|
|
|
260
231
|
def display_frames(self, im0):
|
|
261
232
|
"""
|
|
@@ -265,8 +236,7 @@ class ParkingManagement:
|
|
|
265
236
|
im0 (ndarray): inference image
|
|
266
237
|
"""
|
|
267
238
|
if self.env_check:
|
|
268
|
-
cv2.
|
|
269
|
-
cv2.imshow(self.window_name, im0)
|
|
239
|
+
cv2.imshow("Ultralytics Parking Manager", im0)
|
|
270
240
|
# Break Window
|
|
271
241
|
if cv2.waitKey(1) & 0xFF == ord("q"):
|
|
272
242
|
return
|
ultralytics/utils/checks.py
CHANGED
|
@@ -656,9 +656,10 @@ def check_amp(model):
|
|
|
656
656
|
|
|
657
657
|
def amp_allclose(m, im):
|
|
658
658
|
"""All close FP32 vs AMP results."""
|
|
659
|
-
|
|
659
|
+
batch = [im] * 8
|
|
660
|
+
a = m(batch, imgsz=128, device=device, verbose=False)[0].boxes.data # FP32 inference
|
|
660
661
|
with autocast(enabled=True):
|
|
661
|
-
b = m(
|
|
662
|
+
b = m(batch, imgsz=128, device=device, verbose=False)[0].boxes.data # AMP inference
|
|
662
663
|
del m
|
|
663
664
|
return a.shape == b.shape and torch.allclose(a, b.float(), atol=0.5) # close to 0.5 absolute tolerance
|
|
664
665
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ultralytics
|
|
3
|
-
Version: 8.2.
|
|
3
|
+
Version: 8.2.97
|
|
4
4
|
Summary: Ultralytics YOLO for SOTA object detection, multi-object tracking, instance segmentation, pose estimation and image classification.
|
|
5
5
|
Author: Glenn Jocher, Ayush Chaurasia, Jing Qiu
|
|
6
6
|
Maintainer: Glenn Jocher, Ayush Chaurasia, Jing Qiu
|
|
@@ -6,12 +6,12 @@ tests/test_engine.py,sha256=xW-UT9_9xZp-7-hSnbJgMw_ezTk6NqTOIiA59XZDmxA,4934
|
|
|
6
6
|
tests/test_explorer.py,sha256=IMFvZ9uMoEXVC5FwdaVh0821wBgs7muVF6aw1F-auAI,2572
|
|
7
7
|
tests/test_exports.py,sha256=Uezf3OatpPHlo5qoPw-2kqkZxuMCF9L4XF2riD4vmII,8225
|
|
8
8
|
tests/test_integrations.py,sha256=xglcfMPjfVh346PV8WTpk6tBxraCXEFJEQyyJMr5tyU,6064
|
|
9
|
-
tests/test_python.py,sha256=
|
|
9
|
+
tests/test_python.py,sha256=vkA0F9XgOSpU1BxI2Lzq69f6g-vi8PtOfmb_7P96ZUk,23560
|
|
10
10
|
tests/test_solutions.py,sha256=p_2edhl96Ty3jwzSf02Q2m2mTu9skc0Z-eMcUuuXfLg,3300
|
|
11
|
-
ultralytics/__init__.py,sha256=
|
|
11
|
+
ultralytics/__init__.py,sha256=4ko8wqP19EM9zJljwbpzSwRQRNGDBUI_jSGHJg5rmD0,695
|
|
12
12
|
ultralytics/assets/bus.jpg,sha256=wCAZxJecGR63Od3ZRERe9Aja1Weayrb9Ug751DS_vGM,137419
|
|
13
13
|
ultralytics/assets/zidane.jpg,sha256=Ftc4aeMmen1O0A3o6GCDO9FlfBslLpTAw0gnetx7bts,50427
|
|
14
|
-
ultralytics/cfg/__init__.py,sha256=
|
|
14
|
+
ultralytics/cfg/__init__.py,sha256=7FFk0HG4AvAre9CV70QMTtx1h74pSiNSJaxKSiuFkSo,33138
|
|
15
15
|
ultralytics/cfg/default.yaml,sha256=xRKVF-Z9E3imXTU9OCK94kj3jGgYoo67VJQwuYlHiUU,8228
|
|
16
16
|
ultralytics/cfg/datasets/Argoverse.yaml,sha256=FyeuJT5CHq_9d4hlfAf0kpZlnbUMO0S--UJ1yIqcdKk,3134
|
|
17
17
|
ultralytics/cfg/datasets/DOTAv1.5.yaml,sha256=QVfp_Qp-4rukuicaB4qx86NxSHM8Mrzym8l_fIDo8gw,1195
|
|
@@ -99,15 +99,15 @@ ultralytics/data/explorer/gui/__init__.py,sha256=mHtJuK4hwF8cuV-VHDc7tp6u6D1gHz2
|
|
|
99
99
|
ultralytics/data/explorer/gui/dash.py,sha256=vZ476NaUH4FKU08rAJ1K9WNyKtg0soMyJJxqg176yWc,10498
|
|
100
100
|
ultralytics/engine/__init__.py,sha256=mHtJuK4hwF8cuV-VHDc7tp6u6D1gHz2Z7JI8grmQDTs,42
|
|
101
101
|
ultralytics/engine/exporter.py,sha256=MtBFbJp3ifhn9sQXuQb7vxxOmtS_SOw7lnQhrq4H42c,57078
|
|
102
|
-
ultralytics/engine/model.py,sha256=
|
|
102
|
+
ultralytics/engine/model.py,sha256=1sWOBvLL2JIH8JuHoxwvr1MPfKFww0ORyLESx3Fs2c8,51582
|
|
103
103
|
ultralytics/engine/predictor.py,sha256=MgMWHUJdRcVCaVmOyvdy2Gjk_EyRHv-ar0SSGxQe8F4,17471
|
|
104
|
-
ultralytics/engine/results.py,sha256=
|
|
104
|
+
ultralytics/engine/results.py,sha256=8RJlN8J-_9w-mrDZm9wC-DZJTPBS7v1c_r_R173QyRM,75043
|
|
105
105
|
ultralytics/engine/trainer.py,sha256=VOuR9WpDgYILevpWnWAtKLEIcJ4iFG41HxOCSbOy0YA,36657
|
|
106
106
|
ultralytics/engine/tuner.py,sha256=gPqDTHH7vRB2O3YyH26m1BjVKbXxuA2XAlPRzTKFZsc,11838
|
|
107
|
-
ultralytics/engine/validator.py,sha256=
|
|
107
|
+
ultralytics/engine/validator.py,sha256=483Ad87Irk7IBlJNLu2SQAJsb7YriALTX9GIgriCmRg,14650
|
|
108
108
|
ultralytics/hub/__init__.py,sha256=AM_twjV9ouUmyxh3opoPgTqDpMOd8xIOHsAKdWS2L18,5663
|
|
109
109
|
ultralytics/hub/auth.py,sha256=kDLakGa2NbzvMAeXc2UdzZ65r0AH-XeM_JfsDY97WGk,5545
|
|
110
|
-
ultralytics/hub/session.py,sha256=
|
|
110
|
+
ultralytics/hub/session.py,sha256=ivTJpGEKEi7F55RloWN-Ks6oeB3ll74AWGAsBtAQOPM,16715
|
|
111
111
|
ultralytics/hub/utils.py,sha256=I7NATG6O_QRw7EU7EHkdTVvbCkwKCyUe54BP60To_so,9715
|
|
112
112
|
ultralytics/hub/google/__init__.py,sha256=uclNs-_5vAzQMgQKgl8eBvml1cx6IZYXRUhrF57v6_k,7504
|
|
113
113
|
ultralytics/models/__init__.py,sha256=TT9iLCL_n9Y80dcUq0Fo-p-GRZCSU2vrWXM3CoMwqqE,265
|
|
@@ -183,7 +183,7 @@ ultralytics/solutions/analytics.py,sha256=bGuZes11D7DNiTsHdwu6PJ0QA0vCiqMMAtZ7Ny
|
|
|
183
183
|
ultralytics/solutions/distance_calculation.py,sha256=o_DAHk4JX8n2Vt7E68MX67mREOBZuy5skbXtVZ6iu_4,5228
|
|
184
184
|
ultralytics/solutions/heatmap.py,sha256=oEVivA4KAK6z0wA5Ca_a2qTckQN8tCt9MCpsPREeNnk,10375
|
|
185
185
|
ultralytics/solutions/object_counter.py,sha256=QXSg2a5IBW70lirIKml8xNgPDyzUy7dLt2gUn59_18A,9941
|
|
186
|
-
ultralytics/solutions/parking_management.py,sha256=
|
|
186
|
+
ultralytics/solutions/parking_management.py,sha256=tGD1dglpIu5KhDWF7xaIRwbqETfpxCfvyvlUsNEsjUQ,9119
|
|
187
187
|
ultralytics/solutions/queue_management.py,sha256=yKPGc2-fN-lMpNddkxjN7xYGIJwMdoU-VIDRxQ1KPow,4869
|
|
188
188
|
ultralytics/solutions/speed_estimation.py,sha256=c9OPGpDU9x6Dj4SobNc-sO90EZTPTGeKkW5u6C6Zj7g,4623
|
|
189
189
|
ultralytics/solutions/streamlit_inference.py,sha256=MKf5P3O5oJwIKu2h_URvzaQjMWoSEMDMBwordplfRxo,5703
|
|
@@ -199,7 +199,7 @@ ultralytics/trackers/utils/matching.py,sha256=3Ie1WNNRZ4_q3365F03XD7Nr9juZB_08mw
|
|
|
199
199
|
ultralytics/utils/__init__.py,sha256=BRqC6AE9epuZJy4XcGzGfuR2zNiXx-mfot2JQomterw,44097
|
|
200
200
|
ultralytics/utils/autobatch.py,sha256=AXboYfNSnTGsYj5FmgGYPQd0crfkeleyms6QXQfZGQ4,4194
|
|
201
201
|
ultralytics/utils/benchmarks.py,sha256=UsVJXTgB6xQ8QBjlNghN3WuZQwXShQjuqv2RcGBLHDY,23640
|
|
202
|
-
ultralytics/utils/checks.py,sha256=
|
|
202
|
+
ultralytics/utils/checks.py,sha256=PmdN42XJ7IIUNbeiY8zjPIfJceaxAO04nc780EoYxTc,28910
|
|
203
203
|
ultralytics/utils/dist.py,sha256=NDFga-uKxkBX2zLxFHSene_cCiGQJoyOeCXcN9JIOIk,2358
|
|
204
204
|
ultralytics/utils/downloads.py,sha256=uLsYFN2G4g2joTNrsZsfc8ytvfNNRXDPkI20qgkZ2B8,21897
|
|
205
205
|
ultralytics/utils/errors.py,sha256=GqP_Jgj_n0paxn8OMhn3DTCgoNkB2WjUcUaqs-M6SQk,816
|
|
@@ -225,9 +225,9 @@ ultralytics/utils/callbacks/neptune.py,sha256=5Z3ua5YBTUS56FH8VQKQG1aaIo9fH8GEyz
|
|
|
225
225
|
ultralytics/utils/callbacks/raytune.py,sha256=ODVYzy-CoM4Uge0zjkh3Hnh9nF2M0vhDrSenXnvcizw,705
|
|
226
226
|
ultralytics/utils/callbacks/tensorboard.py,sha256=0kn4IR10no99UCIheojWRujgybmUHSx5fPI6Vsq6l_g,4135
|
|
227
227
|
ultralytics/utils/callbacks/wb.py,sha256=9-fjQIdLjr3b73DTE3rHO171KvbH1VweJ-bmbv-rqTw,6747
|
|
228
|
-
ultralytics-8.2.
|
|
229
|
-
ultralytics-8.2.
|
|
230
|
-
ultralytics-8.2.
|
|
231
|
-
ultralytics-8.2.
|
|
232
|
-
ultralytics-8.2.
|
|
233
|
-
ultralytics-8.2.
|
|
228
|
+
ultralytics-8.2.97.dist-info/LICENSE,sha256=DZak_2itbUtvHzD3E7GNUYSRK6jdOJ-GqncQ2weavLA,34523
|
|
229
|
+
ultralytics-8.2.97.dist-info/METADATA,sha256=ZXllOjVWz8Z_-O8l8U7EAIr7Hy32uYtPLoMpa9-Vbs0,39504
|
|
230
|
+
ultralytics-8.2.97.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
231
|
+
ultralytics-8.2.97.dist-info/entry_points.txt,sha256=YM_wiKyTe9yRrsEfqvYolNO5ngwfoL4-NwgKzc8_7sI,93
|
|
232
|
+
ultralytics-8.2.97.dist-info/top_level.txt,sha256=XP49TwiMw4QGsvTLSYiJhz1xF_k7ev5mQ8jJXaXi45Q,12
|
|
233
|
+
ultralytics-8.2.97.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|