As easy as I can make Tensorflowjs Multi Output Keras Models

For a long time I have wanted to do some advanced Keras Models like what is shown on this website https://machinelearningmastery.com/keras-functional-api-deep-learning/

Until machine2learn.com came out with their Deep Learning keras model generator I really did not know where to begin.

This example does not really do much except prove that you can save the complex model, by loading what it looks like.



So first lets just define a Multi Output Keras model. and then have let it's json file show up in the text area. This program uses your local storage to save and then upload the "tensorflowjs_models/myMultiModel01/model_topology" file to the textarea

Normal Keras Sequential Model

model = tf.sequential(); // no const so that it is a global variable
model.add(tf.layers.dense({ units: 20, inputShape: [1] }) );
model.add(tf.layers.dense({ units: 20 }) );
model.add(tf.layers.dense({ units: 1 }) );

This Advanced Keras multiple input single output model

const myInput1 = tf.input({shape: [1], name: 'myInput1'});

const myInput1Path1Dense1 = tf.layers.dense({units: 20, name: 'myInput1Path1Dense1'}).apply(myInput1);
const myInput1Path1Dense2 = tf.layers.dense({units: 20, name: 'myInput1Path1Dense2'}).apply(myInput1Path1Dense1);
const myInput1Path1Dense3 = tf.layers.dense({units: 20, name: 'myInput1Path1Dense3'}).apply(myInput1Path1Dense2);
const myInput1Path1Dense4 = tf.layers.dense({units: 1, name: 'myInput1Path1Dense4'}).apply(myInput1Path1Dense3);

const myInput1Path2Dense1 = tf.layers.dense({units: 1, name: 'myInput1Path2Dense1'}).apply(myInput1);
model2 = tf.model({ inputs: myInput1, outputs: [myInput1Path1Dense4,myInput1Path2Dense1] });
// This would be a global model


Note: Check your developer console --> Application --> Key for the 4 files that may be saved differently on your machine.
On my machine they have the same root as the below localStorage identifier:
info
model_topology (the one this code loads)
weight_data (this is in binary format. Does not load into this textarea)
weight_specs

localStorage identifier:


...











This Github, ... this Github Website Version, ... this Hosted Website Version, ... Tensorflowjs

By Jeremy Ellis
Twitter@rocksetta
Website http://rocksetta.com
Use at your own risk!