MCPcopy Create free account
hub / github.com/OpenTalker/StyleHEAT / get_nested_attr

Function get_nested_attr

utils/misc.py:141–159  ·  view source on GitHub ↗

r"""Iteratively try to get the attribute from cfg. If not found, return default. Args: cfg (obj): Config file. attr_name (str): Attribute name (e.g. XXX.YYY.ZZZ). default (obj): Default return value for the attribute. Returns: (obj): Attribute value.

(cfg, attr_name, default)

Source from the content-addressed store, hash-verified

139
140
141def get_nested_attr(cfg, attr_name, default):
142 r"""Iteratively try to get the attribute from cfg. If not found, return
143 default.
144
145 Args:
146 cfg (obj): Config file.
147 attr_name (str): Attribute name (e.g. XXX.YYY.ZZZ).
148 default (obj): Default return value for the attribute.
149
150 Returns:
151 (obj): Attribute value.
152 """
153 names = attr_name.split('.')
154 atr = cfg
155 for name in names:
156 if not hasattr(atr, name):
157 return default
158 atr = getattr(atr, name)
159 return atr
160
161
162def gradient_norm(model):

Callers

nothing calls this directly

Calls 1

splitMethod · 0.80

Tested by

no test coverage detected