glimpse.backends

ACTIVATION_DTYPE

Element type for an array of Glimpse activation values.

DEFAULT_BACKEND_NAME

Backend name used by MakeBackend when no name is supplied.

MakeBackend(name=None)

Return an instance of the given backend.

Parameters:name (str) – Name of requested backend.
class InputLoadError(source=None)

Thrown when an input source can not be loaded.

source = None

The source of the exception. This is generally an InputSource object.

class InputSource(image_path=None)

Describes the input to a hierarchical model.

Example:

Load a still image from disk.

>>> source = InputSource(image_path = "/tmp/MyImage.jpg")
CreateImage()

Reads image from this input source.

Return type:PIL.Image
image_path = None

Path to the image file.

exception BackendError(msg=None, source=None, layer=None, scale=None)

Thrown when an unexpected error occurs during backend processing.

layer = None

The model layer that was being computed.

scale = None

The scale band that was being computed.

source = None

The source of the exception. This is generally an InputSource object.

exception InputSizeError(msg=None, source=None, layer=None, scale=None)

Thrown when an input array was too small (spatially).

class IBackend

The interface implemented by all backend implementations.

ContrastEnhance(data, kwidth, bias, scaling, out=None)

Apply local contrast stretch to an array.

Given a local input neighborhood \(X\), the output is

\[y = \frac{x_c - \mu}{\max(\sigma, \epsilon)}\]

where \(x_c\) is the center of the input neighborhood, \(\mu\) and \(\sigma\) are the mean and standard deviation of \(X\), and \(\epsilon\) is a bias term. This term is used to avoid the amplificiation of noise and to ensure a non-zero divisor.

Parameters:
  • data (2D ndarray of float) – Input data.
  • kwidth (int) – Kernel width.
  • bias (float) – Normalizing term \(\epsilon\) in denominator.
  • scaling (positive int) – Subsampling factor.
  • out (2D ndarray of float) – Array in which to store result. If None, a new array will be created.
Return type:

2D ndarray of float

DotProduct(data, kernels, scaling=None, out=None, **ignore)

Convolve an array with a set of kernels.

This function compares each kernel \(W\) and input neigborhood \(X\) using a dot product, where the output is given by

\[y = X^T W \, ,\]

where \(X^T\) denotes the matrix transpose.

Parameters:
  • data (3D ndarray of float) – Input data.
  • kernels (4D ndarray of float) – Array of 3D kernels.
  • scaling (positive int) – Subsampling factor.
  • out (3D ndarray of float) – Array in which to store result. If None, a new array will be created.
Return type:

3D ndarray of float

GlobalMax(data, out=None)

Find the per-band maxima.

Parameters:
  • data (3D ndarray of float) – Input data.
  • out (1D ndarray of float) – Array in which to store result. If None, a new array will be created.
Return type:

1D ndarray of float

InputMapShapeForOutput(kheight, kwidth, scaling, oheight, owidth)

Given an output map with the given dimensions, compute the shape of the corresponding input map.

This is the inverse of OutputMapShapeForInput().

Parameters:
  • kheight (positive int) – Kernel height.
  • kwidth (positive int) – Kernel width.
  • scaling (positive int) – Subsampling factor.
  • oheight (positive int) – Output map height.
  • owidth (positive int) – Output map width.
Returns:

Input map height and width, in that order.

Return type:

2-tuple of int

LocalMax(data, kwidth, scaling, out=None)

Convolve maps with local 2-D max filter.

The output for each local input neighborhood \(X\) is

\[y = max_i \ x_i \, .\]
Parameters:
  • data (3D ndarray of float) – Input data.
  • kwidth (positive int) – Width of pooling neighborhood.
  • scaling (positive int) – Subsampling factor.
  • out (3D ndarray of float) – Array in which to store result. If None, a new array will be created.
Return type:

3D ndarray of float

NormDotProduct(data, kernels, bias=None, scaling=None, out=None, **ignore)

Convolve an array with a set of kernels, normalizing the response by the vector length of the input neighborhood.

The output for each kernel \(W\) and input neighborhood \(X\) is given by

\[y = \frac{X^T W}{\left\Vert X \right\Vert \left\Vert W \right\Vert} \, ,\]

where \(\left\Vert \cdot \right\Vert\) denotes the Euclidean norm.

Parameters:
  • data (3D ndarray of float) – Input data.
  • kernels (4D ndarray of float) – Array of 3D kernels, where each kernel is expected to have unit vector length.
  • bias (float) – Threshold for denominator.
  • scaling (positive int) – Subsampling factor.
  • out (3D ndarray of float) – Array in which to store result. If None, a new array will be created.
Return type:

3D ndarray of float

NormRbf(data, kernels, bias=None, beta=None, scaling=None, out=None, **ignore)
Compare kernels to input data using the RBF activation function with
normed inputs.

The output for each kernel \(W\) and input neighborhood \(X\) is given by

\[y = \exp \left\{ - 2\beta \left(1 - \text{NDP}(X, W) \right) \right\} \, ,\]

where \(\text{NDP}(\cdot)\) is the normalized dot product.

Parameters:
  • data (3D ndarray of float) – Input data.
  • kernels (4D ndarray of float) – Array of 3D kernels, where each kernel is expected to have unit length.
  • bias (float) – Additive term in denominator.
  • beta (float) – Tuning parameter for radial basis function.
  • scaling (positive int) – Subsampling factor.
  • out (3D ndarray of float) – Array in which to store result. If None, a new array will be created.
Return type:

3D ndarray of float

OutputMapShapeForInput(kheight, kwidth, scaling, iheight, iwidth)

Given an input map with the given dimensions, compute the shape of the corresponding output map.

Parameters:
  • kheight (positive int) – Kernel height.
  • kwidth (positive int) – Kernel width.
  • scaling (positive int) – Subsampling factor.
  • iheight (positive int) – Input map height.
  • iwidth (positive int) – Input map width.
Returns:

Output map height and width, in that order.

Return type:

2-tuple of int

PrepareArray(array)

Prepare array to be passed to backend methods.

Parameters:array (ndarray of float) – Array to be prepared, which will not be modified.
Return type:ndarray of float
Rbf(data, kernels, beta=None, scaling=None, out=None, **ignore)

Compare kernels to input data using the RBF activation function.

The output for each kernel \(W\) and input neighborhood \(X\) is given by

\[y = \exp \left\{ - \beta \left\Vert X - W \right\Vert ^2 \right\} \, ,\]

where \(\beta\) controls the sensitivity of the RBF.

Parameters:
  • data (3D ndarray of float) – Input data.
  • kernels (4D ndarray of float) – Array of 3D kernels.
  • beta (float) – Tuning parameter for radial basis function.
  • scaling (positive int) – Subsampling factor.
  • out (3D ndarray of float) – Array in which to store result. If None, a new array will be created.
Return type:

3D ndarray of float

base_backend Module

class BaseBackend[source]

IBackend implementation using vanilla C++ code.

scipy_backend Module

class ScipyBackend[source]

IBackend implementation using calls to scipy functions.

Table Of Contents

Previous topic

API Reference

Next topic

glimpse.models

This Page