tensorflow.js lambda layer written by twitter.com/benjaminwegener license: MIT

see

  https://benjamin-wegener.blogspot.com/2020/02/tensorflowjs-lambda-layer.html

### Hierarchy

- Layer
  - LambdaLayer

## Index

### Constructors

- constructor

### Properties

- _refCount
- _stateful
- _trainableWeights
- activityRegularizer
- batchInputShape
- built
- dtype
- id
- inboundNodes
- initialWeights
- input
- inputSpec
- lambdaFunction
- lambdaOutputShape
- losses
- name
- nonTrainableWeights
- outboundNodes
- output
- outputShape
- stateful
- supportsMasking
- trainable
- trainableWeights
- trainable_
- updates
- weights

### Accessors

- className

### Methods

- addLoss
- addWeight
- apply
- assertInputCompatibility
- assertNotDisposed
- build
- calculateLosses
- call
- clearCallHook
- computeMask
- computeOutputShape
- countParams
- dispose
- disposeWeights
- getClassName
- getConfig
- getInputAt
- getOutputAt
- getWeights
- invokeCallHook
- resetStates
- setCallHook
- setFastWeightInitDuringBuild
- setWeights
- warnOnIncompatibleInputShape
- fromConfig
- nodeKey

## Constructors

### constructor

- new LambdaLayer(config: LambdaLayerOptions): LambdaLayer

- Overrides Layer.__constructor

  - Defined in src/model_interface.ts:155

  #### Parameters

  - ##### config: LambdaLayerOptions

  #### Returns LambdaLayer

## Properties

### Protected _refCount

_refCount: number | null

Inherited from LambdaLayer._refCount

- Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:304

### Protected _stateful

_stateful: boolean

Inherited from LambdaLayer._stateful

- Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:303

### Protected _trainableWeights

_trainableWeights: LayerVariable[]

Inherited from LambdaLayer._trainableWeights

- Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:295

### activityRegularizer

activityRegularizer: Regularizer

Inherited from LambdaLayer.activityRegularizer

- Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:294

### batchInputShape

batchInputShape: Shape

Inherited from LambdaLayer.batchInputShape

- Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:289

### built

built: boolean

Inherited from LambdaLayer.built

- Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:377

### dtype

dtype: DataType

Inherited from LambdaLayer.dtype

- Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:290

### id

id: number

Inherited from LambdaLayer.id

- Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:302

### inboundNodes

inboundNodes: Node[]

Inherited from LambdaLayer.inboundNodes

- Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:292

### initialWeights

initialWeights: Tensor[]

Inherited from LambdaLayer.initialWeights

- Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:291

### input

input: SymbolicTensor | SymbolicTensor[]

Inherited from LambdaLayer.input

- Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:356

Retrieves the input tensor(s) of a layer.

Only applicable if the layer has exactly one inbound node, i.e. if it is connected to one incoming layer.

returns

  Input tensor or list of input tensors.

exception

  AttributeError if the layer is connected to more than one incoming layers.

### inputSpec

inputSpec: InputSpec[]

Inherited from LambdaLayer.inputSpec

- Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:285

List of InputSpec class instances.

Each entry describes one required input:

- ndim
- dtype A layer with `n` input tensors must have an `inputSpec` of length `n`.

### lambdaFunction

lambdaFunction: string

- Defined in src/model_interface.ts:153

### lambdaOutputShape

lambdaOutputShape: TFShape | Matrix | Vector

- Defined in src/model_interface.ts:155

### losses

losses: RegularizerFn[]

Inherited from LambdaLayer.losses

- Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:369

### name

name: string

Overrides Layer.name

- Defined in src/model_interface.ts:152

### nonTrainableWeights

nonTrainableWeights: LayerVariable[]

Inherited from LambdaLayer.nonTrainableWeights

- Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:380

### outboundNodes

outboundNodes: Node[]

Inherited from LambdaLayer.outboundNodes

- Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:293

### output

output: SymbolicTensor | SymbolicTensor[]

