glimpse.models.ml

class Layer

Bases: glimpse.models.base.model.Layer

Enumerator for model layers.

RETINA = LayerSpec(id_='r', name='retina', depends=[LayerSpec(id_='i', name='image', depends=[LayerSpec(id_='s', name='source', depends=None)])])

Specifier for the preprocessed input.

S1 = LayerSpec(id_='s1', name='S1', depends=[LayerSpec(id_='r', name='retina', depends=[LayerSpec(id_='i', name='image', depends=[LayerSpec(id_='s', name='source', depends=None)])])])

Specifier for the result of S1 filtering.

C1 = LayerSpec(id_='c1', name='C1', depends=[LayerSpec(id_='s1', name='S1', depends=[LayerSpec(id_='r', name='retina', depends=[LayerSpec(id_='i', name='image', depends=[LayerSpec(id_='s', name='source', depends=None)])])])])

Specifier for the result of C1 pooling.

S2 = LayerSpec(id_='s2', name='S2', depends=[LayerSpec(id_='c1', name='C1', depends=[LayerSpec(id_='s1', name='S1', depends=[LayerSpec(id_='r', name='retina', depends=[LayerSpec(id_='i', name='image', depends=[LayerSpec(id_='s', name='source', depends=None)])])])])])

Specifier for the result of S2 filtering.

C2 = LayerSpec(id_='c2', name='C2', depends=[LayerSpec(id_='s2', name='S2', depends=[LayerSpec(id_='c1', name='C1', depends=[LayerSpec(id_='s1', name='S1', depends=[LayerSpec(id_='r', name='retina', depends=[LayerSpec(id_='i', name='image', depends=[LayerSpec(id_='s', name='source', depends=None)])])])])])])

Specifier for the result of C2 (local) pooling.

classmethod AllLayers()

Return the unordered set of all layers.

Return type:list of LayerSpec

Example:

>>> assert(Layer.IMAGE in Layer.AllLayers())
classmethod FromId(id_)

Lookup a LayerSpec object by ID.

Parameters:id – Model-unique layer id_ifier.
Return type:LayerSpec

Example:

>>> lyr = Layer.FromId(Layer.IMAGE.id_)
>>> assert(lyr == Layer.IMAGE)
classmethod FromName(name)

Lookup a LayerSpec object by name.

This method is not case sensitive.

Parameters:name (str) – Layer name.
Return type:LayerSpec

Example:

>>> lyr = Layer.FromName(Layer.IMAGE.name)
>>> assert(lyr == Layer.IMAGE)
classmethod IsSublayer(sub_layer, super_layer)

Determine if one layer appears later in the network than another.

Parameters:
  • sub_layer (LayerSpec) – Lower layer.
  • super_layer (LayerSpec) – Higher layer.
Return type:

bool

Examples:

>>> assert(Layer.IsSublayer(Layer.SOURCE, Layer.IMAGE))
>>> assert(not Layer.IsSublayer(Layer.IMAGE, Layer.SOURCE))
classmethod TopLayer()

Determine the top layer in this network.

The top-most layer is defined as the layer on which no other layer depends. If multiple layers meet this criteria, then the first such layer (as returned by AllLayers()) is returned.

Return type:LayerSpec

Example:

>>> assert(Layer.TopLayer() == Layer.IMAGE)
C1 = LayerSpec(id_='c1', name='C1', depends=[LayerSpec(id_='s1', name='S1', depends=[LayerSpec(id_='r', name='retina', depends=[LayerSpec(id_='i', name='image', depends=[LayerSpec(id_='s', name='source', depends=None)])])])])

Specifier for the result of C1 pooling.

C2 = LayerSpec(id_='c2', name='C2', depends=[LayerSpec(id_='s2', name='S2', depends=[LayerSpec(id_='c1', name='C1', depends=[LayerSpec(id_='s1', name='S1', depends=[LayerSpec(id_='r', name='retina', depends=[LayerSpec(id_='i', name='image', depends=[LayerSpec(id_='s', name='source', depends=None)])])])])])])

Specifier for the result of C2 (local) pooling.

RETINA = LayerSpec(id_='r', name='retina', depends=[LayerSpec(id_='i', name='image', depends=[LayerSpec(id_='s', name='source', depends=None)])])

Specifier for the preprocessed input.

S1 = LayerSpec(id_='s1', name='S1', depends=[LayerSpec(id_='r', name='retina', depends=[LayerSpec(id_='i', name='image', depends=[LayerSpec(id_='s', name='source', depends=None)])])])

Specifier for the result of S1 filtering.

S2 = LayerSpec(id_='s2', name='S2', depends=[LayerSpec(id_='c1', name='C1', depends=[LayerSpec(id_='s1', name='S1', depends=[LayerSpec(id_='r', name='retina', depends=[LayerSpec(id_='i', name='image', depends=[LayerSpec(id_='s', name='source', depends=None)])])])])])

Specifier for the result of S2 filtering.

class State(elements=None, **kw)

Bases: glimpse.models.base.model.State

A container for the Model state.

ModelClass

alias of Model

class Model(backend=None, params=None)

Bases: glimpse.models.base.model.Model

Create a 2-part, HMAX-like hierarchy of S+C layers.

