Skip to content
Related Articles

Related Articles

Tensorflow.js tf.io.browserDownloads() Function

Improve Article
Save Article
  • Last Updated : 11 May, 2022
Improve Article
Save Article

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:

  • fileNamePrefix (string): The prefix of the name of the files to be downloaded. For usage with tf.Model, fileNamePrefix should be one of the two types below:
    1. null or undefined, default file names will be used in this case.
    2. A single string or an Array of a single string.

Returns: IOHandler

Example 1:

Javascript




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:

Javascript




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


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!