Inherited from LambdaLayer.output

- Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:368

Retrieves the output tensor(s) of a layer.

Only applicable if the layer has exactly one inbound node, i.e. if it is connected to one incoming layer.

returns

  Output tensor or list of output tensors.

exception

  AttributeError if the layer is connected to more than one incoming layers.

### outputShape

outputShape: Shape | Shape[]

Inherited from LambdaLayer.outputShape

- Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:516

doc

  {heading: 'Models', 'subheading': 'Classes'}

### stateful

stateful: boolean

Inherited from LambdaLayer.stateful

- Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:386

### supportsMasking

supportsMasking: boolean

Inherited from LambdaLayer.supportsMasking

- Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:286

### trainable

trainable: boolean

Inherited from LambdaLayer.trainable

- Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:378

### trainableWeights

trainableWeights: LayerVariable[]

Inherited from LambdaLayer.trainableWeights

- Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:379

### Protected trainable_

trainable_: boolean

Inherited from LambdaLayer.trainable_

- Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:288

Whether the layer weights will be updated during training.

### updates

updates: Tensor[]

Inherited from LambdaLayer.updates

- Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:376

### weights

weights: LayerVariable[]

Inherited from LambdaLayer.weights

- Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:385

The concatenation of the lists trainableWeights and nonTrainableWeights (in this order).

## Accessors

### Static className

- get className(): string

- - Defined in src/model_interface.ts:199

  #### Returns string

## Methods

### addLoss

- addLoss(losses: RegularizerFn | RegularizerFn[]): void

- Inherited from LambdaLayer.addLoss

  - Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:591
  doc

    {heading: 'Models', 'subheading': 'Classes'}

  #### Parameters

  - ##### losses: RegularizerFn | RegularizerFn[]

  #### Returns void

### Protected addWeight

- addWeight(name: string, shape: Shape, dtype?: DataType, initializer?: Initializer, regularizer?: Regularizer, trainable?: undefined | false | true, constraint?: Constraint): LayerVariable

- Inherited from LambdaLayer.addWeight

  - Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:572
  doc

    {heading: 'Models', 'subheading': 'Classes'}

  #### Parameters

  - ##### name: string

  - ##### shape: Shape

  - ##### Optional dtype: DataType

  - ##### Optional initializer: Initializer

  - ##### Optional regularizer: Regularizer

  - ##### Optional trainable: undefined | false | true

  - ##### Optional constraint: Constraint

  #### Returns LayerVariable

### apply

- apply(inputs: Tensor | Tensor[] | SymbolicTensor | SymbolicTensor[], kwargs?: Kwargs): Tensor | Tensor[] | SymbolicTensor | SymbolicTensor[]

- Inherited from LambdaLayer.apply

  - Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:496
  doc

    {heading: 'Models', 'subheading': 'Classes'}

  #### Parameters

  - ##### inputs: Tensor | Tensor[] | SymbolicTensor | SymbolicTensor[]

  - ##### Optional kwargs: Kwargs

  #### Returns Tensor | Tensor[] | SymbolicTensor | SymbolicTensor[]

### Protected assertInputCompatibility

- assertInputCompatibility(inputs: Tensor | Tensor[] | SymbolicTensor | SymbolicTensor[]): void

- Inherited from LambdaLayer.assertInputCompatibility

  - Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:407

  Checks compatibility between the layer and provided inputs.

  This checks that the tensor(s) `input` verify the input assumptions of the layer (if any). If not, exceptions are raised.

  exception

    ValueError in case of mismatch between the provided inputs and the expectations of the layer.

  #### Parameters

  - ##### inputs: Tensor | Tensor[] | SymbolicTensor | SymbolicTensor[]

    Input tensor or list of input tensors.

  #### Returns void

### Protected assertNotDisposed

- assertNotDisposed(): void

- Inherited from LambdaLayer.assertNotDisposed

  - Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:653

  #### Returns void

### build

- build(inputShape: Shape | Shape[]): void