LayerClass

The datatype associated with layer descriptors for this model.

alias of Layer

ParamClass

The parameters type associated with this model.

alias of Params

StateClass

The datatype associated with network states for this model.

alias of State

BuildC1(s1s)

Compute the C1 layer activity from multi-scale S1 activity.

Parameters:s1s (list of 3D ndarray of float) – S1 maps indexed by scale.
Returns:C1 maps indexed by scale and orientation.
Return type:list of 3D ndarray of float
BuildC2(s2s)

Compute global C2 layer activity from multi-scale S2 activity.

Parameters:s2s – S2 maps indexed by scale and prototype.
Type :s2s: list of list of 2D ndarray of float
Returns:C2 activity for each prototype.
Return type:1D ndarray of float
BuildRetina(img)

Compute retinal layer activity from the input image.

Parameters:img – Image data.
Type :2D ndarray of float
Return type:2D ndarray of float
BuildS1(retina)

Apply S1 processing to some existing retinal layer data.

Note

This method pools over phase, so the output has only scale and orientation bands.

Parameters:retina (2D ndarray of float) – Result of retinal layer processing.
Returns:S1 maps indexed by scale and orientation.
Return type:list of 3D ndarray of float
BuildS2(c1s)

Compute the S2 layer activity from multi-scale C1 activity.

Parameters:c1s (list of 3D ndarray of float) – C1 maps indexed by scale and orientation.
Returns:S2 maps indexed by scale, kernel width, and prototype.
Return type:list of list of 3D ndarray of float
MakeState(source, copy=False)

Create a model state wrapper for the given image source.

Parameters:
  • state (str or Image.Image or 2D array of ACTIVATION_DTYPE or State subclass) – Source information
  • copy (bool) – If the input is already a state object, this argument determines whether the state is copied.
Return type:

state.State subclass

If source is an array, values should lie in the range [0,1).

Register(node, f)

Add a callback to compute a value for a node.

Note: be careful of passing a lambda function for f, as this will likely cause an error if serialized.

s1_kernels

The set of S1 kernels, which is generated if not set.

Returns:S1 kernels indexed by orientation, and phase.
Return type:4D ndarray of float
s2_kernels

The set of S2 kernels.

Returns:S2 kernels indexed by kernel size, kernel offset, and orientation.
Return type:list of 4D ndarray of float
class Params(**kw)

Bases: glimpse.models.base.param.Params

Parameter container for glimpse.models.ml.

s1_kernel_shape

The expected shape of the S1 kernels array, including band structure.

Return type:tuple of int
s1_kernels_are_normed

Determine if the model uses unit-norm S1 kernels.

Return type:bool
s2_kernel_shapes

The expected shape of a single S2 kernel.

One shape tuple is returned for each S2 kernel shape supported by the model.

Return type:tuple of tuple of int
s2_kernel_widths

The set of supported S2 kernel widths (i.e., spatial extents).

Return type:tuple of int
s2_kernels_are_normed

Determine if the model uses unit-norm S2 kernels.

Return type:bool
MinimumRetinaSize(params)

Compute the smallest retinal layer that supports the given parameters.

This function discounts the effect of scaling.

Parameters:params – Parameter settings for model.
Return type:int
Returns:Length of smaller edge of retina.
NumScalesSupported(params, retina_size)

Compute the number of scale bands supported for a given retinal size.

This ensures that at least one S2 unit can be computed for every scale band.

Parameters:
  • params – Parameter settings for model.
  • retina_size (int) – Length of shorter edge of retina layer.
Return type:

int

Returns:

Number of scales.

Whiten(data)

Normalize an array, such that each location contains equal energy.

For each X-Y location, the vector \(a\) of data (containing activation for each band) is sphered according to:

\[a' = (a - \mu_a ) / \sigma_a\]

where \(\mu_a\) and \(\sigma_a\) are the mean and standard deviation of \(a\), respectively.

Caution

This function modifies the input data in-place.

Parameters:data (3D ndarray of float) – Layer activity to modify.
Returns:The data array.
Return type:3D ndarray of float
GetS2ReceptiveField(params, scale, y, x, kwidth_offset=0)

Compute the receptive field for a given S2 unit.

Parameters:
  • params (glimpse.models.ml.Params) – Model parameters.
  • scale (int) – Unit’s scale band.
  • y (int) – Unit’s vertical offset.
  • x (int) – Unit’s horizontal offset.
  • kwidth_offset (int) – Offset for S2 kernel width (for models using multiple kernel sizes).
Return type:

4-tuple of int

Returns:

Bounding box (top, bottom, left, right) in image coordinates.

PlotS2ReceptiveField(model, path, scale, y, x, s2_kwidth_offset=0)

Plot the location of an S2 unit’s receptive field on a given image.

Parameters:
  • model – Glimpse model for S2 unit.
  • path (str) – Path to image on disk.
  • scale (int) – Scale band of S2 unit.
  • y (int) – Vertical offset of S2 unit.
  • x (int) – Horizontal offset of S2 unit.
  • s2_kwidth_offset (int) – Offset for kernel width of S2 unit.

Requires matplotlib.

Previous topic

glimpse.models.base.layer

Next topic

glimpse.prototypes

This Page