As easy as I can make Tensorflowjs Multi Input Keras Models

For a long time I have wanted to do some advanced Keras Models like what is shown on this website

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

Note: This example doesn't really do anything except save and then load the Keras model If you get a printout of the model, then the example has been successful.

So first lets just define a Multi Input Keras model. and then have 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 myInput1Dense1 = tf.layers.dense({units: 20, name: 'myInput1Dense1'}).apply(myInput1);
const myInput1Dense2 = tf.layers.dense({units: 20, name: 'myInput1Dense2'}).apply(myInput1Dense1);
const myInput1Dense3 = tf.layers.dense({units: 1, name: 'myInput1Dense3'}).apply(myInput1Dense2)

const myInput2 = tf.input({shape: [1], name: 'myInput2'});
const myInput2Dense1 = tf.layers.dense({units: 20, name: 'myInput2Dense1'}).apply(myInput2);
const myInput2Dense2 = tf.layers.dense({units: 20, name: 'myInput2Dense2'}).apply(myInput2Dense1);
const myInput2Dense3 = tf.layers.dense({units: 1, name: 'myInput2Dense3'}).apply(myInput2Dense2);

const myConcatenate1 = tf.layers.concatenate({axis : 1, name: 'myConcatenate1'}).apply([myInput1Dense3, myInput2Dense3]);
const myConcatenate1Dense4 = tf.layers.dense({units: 1, name: 'myConcatenate1Dense4'}).apply(myConcatenate1)

model2 = tf.model({inputs: [myInput1,myInput2], outputs: myConcatenate1Dense4}); // 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:
model_topology (the one this code loads)
weight_data (this is in binary format. Does not load into this textarea)

localStorage identifier:


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

By Jeremy Ellis
Use at your own risk!