Function mindspore::dataset::Mnist

Function Documentation

inline std::shared_ptr<MnistDataset> mindspore::dataset::Mnist(const std::string &dataset_dir, const std::string &usage = "all", const std::shared_ptr<Sampler> &sampler = std::make_shared<RandomSampler>(), const std::shared_ptr<DatasetCache> &cache = nullptr)

Function to create a MnistDataset.

Note

The generated dataset has two columns [“image”, “label”]

Parameters
  • dataset_dir[in] Path to the root directory that contains the dataset

  • usage[in] of MNIST, can be “train”, “test” or “all” (default = “all”).

  • sampler[in] Shared pointer to a sampler object used to choose samples from the dataset. If sampler is not given, a RandomSampler will be used to randomly iterate the entire dataset (default = RandomSampler())

  • cache[in] Tensor cache to use. (default=nullptr which means no cache is used).

Returns

Shared pointer to the current MnistDataset

Example
/* Define dataset path and MindData object */
std::string folder_path = "/path/to/mnist_dataset_directory";
std::shared_ptr<Dataset> ds = Mnist(folder_path, "all", std::make_shared<RandomSampler>(false, 20));

/* Create iterator to read dataset */
std::shared_ptr<Iterator> iter = ds->CreateIterator();
std::unordered_map<std::string, mindspore::MSTensor> row;
iter->GetNextRow(&row);

/* Note: In MNIST dataset, each dictionary has keys "image" and "label" */
auto image = row["image"];