Tensorflow.js tf.data.Dataset class .prefetch() Method Last Updated : 22 Apr, 2022 Comments Improve Suggest changes Like Article Like Report Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. The tf.data.Dataset class .prefetch() function is used to produce a dataset that prefetches the specified elements from this given dataset. Syntax: prefetch (bufferSize) Parameters: This function accepts a parameter which is illustrated below: bufferSize: It is an integer value that specifies the number of elements to be prefetched. Return Value: It returns a dataset of elements. Example 1: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Calling the .prefetch() function over // the specified dataset of some elements const a = tf.data.array([5, 10, 15, 20]).prefetch(4); // Getting the dataset of prefetched elements await a.forEachAsync(a => console.log(a)); Output: 5 10 15 20 Example 2: JavaScript // Importing the tensorflow.js library import * as tf from "@tensorflow/tfjs" // Specifying a dataset of some elements const a = tf.data.array(["a", "b", "c", "d", "e"]); // Calling the .prefetch() function over // the above dataset along with the // batch of size 2 const b = a.batch(2) const c = b.prefetch(2) // Getting the dataset of prefetched elements await c.forEachAsync(c => console.log(c)); Output: Tensor ['a', 'b'] Tensor ['c', 'd'] Tensor ['e'] Reference: https://js.tensorflow.org/api/latest/#tf.data.Dataset.prefetch Comment More infoAdvertise with us Next Article Tensorflow.js tf.data.Dataset class .take() Method K Kanchan_Ray Follow Improve Article Tags : JavaScript Web Technologies Tensorflow.js TensorFlow.js-Classes TensorFlow.js-Data +1 More Similar Reads Tensorflow.js tf.data.Dataset class .take() Method Tensorflow.js is an open-source library that is developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .take() method is used to form a dataset with maximum count foremost items out of the stated dataset. Syntax: take( 2 min read Tensorflow.js tf.data.Dataset class .batch() Method Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. It also helps the developers to develop ML models in JavaScript language and can use ML directly in the browser or in Node.js. The tf. 2 min read Tensorflow.js tf.data.Dataset class .toArray() Method Tensorflow.js is an open-source library that is developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .toArray() method is used to accumulate each elements of the stated dataset within an array. Syntax: Â toArray() Pa 1 min read Tensorflow.js tf.data.Dataset.skip() Method Tensorflow.js is an open-source library that is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The tf.data.Dataset.skip() method is used to create a dataset that skips count initial elements from this dataset 1 min read Tensorflow.js tf.data.Dataset class.mapAsync() Method Tensorflow.js is an open-source library that is developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment. The .mapAsync() method is used to map the stated dataset over an asynchronous one to one conversion. Syntax: mapAsync(t 2 min read Tensorflow.js tf.Sequential class .fitDataset() Method Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. Tensorflow.js tf.Sequential class .fitDataset() method is used to trains the model using a dataset object. Syntax: model.fitDataset(da 4 min read Like