- Inherited from LambdaLayer.build

  - Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:537
  doc

    {heading: 'Models', 'subheading': 'Classes'}

  #### Parameters

  - ##### inputShape: Shape | Shape[]

  #### Returns void

### calculateLosses

- calculateLosses(): Scalar[]

- Inherited from LambdaLayer.calculateLosses

  - Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:375

  Retrieves the Layer's current loss values.

  Used for regularizers during training.

  #### Returns Scalar[]

### call

- call(input: Tensor<Rank> | Tensor<Rank>[], kwargs?: any): Tensor<Rank> | Tensor<Rank>[]

- Overrides Layer.call

  - Defined in src/model_interface.ts:166

  #### Parameters

  - ##### input: Tensor<Rank> | Tensor<Rank>[]

  - ##### Optional kwargs: any

  #### Returns Tensor<Rank> | Tensor<Rank>[]

### clearCallHook

- clearCallHook(): void

- Inherited from LambdaLayer.clearCallHook

  - Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:428

  Clear call hook. This is currently used for testing only.

  #### Returns void

### computeMask

- computeMask(inputs: Tensor | Tensor[], mask?: Tensor | Tensor[]): Tensor | Tensor[]

- Inherited from LambdaLayer.computeMask

  - Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:612

  Computes an output mask tensor.

  #### Parameters

  - ##### inputs: Tensor | Tensor[]

    Tensor or list of tensors.

  - ##### Optional mask: Tensor | Tensor[]

    Tensor or list of tensors.

  #### Returns Tensor | Tensor[]

  null or a tensor (or list of tensors, one per output tensor of the layer).

### computeOutputShape

- computeOutputShape(inputShape: Matrix): (null | number)[] | number[][]

- Overrides Layer.computeOutputShape

  - Defined in src/model_interface.ts:181

  #### Parameters

  - ##### inputShape: Matrix

  #### Returns (null | number)[] | number[][]

### countParams

- countParams(): number

- Inherited from LambdaLayer.countParams

  - Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:526
  doc

    {heading: 'Models', 'subheading': 'Classes'}

  #### Returns number

### dispose

- dispose(): DisposeResult

- Inherited from LambdaLayer.dispose

  - Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:683
  doc

    {heading: 'Models', 'subheading': 'Classes'}

  #### Returns DisposeResult

### Protected disposeWeights

- disposeWeights(): number

- Inherited from LambdaLayer.disposeWeights

  - Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:652

  Dispose the weight variables that this Layer instance holds.

  #### Returns number

  Number of disposed variables.

### getClassName

- getClassName(): string

- Inherited from LambdaLayer.getClassName

  - Defined in node_modules/@tensorflow/tfjs-core/dist/serialization.d.ts:70

  Return the class name for this class to use in serialization contexts.

  Generally speaking this will be the same thing that constructor.name would have returned. However, the class name needs to be robust against minification for serialization/deserialization to work properly.

  There's also places such as initializers.VarianceScaling, where implementation details between different languages led to different class hierarchies and a non-leaf node is used for serialization purposes.

  #### Returns string

### getConfig

- getConfig(): { lambdaFunction: string; lambdaOutputShape: (null | number)[] | number[][] | number[] }

- Overrides Layer.getConfig

  - Defined in src/model_interface.ts:190

  #### Returns { lambdaFunction: string; lambdaOutputShape: (null | number)[] | number[][] | number[] }

  - ##### lambdaFunction: string

  - ##### lambdaOutputShape: (null | number)[] | number[][] | number[]

### getInputAt

- getInputAt(nodeIndex: number): SymbolicTensor | SymbolicTensor[]

- Inherited from LambdaLayer.getInputAt

  - Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:334

  Retrieves the input tensor(s) of a layer at a given node.

  #### Parameters

  - ##### nodeIndex: number

    Integer, index of the node from which to retrieve the attribute. E.g. `nodeIndex=0` will correspond to the first time the layer was called.

  #### Returns SymbolicTensor | SymbolicTensor[]

  A tensor (or list of tensors if the layer has multiple inputs).

