• Creates an IOHandler subtype that sends model artifacts to HTTP server.

    An HTTP request of the multipart/form-data mime type will be sent to the path URL. The form data includes artifacts that represent the topology and/or weights of the model. In the case of Keras-style tf.Model, two blobs (files) exist in form-data:

    • A JSON file consisting of modelTopology and weightsManifest.
    • A binary weights file consisting of the concatenated weight values. These files are in the same format as the one generated by tfjs_converter.

    The following code snippet exemplifies the client-side code that uses this function:

    const model = tf.sequential();
    model.add(
    tf.layers.dense({units: 1, inputShape: [100], activation: 'sigmoid'}));

    const saveResult = await model.save(tf.io.http(
    'http://model-server:5000/upload', {requestInit: {method: 'PUT'}}));
    console.log(saveResult);

    If the default POST method is to be used, without any custom parameters such as headers, you can simply pass an HTTP or HTTPS URL to model.save:

    const saveResult = await model.save('http://model-server:5000/upload');
    

    The following GitHub Gist https://gist.github.com/dsmilkov/1b6046fd6132d7408d5257b0976f7864 implements a server based on flask that can receive the request. Upon receiving the model artifacts via the requst, this particular server reconstitutes instances of Keras Models in memory.

    Parameters

    • path: string

      A URL path to the model. Can be an absolute HTTP path (e.g., 'http://localhost:8000/model-upload)') or a relative path (e.g., './model-upload').

    • OptionalloadOptions: LoadOptions

      Optional configuration for the loading. It includes the following fields:

      • weightPathPrefix Optional, this specifies the path prefix for weight files, by default this is calculated from the path param.
      • fetchFunc Optional, custom fetch function. E.g., in Node.js, the fetch from node-fetch can be used here.
      • onProgress Optional, progress callback function, fired periodically before the load is completed.

    Returns IOHandler

    An instance of IOHandler.