• Parses a JSON model configuration file and returns a model instance.

    // This example shows how to serialize a model using `toJSON()` and
    // deserialize it as another model using `tf.models.modelFromJSON()`.
    // Note: this example serializes and deserializes only the topology
    // of the model; the weights of the loaded model will be different
    // from those of the the original model, due to random weight
    // initialization.
    // To load the topology and weights of a model, use `tf.loadLayersModel()`.
    const model1 = tf.sequential();
    model1.add(tf.layers.repeatVector({inputShape: [2], n: 4}));
    // Serialize `model1` as a JSON object.
    const model1JSON = model1.toJSON(null, false);
    model1.summary();

    const model2 = await tf.models.modelFromJSON(model1JSON);
    model2.summary();

    Parameters

    • modelAndWeightsConfig: PyJsonDict | ModelAndWeightsConfig

      JSON object or string encoding a model and weights configuration. It can also be only the topology JSON of the model, in which case the weights will not be loaded.

    • Optional customObjects: ConfigDict

    Returns Promise<LayersModel>

    A TensorFlow.js Layers tf.LayersModel instance (uncompiled).

Generated using TypeDoc