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

Method get_sliced_cache

detrsmpl/data/data_structures/human_data.py:297–381  ·  view source on GitHub ↗

Slice the whole HumanData into pieces for HumanDataCacheWriter. Args: slice_size (int, optional): The length of each unit in HumanData cache. Defaults to 10. Returns: List: Two dicts for HumanDataCacheWriter.

(self, slice_size=10)

Source from the content-addressed store, hash-verified

295 np.savez_compressed(npz_path, **dict_to_dump)
296
297 def get_sliced_cache(self, slice_size=10) -> List:
298 """Slice the whole HumanData into pieces for HumanDataCacheWriter.
299
300 Args:
301 slice_size (int, optional):
302 The length of each unit in HumanData cache.
303 Defaults to 10.
304
305 Returns:
306 List:
307 Two dicts for HumanDataCacheWriter.
308 Init HumanDataCacheWriter by HumanDataCacheWriter(**Returns[0])
309 and set data by
310 human_data_cache_writer.update_sliced_dict(Returns[1]).
311 """
312 keypoints_info = {}
313 non_sliced_data = {}
314 sliced_data = {}
315 slice_num = ceil(self.__data_len__ / slice_size)
316 for slice_index in range(slice_num):
317 sliced_data[str(slice_index)] = {}
318 dim_dict = self.__get_slice_dim__()
319 for key, dim in dim_dict.items():
320 # no dim to slice
321 if dim is None:
322 if key.startswith('keypoints') and\
323 (key.endswith('_mask') or
324 key.endswith('_convention')):
325 keypoints_info[key] = self[key]
326 else:
327 non_sliced_data[key] = self[key]
328 elif isinstance(dim, dict):
329 value_dict = self.get_raw_value(key)
330 non_sliced_sub_dict = {}
331 for sub_key in value_dict.keys():
332 sub_value = value_dict[sub_key]
333 if dim[sub_key] is None:
334 non_sliced_sub_dict[sub_key] = sub_value
335 else:
336 sub_dim = dim[sub_key]
337 for slice_index in range(slice_num):
338 slice_start = slice_index * slice_size
339 slice_end = min((slice_index + 1) * slice_size,
340 self.__data_len__)
341 slice_range = slice(slice_start, slice_end)
342 sliced_sub_value = \
343 HumanData.__get_sliced_result__(
344 sub_value, sub_dim, slice_range
345 )
346 if key not in sliced_data[str(slice_index)]:
347 sliced_data[str(slice_index)][key] = {}
348 sliced_data[str(slice_index)][key][sub_key] = \
349 sliced_sub_value
350 if len(non_sliced_sub_dict) > 0:
351 non_sliced_data[key] = non_sliced_sub_dict
352 else:
353 value = self.get_raw_value(key)
354 # slice as ndarray

Callers 1

load_annotationsMethod · 0.80

Calls 6

__get_slice_dim__Method · 0.95
get_raw_valueMethod · 0.95
get_key_strictMethod · 0.95
itemsMethod · 0.45
keysMethod · 0.45
__get_sliced_result__Method · 0.45

Tested by

no test coverage detected