MCPcopy Create free account
hub / github.com/PeizeSun/SparseR-CNN / DatasetMapper

Class DatasetMapper

detectron2/data/dataset_mapper.py:20–187  ·  view source on GitHub ↗

A callable which takes a dataset dict in Detectron2 Dataset format, and map it into a format used by the model. This is the default callable to be used to map your dataset dict into training data. You may need to follow it to implement your own one for customized logic, such as

Source from the content-addressed store, hash-verified

18
19
20class DatasetMapper:
21 """
22 A callable which takes a dataset dict in Detectron2 Dataset format,
23 and map it into a format used by the model.
24
25 This is the default callable to be used to map your dataset dict into training data.
26 You may need to follow it to implement your own one for customized logic,
27 such as a different way to read or transform images.
28 See :doc:`/tutorials/data_loading` for details.
29
30 The callable currently does the following:
31
32 1. Read the image from "file_name"
33 2. Applies cropping/geometric transforms to the image and annotations
34 3. Prepare data and annotations to Tensor and :class:`Instances`
35 """
36
37 @configurable
38 def __init__(
39 self,
40 is_train: bool,
41 *,
42 augmentations: List[Union[T.Augmentation, T.Transform]],
43 image_format: str,
44 use_instance_mask: bool = False,
45 use_keypoint: bool = False,
46 instance_mask_format: str = "polygon",
47 keypoint_hflip_indices: Optional[np.ndarray] = None,
48 precomputed_proposal_topk: Optional[int] = None,
49 recompute_boxes: bool = False,
50 ):
51 """
52 NOTE: this interface is experimental.
53
54 Args:
55 is_train: whether it's used in training or inference
56 augmentations: a list of augmentations or deterministic transforms to apply
57 image_format: an image format supported by :func:`detection_utils.read_image`.
58 use_instance_mask: whether to process instance segmentation annotations, if available
59 use_keypoint: whether to process keypoint annotations if available
60 instance_mask_format: one of "polygon" or "bitmask". Process instance segmentation
61 masks into this format.
62 keypoint_hflip_indices: see :func:`detection_utils.create_keypoint_hflip_indices`
63 precomputed_proposal_topk: if given, will load pre-computed
64 proposals from dataset_dict and keep the top k proposals for each image.
65 recompute_boxes: whether to overwrite bounding box annotations
66 by computing tight bounding boxes from instance mask annotations.
67 """
68 if recompute_boxes:
69 assert use_instance_mask, "recompute_boxes requires instance masks"
70 # fmt: off
71 self.is_train = is_train
72 self.augmentations = T.AugmentationList(augmentations)
73 self.image_format = image_format
74 self.use_instance_mask = use_instance_mask
75 self.instance_mask_format = instance_mask_format
76 self.use_keypoint = use_keypoint
77 self.keypoint_hflip_indices = keypoint_hflip_indices

Callers 2

_test_loader_from_configFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected