Load data from npz_path and update them to self. Args: npz_path (str): Path to a dumped npz file.
(self, npz_path: str)
| 232 | return self.__keypoints_compressed__ |
| 233 | |
| 234 | def load(self, npz_path: str): |
| 235 | """Load data from npz_path and update them to self. |
| 236 | |
| 237 | Args: |
| 238 | npz_path (str): |
| 239 | Path to a dumped npz file. |
| 240 | """ |
| 241 | supported_keys = self.__class__.SUPPORTED_KEYS |
| 242 | with np.load(npz_path, allow_pickle=True) as npz_file: |
| 243 | tmp_data_dict = dict(npz_file) |
| 244 | for key, value in list(tmp_data_dict.items()): |
| 245 | if isinstance(value, np.ndarray) and\ |
| 246 | len(value.shape) == 0: |
| 247 | # value is not an ndarray before dump |
| 248 | value = value.item() |
| 249 | elif key in supported_keys and\ |
| 250 | type(value) != supported_keys[key]['type']: |
| 251 | value = supported_keys[key]['type'](value) |
| 252 | if value is None: |
| 253 | tmp_data_dict.pop(key) |
| 254 | elif key == '__key_strict__' or \ |
| 255 | key == '__data_len__' or\ |
| 256 | key == '__keypoints_compressed__': |
| 257 | self.__setattr__(key, value) |
| 258 | # pop the attributes to keep dict clean |
| 259 | tmp_data_dict.pop(key) |
| 260 | elif key == 'bbox_xywh' and value.shape[1] == 4: |
| 261 | value = np.hstack([value, np.ones([value.shape[0], 1])]) |
| 262 | tmp_data_dict[key] = value |
| 263 | else: |
| 264 | tmp_data_dict[key] = value |
| 265 | self.update(tmp_data_dict) |
| 266 | self.__set_default_values__() |
| 267 | |
| 268 | def dump(self, npz_path: str, overwrite: bool = True): |
| 269 | """Dump keys and items to an npz file. |