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

Method decompress_keypoints

detrsmpl/data/data_structures/human_data.py:1046–1083  ·  view source on GitHub ↗

If a key contains 'keypoints', and f'{key}_mask' is in self.keys(), invalid zeros will be inserted to the right places and f'{key}_mask' will be unlocked. Raises: KeyError: A key contains 'keypoints' has been found but its correspo

(self)

Source from the content-addressed store, hash-verified

1044 self.__keypoints_compressed__ = True
1045
1046 def decompress_keypoints(self) -> None:
1047 """If a key contains 'keypoints', and f'{key}_mask' is in self.keys(),
1048 invalid zeros will be inserted to the right places and f'{key}_mask'
1049 will be unlocked.
1050
1051 Raises:
1052 KeyError:
1053 A key contains 'keypoints' has been found
1054 but its corresponding mask is missing.
1055 """
1056 assert self.__keypoints_compressed__ is True
1057 key_pairs = []
1058 for key in self.keys():
1059 mask_key = f'{key}_mask'
1060 val = self.get_raw_value(key)
1061 if isinstance(val, np.ndarray) and \
1062 'keypoints' in key and \
1063 '_mask' not in key:
1064 if mask_key in self:
1065 key_pairs.append([key, mask_key])
1066 else:
1067 class_logger = self.__class__.logger
1068 msg = f'Mask for {key} has not been found.' +\
1069 f'Please remove {key} before decompression.'
1070 print_log(msg=msg,
1071 logger=class_logger,
1072 level=logging.ERROR)
1073 raise KeyError
1074 decompressed_dict = {}
1075 for kpt_key, mask_key in key_pairs:
1076 mask_array = np.asarray(self.get_raw_value(mask_key))
1077 compressed_kpt = self.get_raw_value(kpt_key)
1078 kpt_array = \
1079 self.__class__.__add_zero_pad__(compressed_kpt, mask_array)
1080 decompressed_dict[kpt_key] = kpt_array
1081 # set value after all pairs are decompressed
1082 self.update(decompressed_dict)
1083 self.__keypoints_compressed__ = False
1084
1085 def dump_by_pickle(self, pkl_path: str, overwrite: bool = True) -> None:
1086 """Dump keys and items to a pickle file. It's a secondary dump method,

Callers 2

load_annotationsMethod · 0.45
load_annotationsMethod · 0.45

Calls 4

get_raw_valueMethod · 0.95
__add_zero_pad__Method · 0.80
keysMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected