wrap_dataset_for_transforms_v2¶
- torchaug.data.dataset.wrap_dataset_for_transforms_v2(dataset, target_keys=None)[source]¶
Wrap a
torchvision.datasetfor usage withtorchaug.transforms.Example
>>> dataset = torchvision.datasets.CocoDetection(...) >>> dataset = wrap_dataset_for_transforms_v2(dataset)
Note
For now, only the most popular datasets are supported. Furthermore, the wrapper only supports dataset configurations that are fully supported by
torchaug.transforms. If you encounter an error prompting you to raise an issue totorchvisionfor a dataset or configuration that you need, please do so.The dataset samples are wrapped according to the description below.
Special cases:
torchvision.datasets.CocoDetection: Instead of returning the target as list of dicts, the wrapper returns a dict of lists. In addition, the key-value-pairs"boxes"(inXYXYcoordinate format),"masks"and"labels"are added and wrap the data in the correspondingtorchaug.ta_tensors. The original keys are preserved. Iftarget_keysis omitted, returns only the values for the"image_id","boxes", and"labels".torchvision.datasets.VOCDetection: The key-value-pairs"boxes"and"labels"are added to the target and wrap the data in the correspondingtorchaug.ta_tensors. The original keys are preserved. Iftarget_keysis omitted, returns only the values for the"boxes"and"labels".torchvision.datasets.CelebA: The target fortarget_type="bbox"is converted to theXYXYcoordinate format and wrapped into aBoundingBoxesta_tensors.torchvision.datasets.Kitti: Instead returning the target as list of dicts, the wrapper returns a dict of lists. In addition, the key-value-pairs"boxes"and"labels"are added and wrap the data in the correspondingtorchaug.ta_tensors. The original keys are preserved. Iftarget_keysis omitted, returns only the values for the"boxes"and"labels".torchvision.datasets.OxfordIIITPet: The target fortarget_type="segmentation"is wrapped into atorchaug.ta_tensors._mask.Maskta_tensors.torchvision.datasets.Cityscapes: The target fortarget_type="semantic"is wrapped into atorchaug.ta_tensors._mask.Maskta_tensors. The target fortarget_type="instance"is replaced by a dictionary with the key-value-pairs"masks"(astorchaug.ta_tensors._mask.Maskta_tensors) and"labels".torchvision.datasets.WIDERFace: The value for key"bbox"in the target is converted toXYXYcoordinate format and wrapped into aBoundingBoxesta_tensors.
Image classification datasets
This wrapper is a no-op for image classification datasets, since they were already fully supported by
torchaug.transformsand thus no change is needed fortorchaug.transforms.Segmentation datasets
Segmentation datasets, e.g.
torchvision.datasets.VOCSegmentation, return a two-tuple ofPIL.Image.Image’s. This wrapper leaves the image as is (first item), while wrapping the segmentation mask into atorchaug.ta_tensors._mask.Mask(second item).Video classification datasets
Video classification datasets, e.g.
torchvision.datasets.Kinetics, return a three-tuple containing atorch.Tensorfor the video and audio and aintas label. This wrapper wraps the video into aVideowhile leaving the other items as is.Note
Only datasets constructed with
output_format="TCHW"are supported, since the alternativeoutput_format="THWC"is not supported bytorchaug.transforms.- Parameters:
dataset – the dataset instance to wrap for compatibility with transforms v2.
target_keys (optional) – Target keys to return in case the target is a dictionary. If
None(default), selected keys are specific to the dataset. If"all", returns the full target. Can also be a collection of strings for fine grained access. Currently only supported fortorchvision.datasets.CocoDetection,torchvision.datasets.VOCDetection,torchvision.datasets.Kitti, andtorchvision.datasets.WIDERFace. See above for details. Default:None