def set_field(self,
                  value: Any,
                  name: str,
                  dtype: Optional[Union[Type, Tuple[Type, ...]]] = None,
                  field_type: str = 'data') -> None:
        """Special method for set union field, used as property.setter
        functions."""
        assert field_type in ['metainfo', 'data']
        if dtype is not None:
            assert isinstance(
                value,
                dtype), f'{value} should be a {dtype} but got {type(value)}'

        if name.startswith('_level_'):
            raise AttributeError(
                f'Cannot set {name} to be a field because the pattern '
                '<_level_{n}> is reserved for inner data field')

        if field_type == 'metainfo':
            if name in self._data_fields:
                raise AttributeError(
                    f'Cannot set {name} to be a field of metainfo '
                    f'because {name} is already a data field')
            self._metainfo_fields.add(name)

        else:
            if name in self._metainfo_fields:
                raise AttributeError(
                    f'Cannot set {name} to be a field of data '
                    f'because {name} is already a metainfo field')

            if not isinstance(value, abc.Sequence):
                raise TypeError(
                    'The value should be a sequence (of numpy.ndarray or'
                    f'torch.Tesnor), but got a {type(value)}')

            if len(value) == 0:
                raise ValueError('Setting empty value is not allowed')

            if not isinstance(value[0], (torch.Tensor, np.ndarray)):
                raise TypeError(
                    'The value should be a sequence of numpy.ndarray or'
                    f'torch.Tesnor, but got a sequence of {type(value[0])}')

            if self.nlevel is not None:
                assert len(value) == self.nlevel, (
                    f'The length of the value ({len(value)}) should match the'
                    f'number of the levels ({self.nlevel})')
            else:
                object.__setattr__(self, '_nlevel', len(value))
                for i in range(self.nlevel):
                    object.__setattr__(self, f'_level_{i}', PixelData())

            for i, v in enumerate(value):
                self[i].set_field(v, name, field_type='data')

            self._data_fields.add(name)

        object.__setattr__(self, name, value)
Special method for set union field, used as property.setter
        functions.
mmpose/mmpose/structures/multilevel_pixel_data.py