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)
| 139 | |
| 140 | |
| 141 | def 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 | |
| 162 | def gradient_norm(model): |