class documentation

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_pathsan iterable of image paths
patchesa 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
samplesa fiftyone.core.collections.SampleCollection from which to extract patches
patches_fieldthe 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_missing

how to handle images with no patches. The supported values are:

  • "skip": skip the image and assign its embedding as None
  • "image": use the whole image as a single patch
  • "error": raise an error
transforman optional transform function to apply to each image patch. When use_numpy == False, this is typically a torchvision transform
sample_idsan iterable of sample IDs corresponding to each image
include_idswhether to include the IDs of the samples in the returned items
ragged_batcheswhether the provided transform may return tensors of different dimensions and thus cannot be stacked
use_numpywhether to use numpy arrays rather than PIL images and Torch tensors when loading data
force_rgbwhether to force convert the images to RGB
force_squarewhether to minimally manipulate the patch bounding boxes into squares prior to extraction
alphaan 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_failureswhether 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_rgb Undocumented
Instance Variable force_square Undocumented
Instance Variable image_paths Undocumented
Instance Variable ragged_batches Undocumented
Instance Variable sample_ids Undocumented
Instance Variable skip_failures Undocumented
Instance Variable transform Undocumented
Instance Variable use_numpy Undocumented
Property has_sample_ids Whether this dataset has sample IDs.
Method _extract_patches Undocumented
Method _parse_inputs Undocumented
Instance Variable _patch_edges Undocumented
Instance Variable _patches Undocumented
def __getitem__(self, idx): (source)

Undocumented

def __init__(self, image_paths=None, patches=None, samples=None, patches_field=None, handle_missing='skip', transform=None, sample_ids=None, include_ids=False, ragged_batches=False, use_numpy=False, force_rgb=False, force_square=False, alpha=None, skip_failures=False): (source)

Undocumented

def __len__(self): (source)

Undocumented

Undocumented

force_rgb: False = (source)

Undocumented

force_square: False = (source)

Undocumented

image_paths: None = (source)

Undocumented

ragged_batches: False = (source)

Undocumented

sample_ids: None = (source)

Undocumented

skip_failures: False = (source)

Undocumented

transform: None = (source)

Undocumented

use_numpy: False = (source)

Undocumented

@property
has_sample_ids = (source)

Whether this dataset has sample IDs.

def _extract_patches(self, image_path, patches): (source)

Undocumented

def _parse_inputs(self, image_paths=None, patches=None, samples=None, patches_field=None, handle_missing='skip', sample_ids=None, include_ids=False): (source)

Undocumented

_patch_edges = (source)

Undocumented

_patches = (source)

Undocumented