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.
Installation
npm install tfjs-data-mnist
Usage
// 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 [784]// label is Tensor1D with shape [10]////// 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, ;
Examples
Running the samples
# do npm install at the root of this directory npm install # install peer dependnencies npm install @tensorflow/tfjs-core @tensorflow/tfjs-data --no-save # change directory into example cd examples # do npm install in example npm install # Run a basic example that shows # how to use the api of Dataset npm run basic # Another example is to train a model # where I use fitDataset api that takes Dataset # as an input npm run train