ReplicateLayer

ReplicateLayer[n]

represents a net layer that takes an input of dimensions {d1,d2,} and replicates it n times to produce an output of dimensions {n,d1,d2,}.

ReplicateLayer[{n1,n2,,nm}]

represents a net layer that takes an input of dimensions {d1,d2,} and replicates it to produce an output of dimensions {n1,n2,,nm,d1,d2,}.

ReplicateLayer[dims,m]

replicates so that dims appears at position m in the list of output dimensions.

Details and Options

  • ReplicateLayer[n] is equivalent to ReplicateLayer[n,1].
  • For ReplicateLayer[n], the rank of the output array is one larger than the rank of the input array.
  • For ReplicateLayer[{n1,,nm}], the rank of the output array is m larger than the rank of the input array.
  • Any of the n or ni can have the value Automatic, leaving the exact output dimension to be inferred from its context in NetChain etc.
  • ReplicateLayer[][input] explicitly computes the output from applying the layer to input.
  • ReplicateLayer[][{input1,input2,}] explicitly computes outputs for each of the inputi.
  • When given a NumericArray as input, the output will be a NumericArray.
  • ReplicateLayer exposes the following ports for use in NetGraph etc.:
  • "Input"an array of arbitrary rank
    "Output"an array of greater rank than the input
  • ReplicateLayer is typically used inside NetChain, NetGraph, etc.
  • ReplicateLayer normally infers the dimensions of its input from its context in NetChain etc. To specify the dimensions explicitly as {n1,n2,}, use ReplicateLayer["Input"->{n1,n2,}].
  • Options[ReplicateLayer] gives the list of default options to construct the layer. Options[ReplicateLayer[]] gives the list of default options to evaluate the layer on some data.
  • Information[ReplicateLayer[]] gives a report about the layer.
  • Information[ReplicateLayer[],prop] gives the value of the property prop of ReplicateLayer[]. Possible properties are the same as for NetGraph.

Examples

open allclose all

Basic Examples  (2)

Create a ReplicateLayer that replicates its input 4 times:

Create a ReplicateLayer that replicates its input 3 times:

Apply the layer to data:

Scope  (6)

Create a ReplicateLayer that replicates its input 3×4 times:

Apply the layer to a vector:

Create a ReplicateLayer that takes an input of specific size:

Apply the layer to an input:

Create a ReplicateLayer that replicates the elements of a vector into rows of length 3:

Apply the layer to an input:

The elements can be replicated into columns instead:

Create a NetGraph containing a ReplicateLayer that automatically broadcasts a vector to a matrix of given size:

This NetGraph is now valid for multiple input dimensions:

Create a ReplicateLayer that replicates a single number to form a vector:

Apply the layer to a number:

The layer threads across a batch of inputs:

Create a NetChain that makes four copies of an image by replicating and then flattening both spatial dimensions in turn:

Possible Issues  (2)

ReplicateLayer cannot accept non-numeric inputs:

ReplicateLayer[dims,pos] will fail when pos is more than one greater than the rank of the input:

Introduced in 2017
 (11.1)
 |
Updated in 2017
 (11.2)