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

Class MultiHumanData

detrsmpl/data/data_structures/multi_human_data.py:35–480  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33
34
35class MultiHumanData(HumanData):
36 SUPPORTED_KEYS = _MultiHumanData_SUPPORTED_KEYS
37
38 def __new__(cls: _HumanData, *args: Any, **kwargs: Any) -> _HumanData:
39 """New an instance of HumanData.
40
41 Args:
42 cls (HumanData): HumanData class.
43
44 Returns:
45 HumanData: An instance of Hu
46 """
47 ret_human_data = super().__new__(cls, args, kwargs)
48 setattr(ret_human_data, '__data_len__', -1)
49 setattr(ret_human_data, '__instance_num__', -1)
50 setattr(ret_human_data, '__key_strict__', False)
51 setattr(ret_human_data, '__keypoints_compressed__', False)
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.
91
92 Args:

Callers 1

load_annotationsMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected