Bases: glimpse.util.dataflow.node.Node
Describes a single layer in a model.
(str) Name of model layer.
Bases: glimpse.models.base.layer.Layer
Return the unordered set of all layers.
Return type: | list of LayerSpec |
---|
Example:
>>> assert(Layer.IMAGE in Layer.AllLayers())
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)
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)
Determine if one layer appears later in the network than another.
Parameters: | |
---|---|
Return type: | bool |
Examples:
>>> assert(Layer.IsSublayer(Layer.SOURCE, Layer.IMAGE))
>>> assert(not Layer.IsSublayer(Layer.IMAGE, Layer.SOURCE))
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)
Specifier for the raw input data.
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.
Bases: glimpse.util.dataflow.state.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. Each model has a seperate state object, so it is always clear which model generated a given state object.
Bases: glimpse.util.dataflow.dataflow.DataFlow
Abstract base class for a Glimpse model.
The datatype associated with layer descriptors for this model. This should be over-ridden by the sub-class with a descendent of layer.Layer.
alias of Layer
The type of the parameter collection associated with this model. This should be over-ridden by the sub-class.
alias of Params
The datatype associated with network states for this model. This should be over-ridden by the sub-class, and should generally be a descendent of state.State.
alias of State
Create a model state wrapper for the given image source.
Parameters: |
|
---|---|
Return type: | state.State subclass |
If source is an array, values should lie in the range [0,1).
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.
Parameter container for the model.Model.
Prepare an image for input into the model.
Parameters: |
|
---|---|
Returns: | Image layer data with values in the range [0, 1]. |
Return type: | 2D ndarray of float |
The image may be scaled and/or cropped, depending on the settings of the image_resize_method attribute of the params argument. If the value is NONE, the image is returned unchanged. Given a value of SCALE_SHORT_EDGE, SCALE_LONG_EDGE, SCALE_WIDTH, or SCALE_HEIGHT, the given image edge will be rescaled to match params.image_resize_length (preserving the aspect ratio).
Finally, the image_resize_method attribute could be SCALE_AND_CROP. In this case, the image is scaled and cropped to a fixed size of (w, w/rho), where w is image_resize_length and rho is image_resize_aspect_ratio. This is achieved scaling the short edge (preserving aspect ratio) and then cropping from the long edge.
See also ScaleImage() and ScaleAndCropImage().
Apply the model through to the given layer.
Parameters: |
|
---|---|
Returns: | Output state containing the given layer |
Return type: | StateClass |
Examples:
Get the IMAGE layer for an image.
>>> model = Model()
>>> input_state = model.MakeState(glab.GetExampleImage())
>>> output_state = BuildLayer(model, Layer.IMAGE, input_state)
>>> assert(Layer.IMAGE in output_state)
Extract patches from the given layer for a single image.
Patches are sampled from random locations and scales.
Parameters: |
|
---|---|
Returns: | list of (patch, location) pairs. The location is a triple, whose axes correspond to the scale, y-offset, and x-offset of the patch’s top-left corner. |
Return type: | list of (patch, location) pairs |
See also SamplePatchesFromData().
Sample patches from a layer of activity.
Parameters: |
|
---|---|
Return type: | pair of arrays |
Returns: | Array of patches and array of corresponding locations (elements are 3-tuples). Location given as (s, y, x), where s is scale, and (y, x) gives the top-left corner of the region. |
Each location (s, y, x) is guaranteed to lie in
0 <= s < S
0 <= y < H - patch_width
0 <= x < W - patch_width
where S is the number of scales in data, and H and W give its spatial height and width, respectively.
Throws InputSizeError if the input is (spatially) smaller than patch_width.
Examples:
Extract 50 patches of size 10x10 from a stack of 2D arrays:
>>> shape = (4, 100, 100)
>>> data = numpy.random.random(shape)
>>> patches, locs = SamplePatchesFromData(data, patch_width = 10, 50)