~/bend-docscommunity

tensor_layer.bend checks

raw source on the hub · import stelliferous@0.0.4.0/tensor_layer.bend as Tensor_layer

A convolution followed by an activation, as a training layer: forward keeps what backward reads, backward gives the gradients in a fixed FP32 order.

4 imports
import Base
import ./math_activation.bend as Activations
import ./tensor_f32.bend as F
import ./tensor_convolution_gradient.bend as Gradient

Types

type Settings source · line 11 · raw

Data

Definitions

def Tensor source · line 8 · raw

Type

def settings source · line 14 · raw

@stride:U32 -> @padding:U32 -> @activation:0xa2af805348d03b11eb853850859654f6/math_activation.Activation -> Settings

def Saved source · line 19 · raw

Type

The layer input and the convolution result before the activation. One backward call uses it.

def forward_activated source · line 22 · raw

@x:Tensor -> @weights:Tensor -> @bias:Tensor -> @pair:Pair(Tensor, Tensor) -> Pair(Tensor, Pair(Saved, Pair(Tensor, Tensor)))

def forward_copied source · line 26 · raw

@settings:Settings -> @xs:Pair(Tensor, Tensor) -> @ws:Pair(Tensor, Tensor) -> @bs:Pair(Tensor, Tensor) -> Pair(Tensor, Pair(Saved, Pair(Tensor, Tensor)))

def forward source · line 35 · raw

@x:Tensor -> @weights:Tensor -> @bias:Tensor -> @settings:Settings -> Pair(Tensor, Pair(Saved, Pair(Tensor, Tensor)))

x [N,C,H,W] or [C,H,W], weights [O,C,k,k] and bias [O]: (the activated output, (what backward reads, (weights, bias))).

def kernel source · line 38 · raw

@shape:List<&2, U32> -> U32

def Parameters source · line 45 · raw

Type

The gradients of the parameters with what the input gradient reads: (weight gradient, (bias gradient, (dz, (weights, the shape of x)))).

def biased source · line 48 · raw

@weight_gradient:Tensor -> @weights:Tensor -> @shape:List<&2, U32> -> @pair:Pair(Tensor, Tensor) -> Parameters

def measured source · line 52 · raw

@weight_gradient:Tensor -> @weights:Tensor -> @dz:Tensor -> @input:Pair(Tensor, List<&2, U32>) -> Parameters

def weighted source · line 56 · raw

@weights:Tensor -> @result:Pair(Tensor, Pair(Tensor, Tensor)) -> Parameters

def shaped source · line 60 · raw

@stride:U32 -> @padding:U32 -> @x:Tensor -> @dz:Tensor -> @measured:Pair(Tensor, List<&2, U32>) -> Parameters

def parameters source · line 65 · raw

@dy:Tensor -> @saved:Saved -> @weights:Tensor -> @settings:Settings -> Parameters

dz = dy * activation'(z), then the gradients of the weights and the bias.

def finished source · line 70 · raw

@weight_gradient:Tensor -> @bias_gradient:Tensor -> @pair:Pair(Tensor, Tensor) -> Pair(Tensor, Pair(Tensor, Pair(Tensor, Tensor)))

def image source · line 75 · raw

@shape:List<&2, U32> -> Pair(U32, U32)

The height and width of [N,C,H,W] or [C,H,W]; zero for another rank.

def sized source · line 81 · raw

@+stride:U32 -> @+padding:U32 -> @weight_gradient:Tensor -> @bias_gradient:Tensor -> @dz:Tensor -> @weights:Tensor -> @size:Pair(U32, U32) -> Pair(Tensor, Pair(Tensor, Pair(Tensor, Tensor)))

def propagated source · line 85 · raw

@+stride:U32 -> @+padding:U32 -> @result:Parameters -> Pair(Tensor, Pair(Tensor, Pair(Tensor, Tensor)))

def backward source · line 91 · raw

@dy:Tensor -> @saved:Saved -> @weights:Tensor -> @+settings:Settings -> Pair(Tensor, Pair(Tensor, Pair(Tensor, Tensor)))

dy, the gradient of the loss with respect to the layer output: (the gradient of the layer input, (weight gradient, (bias gradient, weights))).

def without_input source · line 95 · raw

@result:Parameters -> Pair(Tensor, Pair(Tensor, Tensor))

def backward_parameters source · line 101 · raw

@dy:Tensor -> @saved:Saved -> @weights:Tensor -> @settings:Settings -> Pair(Tensor, Pair(Tensor, Tensor))

backward for a layer whose input needs no gradient: (weight gradient, (bias gradient, weights)).