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.

Returns

Dict, The dictionary contains the serialized dataset graph.

Raises

OSError – Can not open a file

Examples

>>> dataset = ds.MnistDataset(mnist_dataset_dir, 100)
>>> one_hot_encode = c_transforms.OneHot(10)  # num_classes is input argument
>>> dataset = dataset.map(operation=one_hot_encode, input_column_names="label")
>>> dataset = dataset.batch(batch_size=10, drop_remainder=True)
>>> # serialize it to JSON file
>>> ds.engine.serialize(dataset, json_filepath="/path/to/mnist_dataset_pipeline.json")
>>> serialized_data = ds.engine.serialize(dataset)  # serialize it to Python dict