Reference for ultralytics/cfg/__init__.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/cfg/init.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.cfg.cfg2dict(cfg)
Convert a configuration object to a dictionary, whether it is a file path, a string, or a SimpleNamespace object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cfg |
str | Path | dict | SimpleNamespace
|
Configuration object to be converted to a dictionary. |
required |
Returns:
Name | Type | Description |
---|---|---|
cfg |
dict
|
Configuration object in dictionary format. |
Source code in ultralytics/cfg/__init__.py
ultralytics.cfg.get_cfg(cfg=DEFAULT_CFG_DICT, overrides=None)
Load and merge configuration data from a file or dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cfg |
str | Path | Dict | SimpleNamespace
|
Configuration data. |
DEFAULT_CFG_DICT
|
overrides |
str | Dict | optional
|
Overrides in the form of a file name or a dictionary. Default is None. |
None
|
Returns:
Type | Description |
---|---|
SimpleNamespace
|
Training arguments namespace. |
Source code in ultralytics/cfg/__init__.py
ultralytics.cfg.check_cfg(cfg, hard=True)
Check Ultralytics configuration argument types and values.
Source code in ultralytics/cfg/__init__.py
ultralytics.cfg.get_save_dir(args, name=None)
Return save_dir as created from train/val/predict arguments.
Source code in ultralytics/cfg/__init__.py
ultralytics.cfg._handle_deprecation(custom)
Hardcoded function to handle deprecated config keys.
Source code in ultralytics/cfg/__init__.py
ultralytics.cfg.check_dict_alignment(base, custom, e=None)
This function checks for any mismatched keys between a custom configuration list and a base configuration list. If any mismatched keys are found, the function prints out similar keys from the base list and exits the program.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
custom |
dict
|
a dictionary of custom configuration options |
required |
base |
dict
|
a dictionary of base configuration options |
required |
e |
Error
|
An optional error that is passed by the calling function. |
None
|
Source code in ultralytics/cfg/__init__.py
ultralytics.cfg.merge_equals_args(args)
Merges arguments around isolated '=' args in a list of strings. The function considers cases where the first argument ends with '=' or the second starts with '=', as well as when the middle one is an equals sign.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
List[str]
|
A list of strings where each element is an argument. |
required |
Returns:
Type | Description |
---|---|
List[str]
|
A list of strings where the arguments around isolated '=' are merged. |
Source code in ultralytics/cfg/__init__.py
ultralytics.cfg.handle_yolo_hub(args)
Handle Ultralytics HUB command-line interface (CLI) commands.
This function processes Ultralytics HUB CLI commands such as login and logout. It should be called when executing a script with arguments related to HUB authentication.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
List[str]
|
A list of command line arguments |
required |
Source code in ultralytics/cfg/__init__.py
ultralytics.cfg.handle_yolo_settings(args)
Handle YOLO settings command-line interface (CLI) commands.
This function processes YOLO settings CLI commands such as reset. It should be called when executing a script with arguments related to YOLO settings management.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
List[str]
|
A list of command line arguments for YOLO settings management. |
required |
Source code in ultralytics/cfg/__init__.py
ultralytics.cfg.handle_explorer()
Open the Ultralytics Explorer GUI.
Source code in ultralytics/cfg/__init__.py
ultralytics.cfg.parse_key_value_pair(pair)
Parse one 'key=value' pair and return key and value.
Source code in ultralytics/cfg/__init__.py
ultralytics.cfg.smart_value(v)
Convert a string to an underlying type such as int, float, bool, etc.
Source code in ultralytics/cfg/__init__.py
ultralytics.cfg.entrypoint(debug='')
This function is the ultralytics package entrypoint, it's responsible for parsing the command line arguments passed to the package.
This function allows for: - passing mandatory YOLO args as a list of strings - specifying the task to be performed, either 'detect', 'segment' or 'classify' - specifying the mode, either 'train', 'val', 'test', or 'predict' - running special modes like 'checks' - passing overrides to the package's configuration
It uses the package's default cfg and initializes it using the passed overrides. Then it calls the CLI function with the composed cfg
Source code in ultralytics/cfg/__init__.py
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 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 |
|
ultralytics.cfg.copy_default_cfg()
Copy and create a new default configuration file with '_copy' appended to its name.