tfm.hyperparams.ParamsDict
Stay organized with collections
Save and categorize content based on your preferences.
A hyperparameter container class.
tfm.hyperparams.ParamsDict(
default_params=None, restrictions=None
)
Args |
default_params
|
a Python dict or another ParamsDict object including the
default parameters to initialize.
|
restrictions
|
a list of strings, which define a list of restrictions to
ensure the consistency of different parameters internally. Each
restriction string is defined as a binary relation with a set of
operators, including {'==', '!=', '<', '<=', '>', '>='}.
|
Methods
as_dict
View source
as_dict()
Returns a dict representation of ParamsDict.
For the nested ParamsDict, a nested dict will be returned.
get
View source
get(
key, value=None
)
Accesses through built-in dictionary get method.
lock
View source
lock()
Makes the ParamsDict immutable.
override
View source
override(
override_params, is_strict=True
)
Override the ParamsDict with a set of given params.
Args |
override_params
|
a dict or a ParamsDict specifying the parameters to be
overridden.
|
is_strict
|
a boolean specifying whether override is strict or not. If
True, keys in override_params must be present in the ParamsDict. If
False, keys in override_params can be different from what is currently
defined in the ParamsDict. In this case, the ParamsDict will be extended
to include the new keys.
|
validate
View source
validate()
Validate the parameters consistency based on the restrictions.
This method validates the internal consistency using the pre-defined list of
restrictions. A restriction is defined as a string which specifies a binary
operation. The supported binary operations are {'==', '!=', '<', '<=', '>',
'>='}. Note that the meaning of these operators are consistent with the
underlying Python immplementation. Users should make sure the define
restrictions on their type make sense.
For example, for a ParamsDict like the following
a:
a1: 1
a2: 2
b:
bb:
bb1: 10
bb2: 20
ccc:
a1: 1
a3: 3
one can define two restrictions like this
['a.a1 == b.ccc.a1', 'a.a2 <= b.bb.bb2']
What it enforces are |
- a.a1 = 1 == b.ccc.a1 = 1
- a.a2 = 2 <= b.bb.bb2 = 20
|
Raises |
KeyError
|
if any of the following happens
(1) any of parameters in any of restrictions is not defined in
ParamsDict,
(2) any inconsistency violating the restriction is found.
|
ValueError
|
if the restriction defined in the string is not supported.
|
__contains__
View source
__contains__(
key
)
Implements the membership test operator.
Class Variables |
RESERVED_ATTR
|
['_locked', '_restrictions']
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-02-02 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-02-02 UTC."],[],[],null,["# tfm.hyperparams.ParamsDict\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/models/blob/v2.15.0/official/modeling/hyperparams/params_dict.py#L65-L329) |\n\nA hyperparameter container class.\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tfm.hyperparams.params_dict.ParamsDict`](https://www.tensorflow.org/api_docs/python/tfm/hyperparams/ParamsDict)\n\n\u003cbr /\u003e\n\n tfm.hyperparams.ParamsDict(\n default_params=None, restrictions=None\n )\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `default_params` | a Python dict or another ParamsDict object including the default parameters to initialize. |\n| `restrictions` | a list of strings, which define a list of restrictions to ensure the consistency of different parameters internally. Each restriction string is defined as a binary relation with a set of operators, including {'==', '!=', '\\\u003c', '\\\u003c=', '\\\u003e', '\\\u003e='}. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `as_dict`\n\n[View source](https://github.com/tensorflow/models/blob/v2.15.0/official/modeling/hyperparams/params_dict.py#L208-L220) \n\n as_dict()\n\nReturns a dict representation of ParamsDict.\n\nFor the nested ParamsDict, a nested dict will be returned.\n\n### `get`\n\n[View source](https://github.com/tensorflow/models/blob/v2.15.0/official/modeling/hyperparams/params_dict.py#L142-L144) \n\n get(\n key, value=None\n )\n\nAccesses through built-in dictionary get method.\n\n### `lock`\n\n[View source](https://github.com/tensorflow/models/blob/v2.15.0/official/modeling/hyperparams/params_dict.py#L204-L206) \n\n lock()\n\nMakes the ParamsDict immutable.\n\n### `override`\n\n[View source](https://github.com/tensorflow/models/blob/v2.15.0/official/modeling/hyperparams/params_dict.py#L165-L181) \n\n override(\n override_params, is_strict=True\n )\n\nOverride the ParamsDict with a set of given params.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `override_params` | a dict or a ParamsDict specifying the parameters to be overridden. |\n| `is_strict` | a boolean specifying whether override is strict or not. If True, keys in `override_params` must be present in the ParamsDict. If False, keys in `override_params` can be different from what is currently defined in the ParamsDict. In this case, the ParamsDict will be extended to include the new keys. |\n\n\u003cbr /\u003e\n\n### `validate`\n\n[View source](https://github.com/tensorflow/models/blob/v2.15.0/official/modeling/hyperparams/params_dict.py#L222-L329) \n\n validate()\n\nValidate the parameters consistency based on the restrictions.\n\nThis method validates the internal consistency using the pre-defined list of\nrestrictions. A restriction is defined as a string which specifies a binary\noperation. The supported binary operations are {'==', '!=', '\\\u003c', '\\\u003c=', '\\\u003e',\n'\\\u003e='}. Note that the meaning of these operators are consistent with the\nunderlying Python immplementation. Users should make sure the define\nrestrictions on their type make sense.\n\nFor example, for a ParamsDict like the following \n\n a:\n a1: 1\n a2: 2\n b:\n bb:\n bb1: 10\n bb2: 20\n ccc:\n a1: 1\n a3: 3\n\none can define two restrictions like this\n\\['a.a1 == b.ccc.a1', 'a.a2 \\\u003c= b.bb.bb2'\\]\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| What it enforces are ||\n|---|---|\n| \u003cbr /\u003e - a.a1 = 1 == b.ccc.a1 = 1 - a.a2 = 2 \\\u003c= b.bb.bb2 = 20 ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|--------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `KeyError` | if any of the following happens (1) any of parameters in any of restrictions is not defined in ParamsDict, (2) any inconsistency violating the restriction is found. |\n| `ValueError` | if the restriction defined in the string is not supported. |\n\n\u003cbr /\u003e\n\n### `__contains__`\n\n[View source](https://github.com/tensorflow/models/blob/v2.15.0/official/modeling/hyperparams/params_dict.py#L138-L140) \n\n __contains__(\n key\n )\n\nImplements the membership test operator.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Class Variables --------------- ||\n|---------------|--------------------------------|\n| RESERVED_ATTR | `['_locked', '_restrictions']` |\n\n\u003cbr /\u003e"]]