Reference for ultralytics/cfg/__init__.py
Note
Full source code for this file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/cfg/init.py. Help us fix any issues you see by submitting 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.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]
|
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.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
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 |
|
ultralytics.cfg.copy_default_cfg()
Copy and create a new default configuration file with '_copy' appended to its name.