Reference for ultralytics/utils/benchmarks.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/utils/benchmarks.py. If you spot a problem please help fix it by contributing a Pull Request π οΈ. Thank you π!
ultralytics.utils.benchmarks.RF100Benchmark
Source code in ultralytics/utils/benchmarks.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
|
__init__()
Function for initialization of RF100Benchmark.
evaluate(yaml_path, val_log_file, eval_log_file, list_ind)
Model evaluation on validation results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
yaml_path |
str
|
YAML file path. |
required |
val_log_file |
str
|
val_log_file path. |
required |
eval_log_file |
str
|
eval_log_file path. |
required |
list_ind |
int
|
Index for current dataset. |
required |
Source code in ultralytics/utils/benchmarks.py
fix_yaml(path)
Function to fix yaml train and val path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
YAML file path. |
required |
Source code in ultralytics/utils/benchmarks.py
parse_dataset(ds_link_txt='datasets_links.txt')
Parse dataset links and downloads datasets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ds_link_txt |
str
|
Path to dataset_links file. |
'datasets_links.txt'
|
Source code in ultralytics/utils/benchmarks.py
set_key(api_key)
Set Roboflow API key for processing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api_key |
str
|
The API key. |
required |
ultralytics.utils.benchmarks.ProfileModels
ProfileModels class for profiling different models on ONNX and TensorRT.
This class profiles the performance of different models, returning results such as model speed and FLOPs.
Attributes:
Name | Type | Description |
---|---|---|
paths |
list
|
Paths of the models to profile. |
num_timed_runs |
int
|
Number of timed runs for the profiling. Default is 100. |
num_warmup_runs |
int
|
Number of warmup runs before profiling. Default is 10. |
min_time |
float
|
Minimum number of seconds to profile for. Default is 60. |
imgsz |
int
|
Image size used in the models. Default is 640. |
Methods:
Name | Description |
---|---|
profile |
Profiles the models and prints the result. |
Example
Source code in ultralytics/utils/benchmarks.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 |
|
__init__(paths, num_timed_runs=100, num_warmup_runs=10, min_time=60, imgsz=640, half=True, trt=True, device=None)
Initialize the ProfileModels class for profiling models.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
paths |
list
|
List of paths of the models to be profiled. |
required |
num_timed_runs |
int
|
Number of timed runs for the profiling. Default is 100. |
100
|
num_warmup_runs |
int
|
Number of warmup runs before the actual profiling starts. Default is 10. |
10
|
min_time |
float
|
Minimum time in seconds for profiling a model. Default is 60. |
60
|
imgsz |
int
|
Size of the image used during profiling. Default is 640. |
640
|
half |
bool
|
Flag to indicate whether to use half-precision floating point for profiling. |
True
|
trt |
bool
|
Flag to indicate whether to profile using TensorRT. Default is True. |
True
|
device |
device
|
Device used for profiling. If None, it is determined automatically. |
None
|
Source code in ultralytics/utils/benchmarks.py
generate_results_dict(model_name, t_onnx, t_engine, model_info)
staticmethod
Generates a dictionary of model details including name, parameters, GFLOPS and speed metrics.
Source code in ultralytics/utils/benchmarks.py
generate_table_row(model_name, t_onnx, t_engine, model_info)
Generates a formatted string for a table row that includes model performance and metric details.
Source code in ultralytics/utils/benchmarks.py
get_files()
Returns a list of paths for all relevant model files given by the user.
Source code in ultralytics/utils/benchmarks.py
get_onnx_model_info(onnx_file)
Retrieves the information including number of layers, parameters, gradients and FLOPs for an ONNX model file.
Source code in ultralytics/utils/benchmarks.py
iterative_sigma_clipping(data, sigma=2, max_iters=3)
staticmethod
Applies an iterative sigma clipping algorithm to the given data times number of iterations.
Source code in ultralytics/utils/benchmarks.py
print_table(table_rows)
staticmethod
Formats and prints a comparison table for different models with given statistics and performance data.
Source code in ultralytics/utils/benchmarks.py
profile()
Logs the benchmarking results of a model, checks metrics against floor and returns the results.
Source code in ultralytics/utils/benchmarks.py
profile_onnx_model(onnx_file, eps=0.001)
Profiles an ONNX model by executing it multiple times and returns the mean and standard deviation of run times.
Source code in ultralytics/utils/benchmarks.py
profile_tensorrt_model(engine_file, eps=0.001)
Profiles the TensorRT model, measuring average run time and standard deviation among runs.
Source code in ultralytics/utils/benchmarks.py
ultralytics.utils.benchmarks.benchmark(model=WEIGHTS_DIR / 'yolov8n.pt', data=None, imgsz=160, half=False, int8=False, device='cpu', verbose=False)
Benchmark a YOLO model across different formats for speed and accuracy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
str | Path | optional
|
Path to the model file or directory. Default is Path(SETTINGS['weights_dir']) / 'yolov8n.pt'. |
WEIGHTS_DIR / 'yolov8n.pt'
|
data |
str
|
Dataset to evaluate on, inherited from TASK2DATA if not passed. Default is None. |
None
|
imgsz |
int
|
Image size for the benchmark. Default is 160. |
160
|
half |
bool
|
Use half-precision for the model if True. Default is False. |
False
|
int8 |
bool
|
Use int8-precision for the model if True. Default is False. |
False
|
device |
str
|
Device to run the benchmark on, either 'cpu' or 'cuda'. Default is 'cpu'. |
'cpu'
|
verbose |
bool | float | optional
|
If True or a float, assert benchmarks pass with given metric. Default is False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
df |
DataFrame
|
A pandas DataFrame with benchmark results for each format, including file size, metric, and inference time. |
Source code in ultralytics/utils/benchmarks.py
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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|