Creates a tf.Sequential model. A sequential model is any model where the
outputs of one layer are the inputs to the next layer, i.e. the model
topology is a simple 'stack' of layers, with no branching or skipping.
This means that the first layer passed to a tf.Sequential model should have
a defined input shape. What that means is that it should have received an
inputShape or batchInputShape argument, or for some type of layers
(recurrent, Dense...) an inputDim argument.
The key difference between tf.model and tf.sequential is that
tf.sequential is less generic, supporting only a linear stack of layers.
tf.model is more generic and supports an arbitrary graph (without
cycles) of layers.
Examples:
constmodel = tf.sequential();
// First layer must have an input shape defined. model.add(tf.layers.dense({units:32, inputShape: [50]})); // Afterwards, TF.js does automatic shape inference. model.add(tf.layers.dense({units:4}));
// Inspect the inferred shape of the model's output, which equals // `[null, 4]`. The 1st dimension is the undetermined batch dimension; the // 2nd is the output size of the model's last layer. console.log(JSON.stringify(model.outputs[0].shape));
It is also possible to specify a batch size (with potentially undetermined
batch dimension, denoted by "null") for the first layer using the
batchInputShape key. The following example is equivalent to the above:
constmodel = tf.sequential();
// First layer must have a defined input shape model.add(tf.layers.dense({units:32, batchInputShape: [null, 50]})); // Afterwards, TF.js does automatic shape inference. model.add(tf.layers.dense({units:4}));
// Inspect the inferred shape of the model's output. console.log(JSON.stringify(model.outputs[0].shape));
You can also use an Array of already-constructed Layers to create
a tf.Sequential model:
Creates a
tf.Sequential
model. A sequential model is any model where the outputs of one layer are the inputs to the next layer, i.e. the model topology is a simple 'stack' of layers, with no branching or skipping.This means that the first layer passed to a
tf.Sequential
model should have a defined input shape. What that means is that it should have received aninputShape
orbatchInputShape
argument, or for some type of layers (recurrent, Dense...) aninputDim
argument.The key difference between
tf.model
andtf.sequential
is thattf.sequential
is less generic, supporting only a linear stack of layers.tf.model
is more generic and supports an arbitrary graph (without cycles) of layers.Examples:
It is also possible to specify a batch size (with potentially undetermined batch dimension, denoted by "null") for the first layer using the
batchInputShape
key. The following example is equivalent to the above:You can also use an
Array
of already-constructedLayer
s to create atf.Sequential
model: