Open In App

Tensorflow.js tf.io.browserDownloads() Function

Tensorflow.js is a Google-developed open-source toolkit for executing machine learning models and deep learning neural networks in the browser or on the node platform. It also enables developers to create machine learning models in JavaScript and utilize them directly in the browser or with Node.js.

The function tf.io.browserDownloads() is used to create an IOHandler that triggers file downloads from the browser.



Syntax:

tf.io.browserDownloads (fileNamePrefix?) 

Parameters:



Returns: IOHandler

Example 1:




const model = tf.sequential();
model.add(tf.layers.dense(
    { units: 1, 
    inputShape: [10], 
    activation: 'sigmoid' }));
const res = await model.save('downloads://testModel');
console.log(res);

Output:

{
 "modelArtifactsInfo": {
    "dateSaved": "2022-04-30T05:37:03.289Z",
    "modelTopologyType": "JSON",
    "modelTopologyBytes": 612,
    "weightSpecsBytes": 124,
    "weightDataBytes": 44
  }
}

Example 2:




const model = tf.sequential();
model.add(tf.layers.dense(
    { units: 10, 
    inputShape: [10], 
    activation: 'sigmoid'}));
  
model.add(tf.layers.dense(
    { units: 10, 
    inputShape: [10], 
    activation: 'sigmoid'}));
  
model.add(tf.layers.dense(
    { units: 1, 
    inputShape: [10], 
    activation: 'sigmoid'}));
  
const res = await model.save('downloads://testModel');
console.log(res);

Output:

{
   "modelArtifactsInfo": {
       "dateSaved": "2022-04-30T05:39:13.304Z",
       "modelTopologyType": "JSON",
       "modelTopologyBytes": 1570,
       "weightSpecsBytes": 374,
       "weightDataBytes": 924
   }
}

Reference: https://js.tensorflow.org/api/latest/#io.browserDownloads


Article Tags :