| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
"""Example of basic ConfigDict usage. |
| 16 |
|
| 17 |
This example shows the most basic usage of ConfigDict, including type safety. |
| 18 |
For examples of more features, see example_advanced. |
| 19 |
""" |
| 20 |
|
| 21 |
from absl import app |
| 22 |
from ml_collections import config_dict |
| 23 |
|
| 24 |
|
| 25 |
def main(_): |
| 26 |
cfg = config_dict.ConfigDict() |
| 27 |
cfg.float_field = 12.6 |
| 28 |
cfg.integer_field = 123 |
| 29 |
cfg.another_integer_field = 234 |
| 30 |
cfg.nested = config_dict.ConfigDict() |
| 31 |
cfg.nested.string_field = 'tom' |
| 32 |
|
| 33 |
print(cfg.integer_field) |
| 34 |
print(cfg['integer_field']) |
| 35 |
|
| 36 |
try: |
| 37 |
cfg.integer_field = 'tom' |
| 38 |
except TypeError as e: |
| 39 |
print(e) |
| 40 |
|
| 41 |
cfg.float_field = 12 |
| 42 |
cfg.nested.string_field = u'bob' |
| 43 |
|
| 44 |
print(cfg) |
| 45 |
|
| 46 |
|
| 47 |
if __name__ == '__main__': |
| 48 |
app.run(main) |