Exemplo n.º 1
0
    def __call__(self, results):

        if results.get(f'{self.item}_root_removed', False):
            raise RuntimeError('The transform RelativeJointRandomFlip should '
                               f'not be applied to {self.item} whose root '
                               'joint has been removed and joint indices have '
                               'been changed')

        if np.random.rand() <= self.flip_prob:

            flip_pairs = results['ann_info']['flip_pairs']
            # flip joint coordinates
            assert self.item in results
            joints = results[self.item]

            joints_flipped = fliplr_regression(joints,
                                               flip_pairs,
                                               center_mode='root',
                                               center_index=self.root_index)

            results[self.item] = joints_flipped
            # flip joint visibility
            if self.vis_item is not None:
                assert self.vis_item in results
                visible = results[self.vis_item]
                visible_flipped = visible.copy()
                for left, right in flip_pairs:
                    visible_flipped[..., left, :] = visible[..., right, :]
                    visible_flipped[..., right, :] = visible[..., left, :]
                results[self.vis_item] = visible_flipped

        return results
Exemplo n.º 2
0
    def __call__(self, results):

        if results.get(f'{self.item}_root_removed', False):
            raise RuntimeError('The transform RelativeJointRandomFlip should '
                               f'not be applied to {self.item} whose root '
                               'joint has been removed and joint indices have '
                               'been changed')

        if np.random.rand() <= self.flip_prob:

            flip_pairs = results['ann_info']['flip_pairs']

            # flip joint coordinates
            for i, item in enumerate(self.item):
                assert item in results
                joints = results[item]

                joints_flipped = fliplr_regression(joints, flip_pairs,
                                                   **self.flip_cfg[i])

                results[item] = joints_flipped

            # flip joint visibility
            for vis_item in self.vis_item:
                assert vis_item in results
                visible = results[vis_item]
                visible_flipped = visible.copy()
                for left, right in flip_pairs:
                    visible_flipped[..., left, :] = visible[..., right, :]
                    visible_flipped[..., right, :] = visible[..., left, :]
                results[vis_item] = visible_flipped

            # flip horizontal distortion coefficients
            if self.flip_camera:
                if self.static_camera:
                    camera_param = copy.deepcopy(self.camera_param)
                else:
                    assert 'camera_param' in results, \
                        'Camera parameters are missing.'
                    camera_param = results['camera_param']
                assert 'c' in camera_param
                camera_param['c'][0] *= -1

                if 'p' in camera_param:
                    camera_param['p'][0] *= -1

                if 'camera_param' not in results:
                    results['camera_param'] = dict()
                results['camera_param'].update(camera_param)

        return results
Exemplo n.º 3
0
    def inference_model(self, x, flip_pairs=None):
        """Inference function.

        Returns:
            output_regression (np.ndarray): Output regression.

        Args:
            x (torch.Tensor[N, K, 2]): Input features.
            flip_pairs (None | list[tuple()):
                Pairs of keypoints which are mirrored.
        """
        output = self.forward(x)

        if flip_pairs is not None:
            output_regression = fliplr_regression(
                output.detach().cpu().numpy(), flip_pairs)
        else:
            output_regression = output.detach().cpu().numpy()
        return output_regression