class TorchImagePatchesDataset(Dataset): (source)
Constructor: TorchImagePatchesDataset(image_paths, patches, samples, patches_field, ...)
A torch:torch.utils.data.Dataset
of image patch tensors
extracted from a list of images.
Provide either image_paths and patches or samples and patches_field in order to use this dataset.
Instances of this dataset emit image patches for each sample, or (patches, sample_id) tuples if sample_ids are provided or include_ids == True.
By default, this class will load images in PIL format and emit Torch tensors, but you can use numpy images/tensors instead by passing use_numpy = True.
If ragged_batches = False (the default), this class will emit tensors containing the stacked (along axis 0) patches from each image. In this case, the provided transform must ensure that all image patches are resized to the same shape so they can be stacked.
If ragged_batches = True, lists of patch tensors will be returned.
Parameters | |
image | an iterable of image paths |
patches | a list of labels of type
fiftyone.core.labels.Detection ,
fiftyone.core.labels.Detections ,
fiftyone.core.labels.Polyline , or
fiftyone.core.labels.Polylines specifying the image
patch(es) to extract from each image. Elements can be None if
an image has no patches |
samples | a fiftyone.core.collections.SampleCollection
from which to extract patches |
patches | the name of the field defining the image patches
in samples to extract. Must be of type
fiftyone.core.labels.Detection ,
fiftyone.core.labels.Detections ,
fiftyone.core.labels.Polyline , or
fiftyone.core.labels.Polylines |
handle | how to handle images with no patches. The supported values are:
|
transform | an optional transform function to apply to each image patch. When use_numpy == False, this is typically a torchvision transform |
sample | an iterable of sample IDs corresponding to each image |
include | whether to include the IDs of the samples in the returned items |
ragged | whether the provided transform may return tensors of different dimensions and thus cannot be stacked |
use | whether to use numpy arrays rather than PIL images and Torch tensors when loading data |
force | whether to force convert the images to RGB |
force | whether to minimally manipulate the patch bounding boxes into squares prior to extraction |
alpha | an optional expansion/contraction to apply to the patches before extracting them, in [-1, inf). If provided, the length and width of the box are expanded (or contracted, when alpha < 0) by (100 * alpha)%. For example, set alpha = 0.1 to expand the boxes by 10%, and set alpha = -0.1 to contract the boxes by 10% |
skip | whether to return an Exception object rather than raising it if an error occurs while loading a sample |
Method | __getitem__ |
Undocumented |
Method | __init__ |
Undocumented |
Method | __len__ |
Undocumented |
Instance Variable | alpha |
Undocumented |
Instance Variable | force |
Undocumented |
Instance Variable | force |
Undocumented |
Instance Variable | image |
Undocumented |
Instance Variable | ragged |
Undocumented |
Instance Variable | sample |
Undocumented |
Instance Variable | skip |
Undocumented |
Instance Variable | transform |
Undocumented |
Instance Variable | use |
Undocumented |
Property | has |
Whether this dataset has sample IDs. |
Method | _extract |
Undocumented |
Method | _parse |
Undocumented |
Instance Variable | _patch |
Undocumented |
Instance Variable | _patches |
Undocumented |
Undocumented