mindspore.dataset.serialize

mindspore.dataset.serialize(dataset, json_filepath='')[source]

Serialize dataset pipeline into a JSON file.

Note

Currently some Python objects are not supported to be serialized. For Python function serialization of map operator, de.serialize will only return its function name.

Parameters
  • dataset (Dataset) – The starting node.

  • json_filepath (str) – The filepath where a serialized JSON file will be generated (default=””).

Returns

Dict, The dictionary contains the serialized dataset graph.

Raises

OSError – Can not open a file

Examples

>>> dataset = ds.MnistDataset(mnist_dataset_dir, num_samples=100)
>>> one_hot_encode = transforms.OneHot(10)  # num_classes is input argument
>>> dataset = dataset.map(operations=one_hot_encode, input_columns="label")
>>> dataset = dataset.batch(batch_size=10, drop_remainder=True)
>>> # serialize it to JSON file
>>> serialized_data = ds.serialize(dataset, json_filepath="/path/to/mnist_dataset_pipeline.json")