elektronn2.neuromancer.graphutils module

class elektronn2.neuromancer.graphutils.TaggedShape(shape, tags, strides=None, mfp_offsets=None, fov=None)[source]

Bases: object

Object to manage shape and associated tags uniformly. The []-operator can be used get shape values by either index (int) or tag (str)

Parameters:
  • shape (list/tuple of int) – shape of array, unspecified shapes are None
  • tags (list/tuple of strings or comma-separated string) – tags indicate which purpose the dimensions of the tensor serve. They are sometimes used to decide about reshapes. The maximal tensor has tags: “r, b, s, f, z, y, x, s” which denote: * r: perform recurrence along this axis * b: batch size * s: samples of the same instance (over which expectations are calculated) * f: features, filters, channels * z: convolution no. 3 (slower than 1,2) * y: convolution no. 1 * x: convolution no. 2
  • strides – list of strides, only for spatial dimensions, so it is 1-3 long
  • mfp_offsets
addaxis(axis, size, tag)[source]

Create new TaggedShape with new axis inserted at axis of size size tagged tag. If axis is a tag, the new axis is right of that tag

copy()[source]
delaxis(axis)[source]

Create new TaggedShape with new axis inserted at axis of size size tagged tag. If axis is a tag, the new axis is right of that tag

ext_repr
fov
fov_all_centered
hastag(tag)[source]
mfp_offsets
ndim
offsets
shape
spatial_axes
spatial_shape
spatial_size
strides
stripbatch_prod

Calculate product excluding batch dimension

stripnone

Return the shape but with all None elements removed (e.g. if batch size is unspecified)

stripnone_prod

Return the product of the shape but with all None elements removed (e.g. if batch size is unspecified)

tag2index(target_tag)[source]

Finds the index of the desired tag

tags
updatefov(axis, new_fov)[source]

Create new TaggedShape with new_fov on axis. Axis is given as index of the spatial axes (not matching the absolute index of sh).

updatemfp_offsets(mfp_offsets)[source]
updateshape(axis, new_size, mode=None)[source]

Create new TaggedShape with new_size on axis . Modes for updating: None (override), 'add', 'mult'

updatestrides(strides)[source]
elektronn2.neuromancer.graphutils.as_floatX(x)[source]
class elektronn2.neuromancer.graphutils.make_func(tt_input, tt_output, updates=None, name='Unnamed Function', borrow_inp=False, borrow_out=False, profile_execution=False)[source]

Bases: object

Wrapper for compiled theano functions. Features:

  • The function is compiled on demand (i.e. no wait at initialisation)
  • Singleton return values are returned directly, multiple values as list
  • The last execution time can inspected in the attribute last_exec_time
  • Functions can be timed: profile_execution is an int that specifies the number of runs to average. The average time is printed then.
  • In/Out values can have a borrow flag which might overwrite the numpy arrays but might speed up execution (see theano doc)
compile(profile=False)[source]
elektronn2.neuromancer.graphutils.getinput_for_multioutput(outputs)[source]

For list of several output layers return a list of required input tensors (without duplicates) to compute these outputs.