elektronn2.neuromancer.computations module¶
-
elektronn2.neuromancer.computations.
apply_activation
(x, activation_func, b1=None)[source]¶ Return an activation function callable matching the name Allowed names: ‘relu’, ‘tanh’,’prelu’, ‘sigmoid’, ‘maxout <i>’, ‘lin’,’abs’,’soft+’, ‘elu’, ‘selu’.
Parameters: - x (T.Tensor) – Input tensor.
- activation_func (str) – Name of the activation function.
- b1 – Optional b1 parameter for the activation function. If this is None, no parameter is passed.
Returns: Activation function applied to
x
.Return type: T.Tensor
-
elektronn2.neuromancer.computations.
apply_except_axis
(x, axis, func)[source]¶ Apply a contraction function on all but one axis.
Parameters: - x (T.Tensor) – Input tensor.
- axis (int) – Axis to exclude on application.
- func (function) – A function with signature
func(x, axis=)
eg T.mean, T.std …
Returns: Contraction of
x
, but of the same dimensionality.Return type: T.Tensor
-
elektronn2.neuromancer.computations.
conv
(x, w, axis_order=None, conv_dim=None, x_shape=None, w_shape=None, border_mode='valid', stride=None)[source]¶ Apply appropriate convolution depending on input and filter dimensionality. If input
w_shape
is known, conv might be replaced by tensordotThere are static assumptions which axes are spatial.
Parameters: - x (T.Tensor) – Input data (mini-batch).Tensor of shape
(b, f, x)
,(b, f, x, y)
,(b, z, f, x, y)
or(b,f,x,y,z)
. - w (T.Tensor) – Set of convolution filter weights.Tensor of shape
(f_out, f_in, x)
,(f_out, f_in, x, y)
,(f_out, z, f_in, x, y)
or(f_out, f_in, x, y, z)
. - axis_order (str) – (only relevant for 3d)
'dnn'
(b,f,x,y(,z))
or'theano'
(b, z, f, x, y)
. - conv_dim (int) – Dimensionality of the applied convolution (not the absolute dim of the inputs).
- x_shape (tuple) – shape tuple (
TaggedShape
supported). - w_shape (tuple) – shape tuple, see
w
. - border_mode (str) –
'valid'
: only apply filter to complete patches of the image. Generates output of shape: image_shape -filter_shape + 1.'full'
zero-pads image to multiple of filter shape to generate output of shape: image_shape + filter_shape - 1.
- stride (tuple) – (tuple of len 2)Factor by which to subsample the output.
Returns: Set of feature maps generated by convolution.
Return type: T.Tensor
- x (T.Tensor) –
-
elektronn2.neuromancer.computations.
dot
(x, W, axis=1)[source]¶ Calculate a tensordot between 1 axis of
x
and the first axis ofW
.Requires
x.shape[axis]==W.shape[0]
. Identical to dot ifx
,W
2d andaxis==1
.Parameters: - x (T.Tensor) – Input tensor.
- W (T.Tensor) – Weight tensor, (f_in, f_out).
- axis (int) – Axis on
x
to apply dot.
Returns: x
with dot applied. The shape ofx
changes onaxis
ton_out
.Return type: T.Tensor
-
elektronn2.neuromancer.computations.
fragmentpool
(conv_out, pool, offsets, strides, spatial_axes, mode='max')[source]¶
-
elektronn2.neuromancer.computations.
fragments2dense
(fragments, offsets, strides, spatial_axes)[source]¶
-
elektronn2.neuromancer.computations.
maxout
(x, factor=2, axis=None)[source]¶ Maxpooling along the feature axis.
The feature count is reduces by
factor
.Parameters: - x (T.Tensor) – Input tensor (b, f, x, y), (b, z, f, x, y).
- factor (int) – Pooling factor.
- axis (int or None) – Feature axis of
x
(1 or 2). If None, 5d tensors get axis 2 and all others axis 1.
Returns: x
with pooling applied.Return type: T.Tensor
-
elektronn2.neuromancer.computations.
pooling
(x, pool, spatial_axes, mode='max', stride=None)[source]¶ Pooling along spatial axes of 3d and 2d tensors.
There are static assumptions which axes are spatial. The spatial axes must be divisible by the corresponding pooling factor, otherwise the computation might crash later.
Parameters: - x (T.Tensor) – Input tensor (b, f, x, y), (b, z, f, x, y).
- pool (tuple) – 2/3-tuple of pooling factors.
They refer to the spatial axes of
x
(x,y)/(z,x,y). - spatial_axes (tuple) –
- mode (str) –
Can be any of the modes supported by Theano’s dnn_pool(): (‘max’, ‘average_inc_pad’, ‘average_exc_pad’, ‘sum’).
’max’ (default): max-pooling ‘average’ or ‘average_inc_pad’: average-pooling ‘sum’: sum-pooling
- stride (tuple) –
Returns: x
with maxpooling applied. The spatial axes are decreased by the corresponding pooling factorsReturn type: T.Tensor
-
elektronn2.neuromancer.computations.
softmax
(x, axis=1, force_builtin=False)[source]¶ Calculate softmax (pseudo probabilities).
Parameters: - x (T.Tensor) – Input tensor.
- axis (int) – Axis on which to apply softmax.
- force_builtin (bool) – force usage of
theano.tensor.nnet.softmax
(more stable).
Returns: x
with softmax applied, same shape.Return type: T.Tensor
-
elektronn2.neuromancer.computations.
unpooling
(x, pool, spatial_axes)[source]¶ Symmetric unpooling with border: s_new = s*pool + pool-1.
Insert values strided, e.g for pool=3: 00x00x00x…00x00.
Parameters: - x (T.Tensor) – Input tensor.
- pool (int) – Unpooling factor.
- spatial_axes (list) – List of axes on which to perform unpooling.
Returns: x
with unpooling applied.Return type: T.Tensor
-
elektronn2.neuromancer.computations.
upconv
(x, w, stride, x_shape=None, w_shape=None, axis_order='dnn')[source]¶
-
elektronn2.neuromancer.computations.
upsampling
(x, pool, spatial_axes)[source]¶ Upsamling through repetition: s_new = s*p.
e.g for pool=3: aaabbbccc…
Parameters: - x (T.Tensor) – Input tensor.
- pool (int) – Upsampling factor.
- spatial_axes (list) – List of axes on which to perform upsampling.
Returns: x
with upsampling applied.Return type: T.Tensor