### getOutputAt

- getOutputAt(nodeIndex: number): SymbolicTensor | SymbolicTensor[]

- Inherited from LambdaLayer.getOutputAt

  - Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:344

  Retrieves the output tensor(s) of a layer at a given node.

  #### Parameters

  - ##### nodeIndex: number

    Integer, index of the node from which to retrieve the attribute. E.g. `nodeIndex=0` will correspond to the first time the layer was called.

  #### Returns SymbolicTensor | SymbolicTensor[]

  A tensor (or list of tensors if the layer has multiple outputs).

### getWeights

- getWeights(trainableOnly?: undefined | false | true): Tensor[]

- Inherited from LambdaLayer.getWeights

  - Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:545
  doc

    {heading: 'Models', 'subheading': 'Classes'}

  #### Parameters

  - ##### Optional trainableOnly: undefined | false | true

  #### Returns Tensor[]

### Protected invokeCallHook

- invokeCallHook(inputs: Tensor | Tensor[], kwargs: Kwargs): void

- Inherited from LambdaLayer.invokeCallHook

  - Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:417

  #### Parameters

  - ##### inputs: Tensor | Tensor[]

  - ##### kwargs: Kwargs

  #### Returns void

### resetStates

- resetStates(): void

- Inherited from LambdaLayer.resetStates

  - Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:394

  Reset the states of the layer.

  This method of the base Layer class is essentially a no-op. Subclasses that are stateful (e.g., stateful RNNs) should override this method.

  #### Returns void

### setCallHook

- setCallHook(callHook: CallHook): void

- Inherited from LambdaLayer.setCallHook

  - Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:423

  Set call hook. This is currently used for testing only.

  #### Parameters

  - ##### callHook: CallHook

  #### Returns void

### setFastWeightInitDuringBuild

- setFastWeightInitDuringBuild(value: boolean): void

- Inherited from LambdaLayer.setFastWeightInitDuringBuild

  - Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:583

  Set the fast-weight-initialization flag.

  In cases where the initialized weight values will be immediately overwritten by loaded weight values during model loading, setting the flag to `true` saves unnecessary calls to potentially expensive initializers and speeds up the loading process.

  #### Parameters

  - ##### value: boolean

    Target value of the flag.

  #### Returns void

### setWeights

- setWeights(weights: Tensor[]): void

- Inherited from LambdaLayer.setWeights

  - Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:557
  doc

    {heading: 'Models', 'subheading': 'Classes'}

  #### Parameters

  - ##### weights: Tensor[]

  #### Returns void

### Protected warnOnIncompatibleInputShape

- warnOnIncompatibleInputShape(inputShape: Shape): void

- Inherited from LambdaLayer.warnOnIncompatibleInputShape

  - Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:504

  Check compatibility between input shape and this layer's batchInputShape.

  Print warning if any incompatibility is found.

  #### Parameters

  - ##### inputShape: Shape

    Input shape to be checked.

  #### Returns void

### Static fromConfig

- fromConfig<T>(cls: SerializableConstructor<T>, config: ConfigDict): T

- Inherited from LambdaLayer.fromConfig

  - Defined in node_modules/@tensorflow/tfjs-core/dist/serialization.d.ts:84
  nocollapse

  #### Type parameters

  - #### T: Serializable

  #### Parameters

  - ##### cls: SerializableConstructor<T>

  - ##### config: ConfigDict

  #### Returns T

### Static Protected nodeKey

- nodeKey(layer: Layer, nodeIndex: number): string

- Inherited from LambdaLayer.nodeKey

  - Defined in node_modules/@tensorflow/tfjs-layers/dist/engine/topology.d.ts:316

  Converts a layer and its index to a unique (immutable type) name. This function is used internally with `this.containerNodes`.

  #### Parameters

  - ##### layer: Layer

    The layer.

  - ##### nodeIndex: number

    The layer's position (e.g. via enumerate) in a list of nodes.

  #### Returns string

  The unique name.