TensorSpace.js
Getting Start
Basic Concepts
TensorSpace Converter
Model Preprocessing
Models
Layers
Merge Function
Functional Model
Model() can create a TensorSpace model. To compare with the Sequential(), instead of simple layer stack, Model() requires the detailed configurations for each layer.
We can create a model like:
let model = new TSP.model.Model( container, {

    ...
    // required configurations
    inputs: [ input ],
    outputs: [ addLayer ],
    // optional configurations
    layerShape: "rect",
    layerInitStatus: "close",
    stats: true
    ...

} );
To add layers, we have to construct the relations for every layers and claim the input and output layers for the model:
let input = new TSP.layers.GreyscaleInput();

let layer1 = new TSP.layers.Conv2d( {

	name: "conv1"

} );

layer1.apply( input );

let layer2 = new TSP.layers.Conv2d( {

	name: "conv2"

} );

layer2.apply( input );

let layer3 = new TSP.layers.Conv2d( {

	name: "conv3"

} );

layer3.apply( layer2 );

let addLayer = new TSP.layers.Add(

    [ layer1, layer3 ],

    { name: "add" }

);

let model = new TSP.model.Model(container, {

    ...
    inputs: [ input ],
    outputs: [ addLayer ],
    ...

} );
After creating the structure of the model, we can load() the pre-trained ML model and init() to create the layer objects:
model.load( {

    type: "tensorflow",
    url: 'model.json',

    onProgress: function( fraction ) {

        console.log( "Loading progress: " + fraction );

    },

    onComplete: function() {

        console.log( "Complete load model." );

    }

} );

model.init( function() {

    console.log("TensorSpace's Model is initialized!");

} );
predict() method handles the prediction process for all layers including the hidden layers. All results will be used to update the layer model rendering.
Property
.inputs : Layer[]
  • filter_center_focus Required. Used by Model() ONLY.
  • filter_center_focus Represents the list of input layer objects.
  • filter_center_focus We must use Model() to claim the model object if we have multiple inputs from the network.
.outputs : Layer[]
  • filter_center_focus Required. Used by Model() ONLY.
  • filter_center_focus Represents the list of output layer objects.
  • filter_center_focus The output of the model could be multiple.
  • filter_center_focus Represents the strategy of computing data used to render layer aggregation.
.layerShape : String
  • filter_center_focus Represents the layout of expanded feature maps of a layer.
  • filter_center_focus Represents the initial status of an expandable layer. Either "expanded" as feature maps or "collapsed" as an aggregation.
.textSystem : String
  • filter_center_focus Enable or disable the display text information of each layers.
  • filter_center_focus Enable or disable the display of relation lines among layers.
.animeTime : Double
  • filter_center_focus Time spent for animation.
.color : Color Format
  • filter_center_focus All necessary color configurations of different layers and the background.
.stats : Bool
  • filter_center_focus Whether to use stats utility or not.
  • filter_center_focus Configure input shapes for pre-trained model if pre-trained model's input shape is dynamical.
.feedInputs : Array
  • filter_center_focus Configure which inputs of pre-trained model to be applied into TensorSpace model's input.
Method
  • filter_center_focus The init( complete_callback ) method use the provided configurations to create the actual objects of the model.
  • filter_center_focus See Model (concept) for more details.
  • filter_center_focus The load() method is used to maintain the pre-trained ML model (from TensorFlow, Keras or TensorFlow.js).
  • filter_center_focus A specified inputShape must be configured properly.
  • filter_center_focus See Load for more details.
  • filter_center_focus By calling predict() method, the model first collects all inferences (including intermediate and final) and then renders all related 3D visualization components.
  • filter_center_focus See Predict for more details.
.reset() : void
  • filter_center_focus The reset() method is used to set the model back to its initialization status.
  • filter_center_focus The camera will be moved to its initialized position. The view angle will be changed to initial default angle.
  • filter_center_focus All existing prediction data in each layer object will be cleaned up. All visualizing objects will be re-rendered without any data.
.getAllLayers() : Layer[]
  • filter_center_focus To get all layer objects within the model.
  • filter_center_focus To get a specified layer object by its name (String).
CodePen
We can try the examples above in the CodePen below:

See the Pen TensorSpace - Functional Model by syt123450 (@syt123450) on CodePen.