Dataset Tooling

The tooling for datasets is collected in the module hybrid_learning.datasets. For details have a look at the API Reference.

Base dataset handles

BaseDataset

Abstract base class for tuple datasets with storage location.

ActivationDatasetWrapper

Wrapper for image datasets that will generate and yield activation maps.

Custom dataset handles

coco

Standard and concept datasets derived from MS COCO dataset.

fasseg

Dataset handles for FASSEG-like datasets.

broden

Handles for Broden-like datasets.

Caching handles

Cache handles will allow to insert and read objects into/from a cache. For details see Dataset Caching.

Cache

Caching base handle.

CacheCascade

Combine several caches by trying to load from first to last.

CacheDict

Cache the values of dicts using different caches.

CacheTuple

Cache the values of tuples using different caches.

DictCache

Cache objects in a (multiprocessing capable) dictionary in memory.

FileCache

Base class to cache objects as files under a cache folder.

JPGCache

Cache for JPEG images using PIL.

NPYCache

File cache that uses numpy saving and loading mechanism to cache torch.Tensor objects.

NPZCache

File cache that uses numpy compressed saving and loading mechanism to cache torch.Tensor objects.

NoCache

Dummy cache that has no effect.

PTCache

File cache that uses torch saving and loading mechanism.

TensorDictCache

In-memory cache specifically for torch tensors.

Transformations

Transformations can be used to modify data tuples or values.

Transformations for tuples

ApplyMask

Given a 3-tuple of input, target, mask apply the mask to the first two.

FlattenTuple

Return the value of a sequence at selected index.

Identity

Simple identity transformation for example for defaults.

OnAll

Apply a given transformation to all tuple items.

OnBothSides

Apply a given transformation to both input and target of a tuple in parallel.

OnIndex

Apply a given transformation to tuple items at given indices.

OnInput

Apply a given one-value transformation only to the input of a two-tuple.

OnTarget

Apply a given one-value transformation only to the target of a two-tuple.

PackMask

Given a 3-tuple of prediction, target, mask tensors merge mask and target and return a two-tuple.

ReduceTuple

Transform an unpacked input tuple and then reduce it to one value using a reduction func.

SameSize

Given a tuple of input and target image, resize the target to the size of the input.

SubsetTuple

Return a tuple only containing the elements at given indices of input tuple.

UnfoldTuple

Convenience trafo that takes an iterable and returns it as tuple.

UnpackMask

Undo a PackMask operation on the target.

Transformations for dicts

DictTransform

Basic transformation for dicts.

DropAnn

Drop the annotation with given key from the annotations dict.

FlattenDict

Return the value of the annotations dict at selected key.

OnValues

Perform a transformation on all values of a dict.

RestrictDict

Restrict the annotation dictionary to the annotation items with featuring one of the selected keys.

SameSizeTensorValues

Up- or down-scale the tensor mask values of a dictionary to all have the same size.

Transformations for (tensor) images

AsBatch

Ensure that the given transformation is fed with a batch of inputs.

BatchWiseImageTransform

Wrap a transformation operating on a batch of masks to also work on single masks.

Binarize

Simple class for binarizing tensors into high and low class values.

BinarizeByQuantile

Set all but the given highest number of pixels / q-th quantile in an image to zero, rest to 1.

ConvOpWrapper

Base wrapper class to turn convolutional batch operations into single mask operations.

ImageTransform

Transformations that can be applied to images.

IntersectDecode

IoU encode a single mask.

IntersectEncode

Intersection encode a single mask.

IoUEncode

IoU encode a single mask.

NoGrad

Disable requires_grad for the given tensors.

PadAndResize

Transformation that pads an image to a given ratio and then resizes it to fixed size.

RecursiveLambda

Generic lambda transformation that applies the given function with the standard ImageTransform recursion.

Resize

Simple resize.

Threshold

Threshold tensors and set new values below and/or above the threshold.

ToActMap

Evaluate a given image by a torch model on the correct device.

ToBBoxes

Treat pixels of given mask as scores of constant-size bounding boxes, and return a mask with the non-max-suppressed bounding boxes.

ToFixedDims

Squeeze or unsqueeze a tensor to obtain specified number of dimensions.

ToTensor

Turn objects into tensors or move tensors to given device or dtype.

WithThresh

Wrap a batch transformation with binarizing (and unsqueezing) before and after.

Intersection and intersection over union encoders

BatchBoxBloat

Bloat single pixels to full boxes, always choosing the maximum box to be up front.

BatchConvOp

Base class for encoder that use convolution operations.

BatchIntersectDecode2D

Given batch of IoU encoded masks, estimates the original segmentation mask.

BatchIntersectEncode2D

Apply intersection encoding to batch of input masks of shape (batch, 1, height, width).

BatchIoUEncode2D

Apply intersection over union encoding to an input batch.

BatchPeakDetection

Keep only peak points, i.e. ones that take the maximum value within a window around them.

BatchWindowOp

Base class for encoder that use windowing operations.

Visualization and Utility Functions

From hybrid_learning.datasets.data_visualization

apply_mask(img, mask[, color, alpha])

Apply monochrome (possibly non-binary) mask to image of same size with alpha value.

apply_masks(img, masks[, colors, alphas])

compare_masks(*masks[, colors])

Merge several monochrome masks in different colors into the same image.

mean_proportion_pos_px(masks)

From the given samples, calculate the mean of the proportion of positive pixels per mask.

neg_pixel_prop(data[, max_num_samples, ...])

Collect the mean proportion of negative pixels in the binary segmentation mask data.

to_img(tens)

Transform a (cuda) tensor to a PIL.Image.Image.

to_monochrome_img(img_t)

torch.Tensor to monochrome PIL.Image.Image in 'L' (=8-bit) mode.

visualize_classification_data(dataset[, ...])

Visualize a dataset yielding tuples of the form (input, target_class_identifier).

visualize_mask_transforms(titled_datasets[, ...])

Visualize difference between original and the transformed masks of datasets.

visualize_segmentation_data(dataset[, ...])

Visualize a dataset yielding tuples of the form (input, target_mask).

From hybrid_learning.datasets.base

add_gaussian_peak(mask_np, centroid, ...[, ...])

Add a peak to the heatmap mask_np as a non-normalized gaussian at centroid.

cross_validation_splits(train_val_data, ...)

Split dataset it into num_splits and collect tuples of (rest, split).