Ultralytics IterableSimpleNamespace is an extension class of SimpleNamespace that adds iterable functionality and enables usage with dict() and for loops.
| 154 | |
| 155 | |
| 156 | class IterableSimpleNamespace(SimpleNamespace): |
| 157 | """Ultralytics IterableSimpleNamespace is an extension class of SimpleNamespace that adds iterable functionality and |
| 158 | enables usage with dict() and for loops. |
| 159 | """ |
| 160 | |
| 161 | def __iter__(self): |
| 162 | """Return an iterator of key-value pairs from the namespace's attributes.""" |
| 163 | return iter(vars(self).items()) |
| 164 | |
| 165 | def __str__(self): |
| 166 | """Return a human-readable string representation of the object.""" |
| 167 | return '\n'.join(f'{k}={v}' for k, v in vars(self).items()) |
| 168 | |
| 169 | def __getattr__(self, attr): |
| 170 | """Custom attribute access error message with helpful information.""" |
| 171 | name = self.__class__.__name__ |
| 172 | raise AttributeError(f""" |
| 173 | '{name}' object has no attribute '{attr}'. This may be caused by a modified or out of date ultralytics |
| 174 | 'default.yaml' file.\nPlease update your code with 'pip install -U ultralytics' and if necessary replace |
| 175 | {DEFAULT_CFG_PATH} with the latest version from |
| 176 | https://github.com/ultralytics/ultralytics/blob/main/ultralytics/cfg/default.yaml |
| 177 | """) |
| 178 | |
| 179 | def get(self, key, default=None): |
| 180 | """Return the value of the specified key if it exists; otherwise, return the default value.""" |
| 181 | return getattr(self, key, default) |
| 182 | |
| 183 | |
| 184 | def plt_settings(rcparams=None, backend='Agg'): |
no outgoing calls
no test coverage detected