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

Method __setitem__

detrsmpl/data/data_structures/human_data.py:669–721  ·  view source on GitHub ↗

Set self[key] to value. Only be called when using human_data[key] = val. Methods like update won't call __setitem__. In keypoints_compressed mode, if the key contains 'keypoints', and f'{key}_mask' is in self.keys(), invalid zeros will be removed before setting value.

(self, key: _KT, val: _VT)

Source from the content-addressed store, hash-verified

667 return ret_dict
668
669 def __setitem__(self, key: _KT, val: _VT) -> None:
670 """Set self[key] to value. Only be called when using
671 human_data[key] = val. Methods like update won't call __setitem__.
672 In keypoints_compressed mode, if the key contains 'keypoints',
673 and f'{key}_mask' is in self.keys(), invalid zeros
674 will be removed before setting value.
675
676 Args:
677 key (_KT):
678 Key in HumanData.
679 Better be an element in HumanData.SUPPORTED_KEYS.
680 If not, an Error will be raised in key_strict mode.
681 val (_VT):
682 Value to the key.
683
684 Raises:
685 KeyError:
686 self.get_key_strict() is True and
687 key cannot be found in
688 HumanData.SUPPORTED_KEYS.
689 ValueError:
690 Value is supported but doesn't match definition.
691 ValueError:
692 self.check_keypoints_compressed() is True and
693 mask of a keypoint item is missing.
694 """
695 self.__check_key__(key)
696 self.__check_value__(key, val)
697 # if it can be compressed by mask
698 if self.__keypoints_compressed__:
699 class_logger = self.__class__.logger
700 if 'keypoints' in key and \
701 '_mask' in key:
702 msg = 'Mask cannot be modified ' +\
703 'in keypoints_compressed mode.'
704 print_log(msg=msg, logger=class_logger, level=logging.WARN)
705 return
706 elif isinstance(val, np.ndarray) and \
707 'keypoints' in key and \
708 '_mask' not in key:
709 mask_key = f'{key}_mask'
710 if mask_key in self:
711 mask_array = np.asarray(super().__getitem__(mask_key))
712 val = \
713 self.__class__.__remove_zero_pad__(val, mask_array)
714 else:
715 msg = f'Mask for {key} has not been set.' +\
716 f' Please set {mask_key} before compression.'
717 print_log(msg=msg,
718 logger=class_logger,
719 level=logging.ERROR)
720 raise ValueError
721 dict.__setitem__(self, key, val)
722
723 def set_raw_value(self, key: _KT, val: _VT) -> None:
724 """Set the raw value of self[key] to val after key check. It acts the

Callers 3

load_annotationsMethod · 0.45
load_annotationsMethod · 0.45
set_raw_valueMethod · 0.45

Calls 4

__check_key__Method · 0.95
__check_value__Method · 0.95
__remove_zero_pad__Method · 0.80
__getitem__Method · 0.45

Tested by

no test coverage detected