in meshrcnn/data/meshrcnn_transforms.py [0:0]
def __call__(self, dataset_dict):
"""
Transform the dataset_dict according to the configured transformations.
Args:
dataset_dict (dict): Metadata of one image, in Detectron2 Dataset format.
Returns:
dict: a new dict that's going to be processed by the model.
It currently does the following:
1. Read the image from "file_name"
2. Transform the image and annotations
3. Prepare the annotations to :class:`Instances`
"""
# get 3D models for each annotations and remove 3D mesh models from image dict
mesh_models = []
if "annotations" in dataset_dict:
for anno in dataset_dict["annotations"]:
mesh_models.append(
[
self._all_mesh_models[anno["mesh"]][0].clone(),
self._all_mesh_models[anno["mesh"]][1].clone(),
]
)
dataset_dict = {key: value for key, value in dataset_dict.items() if key != "mesh_models"}
dataset_dict = copy.deepcopy(dataset_dict) # it will be modified by code below
if "annotations" in dataset_dict:
for i, anno in enumerate(dataset_dict["annotations"]):
anno["mesh"] = mesh_models[i]
image = utils.read_image(dataset_dict["file_name"], format=self.img_format)
utils.check_image_size(dataset_dict, image)
image, transforms = T.apply_transform_gens(self.tfm_gens, image)
image_shape = image.shape[:2] # h, w
# Pytorch's dataloader is efficient on torch.Tensor due to shared-memory,
# but not efficient on large generic data structures due to the use of pickle & mp.Queue.
# Therefore it's important to use torch.Tensor.
dataset_dict["image"] = torch.as_tensor(image.transpose(2, 0, 1).astype("float32"))
# Can use uint8 if it turns out to be slow some day
if not self.is_train:
dataset_dict.pop("annotations", None)
return dataset_dict
if "annotations" in dataset_dict:
annos = [
self.transform_annotations(obj, transforms, image_shape)
for obj in dataset_dict.pop("annotations")
if obj.get("iscrowd", 0) == 0
]
# Should not be empty during training
instances = annotations_to_instances(annos, image_shape)
dataset_dict["instances"] = instances[instances.gt_boxes.nonempty()]
return dataset_dict