MCPcopy Create free account
hub / github.com/OpenGVLab/HumanBench / tta_mapper

Method tta_mapper

PATH/core/models/tta.py:60–103  ·  view source on GitHub ↗

Args: dict: a dict in standard model input format. See tutorials for details. Returns: list[dict]: a list of dicts, which contain augmented version of the input image. The total number of dicts is ``len(min_sizes) * (2 if flip

(self, dataset_dict)

Source from the content-addressed store, hash-verified

58 self.batch_size = batch_size
59
60 def tta_mapper(self, dataset_dict):
61 """
62 Args:
63 dict: a dict in standard model input format. See tutorials for details.
64
65 Returns:
66 list[dict]:
67 a list of dicts, which contain augmented version of the input image.
68 The total number of dicts is ``len(min_sizes) * (2 if flip else 1)``.
69 Each dict has field "transforms" which is a TransformList,
70 containing the transforms that are used to generate this image.
71 """
72 assert len(dataset_dict["image"].shape) == 4
73 numpy_image = dataset_dict["image"].squeeze().permute(1, 2, 0).cpu().numpy()
74 shape = numpy_image.shape
75 orig_shape = (dataset_dict["height"], dataset_dict["width"])
76 if shape[:2] != orig_shape:
77 # It transforms the "original" image in the dataset to the input image
78 pre_tfm = ResizeTransform(orig_shape[0], orig_shape[1], shape[0], shape[1])
79 else:
80 pre_tfm = NoOpTransform()
81
82 # Create all combinations of augmentations to use
83 aug_candidates = [] # each element is a list[Augmentation]
84 for min_size in self.min_sizes:
85 resize = ResizeShortestEdge(min_size, self.max_size)
86 aug_candidates.append([resize]) # resize only
87 if self.flip:
88 flip = RandomFlip(prob=1.0)
89 aug_candidates.append([resize, flip]) # resize + flip
90
91 # Apply all the augmentations
92 ret = []
93 for aug in aug_candidates:
94 new_image, tfms = apply_augmentations(aug, np.copy(numpy_image))
95 torch_image = torch.from_numpy(np.ascontiguousarray(new_image.transpose(2, 0, 1)))
96
97 torch_image = torch_image.unsqueeze(0)
98
99 dic = copy.deepcopy(dataset_dict)
100 dic["transforms"] = pre_tfm + tfms
101 dic["image"] = torch_image.cuda()
102 ret.append(dic)
103 return ret
104
105 def __call__(self, batched_inputs, current_step):
106 """

Callers 1

_get_augmented_inputsMethod · 0.95

Calls 7

ResizeTransformClass · 0.90
NoOpTransformClass · 0.90
ResizeShortestEdgeClass · 0.90
RandomFlipClass · 0.90
apply_augmentationsFunction · 0.90
permuteMethod · 0.80
cudaMethod · 0.45

Tested by

no test coverage detected