Previous topic

models.viz2.layer_mapping

Next topic

models.viz2.ops

This Page

models.viz2.model

class glimpse.models.viz2.model.Layer
static AllLayers()

Return the unordered set of all layers.

static FromId(id)

Lookup a LayerSpec object by ID.

static FromName(name)

Lookup a LayerSpec object by name.

SOURCE = LayerSpec(id=s, name=source, depends=[])

Specifier for the source of the image data. This may be None if the data was generated programatically, or an InputSource object if the data came from an image file.

IMAGE = LayerSpec(id=i, name=image, depends=[source])

Specifier for the raw input data.

S1 = LayerSpec(id=s1, name=S1, depends=[retina])

Specifier for the result of S1 filtering.

C1 = LayerSpec(id=c1, name=C1, depends=[S1])

Specifier for the result of C1 pooling.

S2 = LayerSpec(id=s2, name=S2, depends=[C1])

Specifier for the result of S2 filtering.

C2 = LayerSpec(id=c2, name=C2, depends=[S2])

Specifier for the result of C2 (local) pooling.

IT = LayerSpec(id=it, name=IT, depends=[C2])

Specifier for the result of IT (global) pooling.

class glimpse.models.viz2.model.State

A dictionary container for the Model state.

The main purpose of extending the dictionary (instead of just storing states as dictionary objects) is to indicate with which model a given state is associated. Similarly, each model has a seperate state object, so it is always clear which model generated a given state object.

ModelClass

The datatype associated with the model for this state.

alias of Model

class glimpse.models.viz2.model.Model(backend=None, params=None)

Bases: glimpse.models.viz2.ops.ModelOps, glimpse.models.misc.AbstractNetwork

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

This module implements the “Viz2” model used for the GCNC 2011 experiments.

BuildC1FromS1(s1s)

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

Parameters:s1s (4D ndarray of float) – S1 activity for each scale.
Returns:C1 activity, with one array per scale.
Return type:list of 3D ndarray of float
BuildC2FromS2(s2s)

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

Parameters:s2s – S2 activity
Type :s2s: 4D array
Returns:C2 activity for each scale and prototype
Return type:2D ndarray of float
BuildImageFromInput(input_)

Create the initial image layer from some input.

Parameters:input (PIL.Image or 2D ndarray) – Input data. If array, values should lie in the range [0, 1].
Returns:image layer data
Return type:2D ndarray of float
BuildItFromC2(c2s)

Compute the IT layer activity from multi-scale C2 activity.

Parameters:c2s (2D ndarray of float) – C2 activity
Returns:IT activity for each prototype
Return type:1D ndarray of float
BuildLayer(output_layer, state, save_all=True)

Apply the model through to the given layer.

Parameters:
  • output_layer (LayerSpec or scalar (layer ID)) – Output layer to compute.
  • state (State) – Initial model state from which to compute the output layer.
  • save_all (bool) – Whether the resulting state should contain values for all computed layers in the network, or just the output layer.
Returns:

Output state containing the given layer

Return type:

State

BuildLayerCallback(output_layer, save_all=True)

Create a function that will apply the model through to the given layer.

Parameters:
  • output_layer (LayerSpec or scalar (layer id)) – Output layer to compute.
  • state (State) – Initial model state from which to compute the output layer.
  • save_all (bool) – Whether the resulting state should contain values for all computed layers in the network, or just the output layer.
Returns:

A callable object that, when evaluated, will apply the model.

Return type:

LayerBuilder

BuildNode(output_id, state)

Construct the given output value.

The output value is built by recursively building required dependencies. A node is considered to be built if the node’s key is set in the state dictionary, even if the corresponding value is None.

Parameters:
  • output_id – Unique identifier for the node to compute.
  • state (dict) – Current state of the network, which may be used to store the updated network state.
Returns:

The final state of the network, which is guaranteed to contain a value for the output node.

Return type:

dict

BuildRetinaFromImage(img)

Compute retinal layer activity from the input image.

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

Apply S1 processing to some existing retinal layer data.

Note

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

