glimpse.experiment.om_wkmeans

class BaseMaskCache(model, get_mask_path=None)[source]

An abstract base class for object mask caches.

__getitem__(img_path)[source]

Get object mask for image.

Parameters:img_path (str) – Path to image for which object mask should be returned.
Return type:2D array of float
Returns:Object mask as matrix of float, with values in [0,1).
class MaskCache(model, mask_dir)[source]

Bases: glimpse.experiment.om_wkmeans.BaseMaskCache

A cache for object masks.

get_mask_path(img_path)[source]

Get the path to an object mask on disk.

Parameters:img_path (str) – Path to image for which mask should be returned.
Return type:str
Returns:Path to object mask image.
PrototypeFGRatio(exp, masks)[source]

Compute the foreground ratio for each prototype.

The foreground ratio is the number of foreground pixels in the receptive field, divided by the total number of pixels in the receptive field. If the image has no foreground object, its foreground ratio is defined to be zero.

Parameters:masks – Mapping from image path to mask path. This will usually be a :class:MaskCache.
Returns:Foreground ratio for each imprinted prototype in experiment.
Return type:1-d array of float
LearnPatchesFromImages(exp, masks, num_samples, num_prototypes, pool, base_weight=None, progress=None)[source]

Learn patch models by object-mask weighted k-Means clustering.

Weights are given by the overlap between the image patch and the image’s foreground object.

Parameters:
  • masks – Mapping from image path to mask path. This will usually be a :class:MaskCache.
  • num_samples (int) – Number of samples used to cluster via k-Means.
  • num_prototypes (int) – Number of centroids used for k-Means.
  • pool – Worker pool to use when extracting patches.
  • base_weight (float) – Value added to all weights before learning.
  • progress – Handler for incremental progress updates.
Returns:

Learned patches.

Return type:

array of float

Previous topic

glimpse.experiment.mf_wkmeans

Next topic

glimpse.glab.api

This Page