Dataset API (tfjs-data) for MNIST
This package provides the Dataset API for MNIST dataset. It is built using @tensorflow/tfjs-data package (which is now included in @tensorflow/tfjs union package) that provides a uniform and consistent way to access various datasets.
npm install tfjs-data-mnist
// get the dataset;// there are 2 properties in ds (testDataset and trainDataset)// get the iterator for testDataset;// iterate by invoking next;// dataElement.done === true => there are no more elements// dataElement.value is **TensorContainer** of type [feature, label]// where feature and label are of type Tensor1D//// feature is Tensor1D with shape // label is Tensor1D with shape ////// label is actually a one-hot encoded vector// how to get the feature and label;;// The nice thing about dataset API is that you get// lot of operations such as suffle, repeat, take etc// for free// Here is an example to first shuffle the dataset// and then take only first 5 samples;// You can also pass dataset to train the modelawait model.fitDatasetds.trainDataset.batch32,;
Running the samples
# do npm install at the root of this directorynpm install# install peer dependnenciesnpm install @tensorflow/tfjs-core @tensorflow/tfjs-data --no-save# change directory into examplecd examples# do npm install in examplenpm install# Run a basic example that shows# how to use the api of Datasetnpm run basic# Another example is to train a model# where I use fitDataset api that takes Dataset# as an inputnpm run train