Parameters:retina (2D ndarray of float) – Result of retinal layer processing.
Return type:4D ndarray of float
BuildS2FromC1(c1s)

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

Parameters:c1s (4D ndarray of float, or list of 3D ndarray of float) – C1 activity
Returns:S2 activity for each scale
Return type:4D ndarray of float
BuildSingleNode(output_id, state)

Compute activity for a single model layer.

This method is called by BuildNode().

Parameters:
  • output_id (LayerSpec) – Layer to compute.
  • state (State) – Model state from which to compute given layer.
Returns:

Activity for given output layer.

Return type:

ndarray

GetDependencies(output_id)

Find the set of dependencies for a given model layer.

Return type:list of LayerSpec
ImprintS2Prototypes(num_prototypes, input_states, normalize=True, pool=None)

Imprint a set of S2 prototypes from a set of images.

Parameters:
  • num_prototypes (int) – Total number of prototypes to generate.
  • input_states (list of State) – initial network states from which to compute C1.
  • normalize (bool) – Whether each prototype is scaled to have unit norm.
  • pool – Worker pool used to evaluate the model.
Returns:

A numpy array of prototypes, and a list of prototype locations.

LayerClass

The datatype associated with layer descriptors for this model.

alias of Layer

MakeStateFromFilename(filename, resize=None)

Create a model state with a single SOURCE layer.

Parameters:
  • filename (str) – Path to an image file.
  • resize (int) – Scale minimum edge to fixed length.
Returns:

The new model state.

Return type:

State

MakeStateFromImage(image)

Create a model state with a single IMAGE layer.

Parameters:
  • image (PIL.Image or 2D ndarray) – Input data. If array, values should lie in the range [0, 1].
  • resize (int) – Scale minimum edge to fixed length.
Returns:

The new model state.

Return type:

State

ParamsClass

alias of Params

SampleC1Patches(num_patches, state, normalize=False)

Compute C1 activity and sample patches from random locations and scales.

Parameters:
  • num_patches (int) – Number of patches to extract.
  • normalize (bool) – Whether to normalize each C1 patch.
Returns:

The set of patches

Return type:

list of (patch, location) pairs

SampleC1PatchesCallback(num_patches, normalize=False)

Create a function that will sample patches from random locations and scales.

Parameters:
  • num_patches (int) – Number of patches to extract.
  • normalize (bool) – Whether to normalize each C1 patch.
Returns:

A callable object that, when evaluated, will sample patches

Return type:

C1PatchSampler

StateClass

The datatype associated with network states for this model.

alias of State

s1_kernel_shape

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

Return type:tuple of int
s1_kernels

The S1 kernels array, which are generated if not set.

s2_kernel_shape

The expected shape of a single S2 kernel, without band structure.

Return type:tuple of int
s2_kernels

The S2 kernels array.

class glimpse.models.viz2.model.LayerBuilder(model, output_layer_id, save_all=True)

Represents a serializable function.

This function computes a network state transformation, computing the value of some network layer and any required dependencies.

__call__(state)

Transform between network states.

__init__(model, output_layer_id, save_all=True)

Create a new object.

Parameters:
  • model (Model) – The model to use when computing layer activity.
  • output_layer_id (LayerSpec or scalar (layer id)) – Highest layer in model to compute.
  • save_all (bool) – Whether the resulting state should contain values for all computed layers in the network, or just the output layer.
class glimpse.models.viz2.model.C1PatchSampler(model, num_patches, normalize=False)

Represents a serializable function.

This function computes a network state transformation for feedforward S->C layer networks. This function computes C1 activity and then extracts patches from randomly-sampled locations and scales.

__call__(state)

Transform an input model state to a set of C1 patches.

Parameters:state (State) – Input model state.
Returns:list of (patch, sample location) pairs
__init__(model, num_patches, normalize=False)

Create new object.

Parameters:
  • model – Viz2 model instantiation to use when computing C1 activity.
  • num_patches (int) – Number of patches to extract.
  • normalize (bool) – Whether to normalize each C1 patch.
Type :

model: Model