Core

Dense

layer eddl::Dense(layer parent, int ndim, bool use_bias = true, string name = "")

Regular densely-connected NN layer.

Parameters
  • parent – Parent layer

  • ndim – Positive integer, dimensionality of the output space

  • use_bias – Boolean, whether the layer uses a bias vector.

  • name – A name for the operation

Returns

Densely-connected NN layer

Example:

l = Dense(l, 1024);

Embedding

layer eddl::Embedding(layer parent, int vocsize, int length, int output_dim, bool mask_zeros = false, string name = "")

Turns positive integers (indexes) into dense vectors of fixed size. eg. [[4], [20]] -> [[0.25, 0.1], [0.6, -0.2]].

Parameters
  • parent – Parent layer

  • vocsize – Size of the vocabulary, i.e. maximum integer index + 1

  • output_dim – Dimension of the dense embedding

  • length – (1) Length of the sequence, to connect to Dense Layers no Recurrent

  • name – A name for the operation

Returns

The embedded input

Example:

l = Embedding(l, 2000, 1, 32);

Reshape

layer eddl::Reshape(layer parent, const vector<int> &shape, string name = "")

Reshapes an output to a certain shape.

Parameters
  • parent – Parent layer

  • shape – Target shape. Vector of integers. Does not include the batch axis

  • name – A name for the operation

Returns

Output of reshape operation

Example:

l = Reshape(l,{1,28,28});

// Reshape to 1D tensor:
l = Reshape(l,{-1});

Flatten

Transforms the input tensor into a 1D-tensor. Alias for Reshape(l, {-1}).

layer eddl::Flatten(layer parent, string name = "")

Flattens the input. Does not affect the batch size.

Parameters
  • parent – Parent layer

  • name – A name for the operation

Returns

Output of reshape operation

Example:

l = Flatten(l);

Squeeze

layer eddl::Squeeze(layer parent, int axis = -1, string name = "")

Dimension of size one is removed at the specified position. (Batch dimension is ignored)

Parameters
  • parent – Parent layer

  • axis – if given, the input will be squeezed only in this dimension. Else (-1), squeezes all

  • name – A name for the operation

Returns

Output of reshape operation

Example:

// Squeeze all dimensions (ignoring batch)
l = Squeeze(l, -1);  // ([B,] 32, 1, 5, 1) => ([B,] 32, 5)

// Squeeze specific dimension (ignoring batch)
l = Squeeze(l, 3);  // ([B,] 32, 1, 5, 1) => ([B,] 32, 1, 5)

Unsqueeze

layer eddl::Unsqueeze(layer parent, int axis = 0, string name = "")

Dimension of size one is inserted at the specified position. (Batch dimension is ignored)

Parameters
  • parent – Parent layer

  • axis – if given, the input will be unsqueezed only in this dimension

  • name – A name for the operation

Returns

Output of reshape operation

Example:

// Unsqueeze dimension (ignoring batch)
l = Unsqueeze(l, 0);  // ([B,] 5) => ([B,] 1, 5)

// Unsqueeze dimension (ignoring batch)
l = Unsqueeze(l, 1);  // ([B,] 5) => ([B,] 5, 1)

Input

layer eddl::Input(const vector<int> &shape, string name = "")

Used to initialize an input to a model.

Parameters
  • shape – A shape vector (integer), not including the batch size. For instance, shape=(32,) indicates that the expected input will be batches of 32-dimensional vectors

  • name – A name for the operation

Returns

Input layer

Example:

layer in = Input({784});

Dropout

layer eddl::Dropout(layer parent, float rate, bool iw = true, string name = "")

Applies Dropout to a layer.

Dropout consists in randomly setting a fraction rate of input units to 0 at each update during training time, which helps prevent overfitting.

Parameters
  • parent – Parent layer

  • rate – Between 0 and 1. Fraction of the input units to drop

  • iw – perform weighting in inference (boolean, true)

  • name – A name for the operation

Returns

Layer with Dropout

Example:

l = Dropout(l, 0.3);

Select

Selects a subset of the output tensor using indices (similar to Numpy; the batch is ignored)

layer eddl::Select(layer l, vector<string> indices, string name = "")

Returns a new layer which indexes the input tensor using the entries in indices.

Parameters
  • l – Parent layer

  • indices – Vector of indices to be selected

  • name – A name for the operation

Returns

A tensor with the selected elements

Example:

l = Select(l, {"-1", "20:100", "50:-10", ":"});

Slice

Alias for Select Selects a subset of the output tensor using indices (similar to Numpy; the batch is ignored)

layer eddl::Slice(layer l, vector<string> indices, string name = "")

Returns a new layer which indexes the input tensor using the entries in indices. (alias for Select) Alias for Select.

Parameters
  • l – Parent layer

  • indices – Vector of indices to be selected

  • name – A name for the operation

Returns

A tensor with the selected elements

Example:

l = Slice(l, {"-1", "20:100", "50:-10", ":"});

Expand

Returns a layer with singleton dimensions expanded to a larger size.

layer eddl::Expand(layer l, int size, string name = "")

Returns a layer with singleton dimensions expanded to a larger size.

