• A model is a data structure that consists of Layers and defines inputs and outputs.

    The key difference between tf.model and tf.sequential is that tf.model is more generic, supporting an arbitrary graph (without cycles) of layers. tf.sequential is less generic and supports only a linear stack of layers.

    When creating a tf.LayersModel, specify its input(s) and output(s). Layers are used to wire input(s) to output(s).

    For example, the following code snippet defines a model consisting of two dense layers, with 10 and 4 units, respectively.

    // Define input, which has a size of 5 (not including batch dimension).
    const input = tf.input({shape: [5]});

    // First dense layer uses relu activation.
    const denseLayer1 = tf.layers.dense({units: 10, activation: 'relu'});
    // Second dense layer uses softmax activation.
    const denseLayer2 = tf.layers.dense({units: 4, activation: 'softmax'});

    // Obtain the output symbolic tensor by applying the layers on the input.
    const output = denseLayer2.apply(denseLayer1.apply(input));

    // Create the model based on the inputs.
    const model = tf.model({inputs: input, outputs: output});

    // The model can be used for training, evaluation and prediction.
    // For example, the following line runs prediction with the model on
    // some fake data.
    model.predict(tf.ones([2, 5])).print();

    See also: tf.sequential, tf.loadLayersModel.

    Parameters

    • args: ContainerArgs

    Returns LayersModel

    Doc

Generated using TypeDoc