参考资料 ultralytics/utils/benchmarks.py
备注
该文件可在https://github.com/ultralytics/ultralytics/blob/main/ultralytics/utils/benchmarks .py 上获取。如果您发现问题,请通过提交 Pull Request🛠️ 帮助修复。谢谢🙏!
ultralytics.utils.benchmarks.RF100Benchmark
源代码 ultralytics/utils/benchmarks.py
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 285 |
|
__init__()
用于初始化 RF100Benchmark 的函数。
evaluate(yaml_path, val_log_file, eval_log_file, list_ind)
根据验证结果对模型进行评估。
参数
名称 | 类型 | 说明 | 默认值 |
---|---|---|---|
yaml_path |
str
|
YAML 文件路径。 |
所需 |
val_log_file |
str
|
val_log_file 路径。 |
所需 |
eval_log_file |
str
|
eval_log_file 路径。 |
所需 |
list_ind |
int
|
当前数据集的索引。 |
所需 |
源代码 ultralytics/utils/benchmarks.py
fix_yaml(path)
修复 yaml train 和 val 路径的功能。
参数
名称 | 类型 | 说明 | 默认值 |
---|---|---|---|
path |
str
|
YAML 文件路径。 |
所需 |
源代码 ultralytics/utils/benchmarks.py
parse_dataset(ds_link_txt='datasets_links.txt')
解析数据集链接并下载数据集。
参数
名称 | 类型 | 说明 | 默认值 |
---|---|---|---|
ds_link_txt |
str
|
数据集链接文件的路径。 |
'datasets_links.txt'
|
源代码 ultralytics/utils/benchmarks.py
set_key(api_key)
设置Roboflow API 密钥以便处理。
参数
名称 | 类型 | 说明 | 默认值 |
---|---|---|---|
api_key |
str
|
API 密钥。 |
所需 |
ultralytics.utils.benchmarks.ProfileModels
ProfileModels 类用于在ONNX 和TensorRT 上剖析不同的模型。
该类分析不同模型的性能,返回模型速度和 FLOPs 等结果。
属性
名称 | 类型 | 说明 |
---|---|---|
paths |
list
|
剖面模型的路径。 |
num_timed_runs |
int
|
剖析的定时运行次数。默认为 100。 |
num_warmup_runs |
int
|
剖析前的预热运行次数。默认为 10 次。 |
min_time |
float
|
配置文件的最小秒数。默认为 60 秒。 |
imgsz |
int
|
模型中使用的图像大小。默认为 640。 |
方法
名称 | 说明 |
---|---|
profile |
剖析模型并打印结果。 |
示例
源代码 ultralytics/utils/benchmarks.py
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 536 |
|
__init__(paths, num_timed_runs=100, num_warmup_runs=10, min_time=60, imgsz=640, half=True, trt=True, device=None)
初始化用于剖析模型的 ProfileModels 类。
参数
名称 | 类型 | 说明 | 默认值 |
---|---|---|---|
paths |
list
|
待剖析模型的路径列表。 |
所需 |
num_timed_runs |
int
|
剖析的定时运行次数。默认为 100。 |
100
|
num_warmup_runs |
int
|
实际剖析开始前的预热运行次数。默认为 10 次。 |
10
|
min_time |
float
|
剖析模型的最短时间(以秒为单位)。默认为 60 秒。 |
60
|
imgsz |
int
|
剖析时使用的图像大小。默认值为 640。 |
640
|
half |
bool
|
指示是否使用半精度浮点进行剖析的标志。 |
True
|
trt |
bool
|
指示是否使用TensorRT 进行剖析的标志。默认为 True。 |
True
|
device |
device
|
用于剖析的设备。如果无,则自动确定。 |
None
|
源代码 ultralytics/utils/benchmarks.py
generate_results_dict(model_name, t_onnx, t_engine, model_info)
staticmethod
生成模型详细信息字典,包括名称、参数、GFLOPS 和速度指标。
源代码 ultralytics/utils/benchmarks.py
generate_table_row(model_name, t_onnx, t_engine, model_info)
为表格行生成格式化字符串,其中包括模型性能和指标详情。
源代码 ultralytics/utils/benchmarks.py
get_files()
返回用户提供的所有相关模型文件的路径列表。
源代码 ultralytics/utils/benchmarks.py
get_onnx_model_info(onnx_file)
检索ONNX 模型文件的层数、参数、梯度和 FLOPs 等信息。 文件。
源代码 ultralytics/utils/benchmarks.py
iterative_sigma_clipping(data, sigma=2, max_iters=3)
staticmethod
对给定数据应用迭代西格玛剪切算法乘以迭代次数。
源代码 ultralytics/utils/benchmarks.py
print_table(table_rows)
staticmethod
根据给定的统计数据和性能数据,格式化并打印不同型号的对照表。
源代码 ultralytics/utils/benchmarks.py
profile()
记录模型的基准测试结果,根据下限检查指标并返回结果。
源代码 ultralytics/utils/benchmarks.py
profile_onnx_model(onnx_file, eps=0.001)
通过多次执行来剖析ONNX 模型,并返回运行时间的平均值和标准偏差。 时间的平均值和标准偏差。
源代码 ultralytics/utils/benchmarks.py
profile_tensorrt_model(engine_file, eps=0.001)
对TensorRT 模型进行剖析,测量平均运行时间和运行之间的标准偏差。
源代码 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)
对YOLO 模型在不同格式下的速度和准确性进行基准测试。
参数
名称 | 类型 | 说明 | 默认值 |
---|---|---|---|
model |
str | Path | optional
|
模型文件或目录的路径。默认为 Path(SETTINGS['weights_dir']) / 'yolov8n.pt'。 |
WEIGHTS_DIR / 'yolov8n.pt'
|
data |
str
|
要评估的数据集,如果未传递,则从 TASK2DATA 继承。默认为无。 |
None
|
imgsz |
int
|
基准的图像大小。默认为 160。 |
160
|
half |
bool
|
如果为 True,则在模型中使用半精度。默认为假。 |
False
|
int8 |
bool
|
如果为 True,则在模型中使用 int8-精度。默认为假。 |
False
|
device |
str
|
运行基准的设备,可以是 "cpu "或 "cuda"。默认为 "cpu"。 |
'cpu'
|
verbose |
bool | float | optional
|
如果为 True 或浮点数,则断言基准以给定指标通过。 默认为 "假"。 |
False
|
返回:
名称 | 类型 | 说明 |
---|---|---|
df |
DataFrame
|
pandas DataFrame,包含每种格式的基准结果,包括文件大小、度量标准和推理时间、 指标和推理时间。 |
源代码 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 158 |
|