def get_packed_inputs(batch_size=2,
                      num_instances=1,
                      num_keypoints=17,
                      num_levels=1,
                      img_shape=(256, 192),
                      input_size=(192, 256),
                      heatmap_size=(48, 64),
                      simcc_split_ratio=2.0,
                      with_heatmap=True,
                      with_reg_label=True,
                      with_simcc_label=True):
    """Create a dummy batch of model inputs and data samples."""
    rng = np.random.RandomState(0)

    inputs_list = []
    for idx in range(batch_size):
        inputs = dict()

        # input
        h, w = img_shape
        image = rng.randint(0, 255, size=(3, h, w), dtype=np.uint8)
        inputs['inputs'] = torch.from_numpy(image)

        # meta
        img_meta = {
            'id': idx,
            'img_id': idx,
            'img_path': '<demo>.png',
            'img_shape': img_shape,
            'input_size': input_size,
            'flip': False,
            'flip_direction': None,
            'flip_indices': list(range(num_keypoints))
        }

        np.random.shuffle(img_meta['flip_indices'])
        data_sample = PoseDataSample(metainfo=img_meta)

        # gt_instance
        gt_instances = InstanceData()
        gt_instance_labels = InstanceData()
        bboxes = _rand_bboxes(rng, num_instances, w, h)
        bbox_centers, bbox_scales = bbox_xyxy2cs(bboxes)

        keypoints = _rand_keypoints(rng, bboxes, num_keypoints)
        keypoints_visible = np.ones((num_instances, num_keypoints),
                                    dtype=np.float32)

        # [N, K] -> [N, num_levels, K]
        # keep the first dimension as the num_instances
        if num_levels > 1:
            keypoint_weights = np.tile(keypoints_visible[:, None],
                                       (1, num_levels, 1))
        else:
            keypoint_weights = keypoints_visible.copy()

        gt_instances.bboxes = bboxes
        gt_instances.bbox_centers = bbox_centers
        gt_instances.bbox_scales = bbox_scales
        gt_instances.bbox_scores = np.ones((num_instances, ), dtype=np.float32)
        gt_instances.keypoints = keypoints
        gt_instances.keypoints_visible = keypoints_visible

        gt_instance_labels.keypoint_weights = torch.FloatTensor(
            keypoint_weights)

        if with_reg_label:
            gt_instance_labels.keypoint_labels = torch.FloatTensor(keypoints /
                                                                   input_size)

        if with_simcc_label:
            len_x = np.around(input_size[0] * simcc_split_ratio)
            len_y = np.around(input_size[1] * simcc_split_ratio)
            gt_instance_labels.keypoint_x_labels = torch.FloatTensor(
                _rand_simcc_label(rng, num_instances, num_keypoints, len_x))
            gt_instance_labels.keypoint_y_labels = torch.FloatTensor(
                _rand_simcc_label(rng, num_instances, num_keypoints, len_y))

        # gt_fields
        if with_heatmap:
            if num_levels == 1:
                gt_fields = PixelData()
                # generate single-level heatmaps
                W, H = heatmap_size
                heatmaps = rng.rand(num_keypoints, H, W)
                gt_fields.heatmaps = torch.FloatTensor(heatmaps)
            else:
                # generate multilevel heatmaps
                heatmaps = []
                for _ in range(num_levels):
                    W, H = heatmap_size
                    heatmaps_ = rng.rand(num_keypoints, H, W)
                    heatmaps.append(torch.FloatTensor(heatmaps_))
                # [num_levels*K, H, W]
                gt_fields = MultilevelPixelData()
                gt_fields.heatmaps = heatmaps
            data_sample.gt_fields = gt_fields

        data_sample.gt_instances = gt_instances
        data_sample.gt_instance_labels = gt_instance_labels

        inputs['data_samples'] = data_sample
        inputs_list.append(inputs)

    packed_inputs = pseudo_collate(inputs_list)
    return packed_inputs
Create a dummy batch of model inputs and data samples.
mmpose/mmpose/testing/_utils.py