Parameters
  • l – Parent layer

  • size – Size to which expand the singleton dimensions

  • name – A name for the operation

Returns

A tensor with the selected elements

Example:

 // {3, 1, 5, 1, 5} and size=100 => {3, 100, 5, 100, 5}
l = Expand(l, 100);

Split

Split a tensor (layer) into a list of tensors (layers). (The batch is ignored). The indexes mark the split points.

vlayer eddl::Split(layer l, vector<int> indexes, int axis = -1, bool merge_sublayers = false, string name = "")

Split a layer into a list of tensors layers.

Parameters
  • l – Parent layer

  • indexes – Split indexes ({20, 60} => {0:20, 20:60, 60:end})

  • axis – Which axis to split on (default=-1, last)

  • merge_sublayers – Merge layers symbolically (for the plot)

  • name – A name for the operation

Returns

vector of layers

Example:

 // e.g.: l=> Output shape: {B, 3, 32, 32}
 // vl: {l1, l2, l3}; l1= {B, :1, 32, 32}, l2= {B, 1:2, 32, 32}, l3= {B, 2:, 32, 32}
vector<layer> vl = Split(l, {1,2}, 0);

Permute

Permute the axes of the output tensor (the batch is ignored)

layer eddl::Permute(layer l, vector<int> dims, string name = "")

Permutes the dimensions of the input according to a given pattern.

Parameters
  • l – Parent layer

  • dims – Permutation pattern, does not include the samples dimension.

  • name – A name for the operation

Returns

The permuted tensor.

Example:

l = Permute(l, {0, 2, 1});

Transpose

Permute the last two axes of the output tensor. Alias for Permute(l, {0, 2, 1}).

layer eddl::Transpose(layer parent, string name = "")

Transposes a Layer.

Parameters
  • parent – Parent layer

  • name – A name for the operation

Returns

Output of transpose operation

Example:

l = Transpose(l);

Resize

Same as Scale but with support for backward operation.

layer eddl::Resize(layer parent, vector<int> new_shape, bool reshape = true, string da_mode = "constant", float constant = 0.0f, string coordinate_transformation_mode = "asymmetric", string name = "")

Resize the input image to the given size. [height, width]. Same as the Scale layer, but with the backward operation supported.

Parameters
  • parent – Parent layer

  • new_shape – Vector with layer/images desired new shape

  • reshape – If True, the output shape will be new_shape (classical scale; recommended). If False, the output shape will be the input shape (scale<100%: scale + padding; scale >100%: crop + scale)

  • da_mode – One of “nearest”, “constant”, (ToDo: “mirror”, “reflect”, “wrap”, “original”)

  • constant – Fill value for area outside the resized image, it is used for all channels respectively

  • coordinate_transformation_mode – This attribute describes how to transform the coordinate in the resized tensor to the coordinate in the original tensor.

Returns

Output of scale transformation

Example:

l = Resize(l, {35, 35});

Repeat

layer eddl::Repeat(layer parent, const vector<unsigned int> &repeats, unsigned int axis, string name = "")

Repeats the elements of a tensor (layer’s output) along the specified dimension.

Parameters
  • parent – Parent layer

  • repeats – The number of repetitions for the specified dimension (“int” or “vector of ints”)

  • axis – The axis along which to repeat values. (Batch is ignored)

Returns

Output of repeat operation

layer eddl::Repeat(layer parent, unsigned int repeats, unsigned int axis, string name)

Example:

// Example #1:
l = Repeat(l, 3, 1);  // Repeat depth (axis=3) 3 times
l = Repeat(l, {3, 2, 1}, 1);  // Repeat col 1 => 3 times; col 2 => 2 times; col 3 => 1 time. (repeat=[3,2,1], axis=1)

// Example #2:
l = Reshape(l,{1,28,28});
l = Repeat(l, 3, 0);  // l => (3, 28, 28)

Tile

layer eddl::Tile(layer parent, const vector<int> &repeats, string name = "")

Constructs a tensor by repeating the elements of input. The repeats argument specifies the number of repetitions in each dimension.

Parameters
  • parent – Parent layer

  • repeats – The number of repetitions per dimension.

Returns

Output of repeat operation

Example:

l = Reshape(l,{1,28,28});
l = Tile(l, {3, 1, 1});  // l => (3, 28, 28)

Broadcasting

layer eddl::Broadcast(layer parent1, layer parent2, string name = "")

Prepares the output of the smaller layer to be broadcasted into the bigger one (parent1 or parent2) Example:

  • f(P1(3), P2(4,2,3,5)) => P1 is x. (P2 has no delta)

  • f(P1(4,2,3,5), P2(3)) => P2 is x. (P1 has no delta)

Parameters
  • parent1 – Parent layer

  • parent2 – Parent layer

Returns

Output of repeat operation

Example:

// Normalize: (X-mean) / std
layer mean = ConstOfTensor(new Tensor( {0.485, 0.456, 0.406}, {3}, DEV_CPU));
layer std = ConstOfTensor(new Tensor( {0.229, 0.224, 0.225}, {3}, DEV_CPU));
x = Sub(x, Broadcast(mean, x));
x = Div(x, Broadcast(std, x));