TensorSpace.js
Getting Start
Basic Concepts
Model Preprocessing
Models
Layers
Merge Function
Average
"Average" is constructed as a "factory" to complete the "average" operation. To apply the "Average" function, it is required that the shapes of all input layers are the same (otherwise, we can't perform the operation). The "factory" returns a merged layer instance as the output.
Factory style
layerAverageResult = TSP.layers.Average( [layer1, layer2, ...], { configs } )
The first parameter is a list of layer objects. (TensorSpace currently only supports "Average" operations for 3D vectors. We will introduce others soon.)
The second parameter is the configurations of the output merged layer object.
Fig. 1 - Average layer collapse and expand
Configuration

Name

Tag

Type

Instruction

Usage Notes and Examples

name

🔧

String Name of this layer. Highly recommend to arrange to make code more readable. name: "layerName"

color

⚙️🎨️

color format Color of layer Average default is red #E23E57

closeButton

⚙️🎨️

Dict Close button appearance control dict, more about close button

display : Boolean. true[default] Show button, false Hide button

ratio : Int. Times to normal size, default is 1

For example, 2 means twice the normal size

initStatus

⚙️️🎦

String Layer status at beginning. Open or Close close[default] : Closed at beginning

animation-
TimeRatio

⚙️🎦️

Int The speed of open and close animation Integer for multiple of speed. For example, 2 for 2 times of basic speed.
Properties
.outputShape : Int[]
filter_center_focusThe shape of the output tensor is 3-dimensional. 3️⃣
filter_center_focusThe dataFormat is "channel last". For example, outputShape = [ 32, 32, 4 ] represents the output through this layer has 4 feature maps and each one is 32 by 32.
filter_center_focusAfter model.init() data is available, otherwise is undefined.
.neuralValue : Int[]
filter_center_focusThe intermediate raw data after this layer.
filter_center_focusAfter load and model.init(), the data are available. Otherwise is undefined.
.name : String
filter_center_focusThe custom name for this layer.
filter_center_focusOnce created, you can get it.
.layerType : String
filter_center_focusType of this layer, return a constant: string Average1d, Average2d, Average3d. This type can identify the dimension of input layers
filter_center_focusOnce created, you can get it.
Method
filter_center_focusClick on the layer directly to open it by interacting directly with the object in the 3D scene.
filter_center_focusIn code, calling the method to open it.
let conv2d1 = new TSP.layers.Conv2d( {

    // configure some parameters for Conv2d1.

} );

model.add( conv2d1 );

let conv2d2 = new TSP.layers.Conv2d( {

    /*
     *  configure some parameters for Conv2d2.
     *  Note the shape of Conv2d2 should be the same as Conv2d1.
     */

} );

model.add( conv2d2 );

// perform merge

let mergedLayer = TSP.layers.Average( [ conv2d1, conv2d2 ], {

        /* Configurations */

    }

);

// add merged layer

model.add( mergedLayer );
model.init();

// call .openLayer() to expand the layer

mergedLayer.openLayer();
filter_center_focusTo close by interacting directly with objects in a 3D scene by clicking the close button.
filter_center_focus In code, calling the method to close it.
let conv2d1 = new TSP.layers.Conv2d( {

    // configure some parameters for Conv2d1.

} );

model.add( conv2d1 );

let conv2d2 = new TSP.layers.Conv2d( {

    /*
     *  configure some parameters for Conv2d2.
     *  Note the shape of Conv2d2 should be the same as Conv2d1.
     */

} );

model.add( conv2d2 );

// perform merge

let mergedLayer = TSP.layers.Average( [ conv2d1, conv2d2 ], {

        /* Configurations */

    }

);

// add merged layer

model.add( mergedLayer );
model.init();

// if layer is expanded, then call .closeLayer() to collapse the layer.

mergedLayer.closeLayer();
Example
filter_center_focus Declare an instance of "MergedLayer3d" to facilitate reuse
let mergedLayer = TSP.layers.Average(

    [ layer1, layer2 ],

    {
        animationTimeRatio: 2,
        name: "conv2d1",
        opacityRatio: 2,
        initStatus: "open"
    }

);

model.add( mergedLayer );
filter_center_focusAdd directly
model.add(TSP.layers.Average(

    [ layer1, layer2 ],

    {
        animationTimeRatio: 2,
        name: "conv2d1",
        opacityRatio: 2,
        initStatus: "open"
    }

));
Use Case
When you add average operation layer with Keras | TensorFlow | tfjs in your model the corresponding API is Average in TensorSpace.
Framework Documentation
Keras️ keras.layers.Average()
TensorFlow tf.keras.layers.average( inputs, **kwargs )
TensorFlow.js️ tf.layers.average (config)
Tag Lookup
Tag Icon Meaning Instruction
⭐️ Required Must be provided, cannot be empty. Meanwhile constructor works properly if this arguments provided. Control arguments use default value.
🔧 Suggest Recommended for giving. The API can work without them.
⚙️️ Optional As an auxiliary adjustment parameter when used, selectively added according to the specific situation The parameters here have no effect on the structure of the layer (3D visualized form).
📦 Model Configure the properties of the Layer. It changes the output shape.
🎨 Style Override the properties in TSP.model (model configuration)
🎦 Animation Override the properties in TSP.model (model configuration)
Source Code
tensorspace/src/merge/Average.js