MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / load

Method load

detrsmpl/data/data_structures/multi_human_data.py:54–87  ·  view source on GitHub ↗

Load data from npz_path and update them to self. Args: npz_path (str): Path to a dumped npz file.

(self, npz_path: str)

Source from the content-addressed store, hash-verified

52 return ret_human_data
53
54 def load(self, npz_path: str):
55 """Load data from npz_path and update them to self.
56
57 Args:
58 npz_path (str):
59 Path to a dumped npz file.
60 """
61 supported_keys = self.__class__.SUPPORTED_KEYS
62 with np.load(npz_path, allow_pickle=True) as npz_file:
63 tmp_data_dict = dict(npz_file)
64 for key, value in list(tmp_data_dict.items()):
65 if isinstance(value, np.ndarray) and\
66 len(value.shape) == 0:
67 # value is not an ndarray before dump
68 value = value.item()
69 elif key in supported_keys and\
70 type(value) != supported_keys[key]['type']:
71 value = supported_keys[key]['type'](value)
72 if value is None:
73 tmp_data_dict.pop(key)
74 elif key == '__key_strict__' or \
75 key == '__data_len__' or\
76 key == '__instance_num__' or\
77 key == '__keypoints_compressed__':
78 self.__setattr__(key, value)
79 # pop the attributes to keep dict clean
80 tmp_data_dict.pop(key)
81 elif key == 'bbox_xywh' and value.shape[1] == 4:
82 value = np.hstack([value, np.ones([value.shape[0], 1])])
83 tmp_data_dict[key] = value
84 else:
85 tmp_data_dict[key] = value
86 self.update(tmp_data_dict)
87 self.__set_default_values__()
88
89 def dump(self, npz_path: str, overwrite: bool = True):
90 """Dump keys and items to an npz file.

Callers 1

load_by_pickleMethod · 0.45

Calls 4

__setattr__Method · 0.80
itemsMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected