You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

configs.md 1.9 kB

3 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Use Configs
  2. Detectron2's config system uses yaml and [yacs](https://github.com/rbgirshick/yacs).
  3. In addition to the basic operations that access and update a config, we provide
  4. the following extra functionalities:
  5. 1. The config can have `_BASE_: base.yaml` field, which will load a base config first.
  6. Values in the base config will be overwritten in sub-configs, if there are any conflicts.
  7. We provided several base configs for standard model architectures.
  8. 2. We provide config versioning, for backward compatibility.
  9. If your config file is versioned with a config line like `VERSION: 2`,
  10. detectron2 will still recognize it even if we rename some keys in the future.
  11. ### Use Configs
  12. Some basic usage of the `CfgNode` object is shown below:
  13. ```python
  14. from detectron2.config import get_cfg
  15. cfg = get_cfg() # obtain detectron2's default config
  16. cfg.xxx = yyy # add new configs for your own custom components
  17. cfg.merge_from_file("my_cfg.yaml") # load values from a file
  18. cfg.merge_from_list(["MODEL.WEIGHTS", "weights.pth"]) # can also load values from a list of str
  19. ```
  20. To see a list of available configs in detectron2, see [Config References](../modules/config.html#config-references)
  21. ### Best Practice with Configs
  22. 1. Treat the configs you write as "code": avoid copying them or duplicating them; use "_BASE_"
  23. instead to share common parts between configs.
  24. 2. Keep the configs you write simple: don't include keys that do not affect the experimental setting.
  25. 3. Keep a version number in your configs (or the base config), e.g., `VERSION: 2`,
  26. for backward compatibility.
  27. The builtin configs do not include version number because they are meant to
  28. be always up-to-date.
  29. 4. Save a full config together with a trained model, and use it to run inference.
  30. This is more robust to changes that may happen to the config definition
  31. (e.g., if a default value changed).

No Description