mindspore.data_sink
- mindspore.data_sink(fn, dataset, steps, sink_size=1, jit=False)[source]
A wrapper function to generate a function for the input function.
The generated function will be executed in data sinking mode.
- Parameters
fn (Function) – The Python function that will be run with dataset.
dataset (Dataset) – The dataset iterator. The dataset can be generated by dataset generator API in
mindspore.dataset
, such asmindspore.dataset.ImageFolderDataset
.steps (int) – The total running steps. steps must be positive integer.
sink_size (int) – Control the amount of data in each sink. sink_size must be positive integer. Default: 1.
jit (bool) – Controls the execution mode(Graph mode/PyNative mode) of the generated function. Default: False, means running in PyNative mode.
- Returns
Function, the generated function will be executed in data sinking mode.
- Raises
ValueError – If steps or sink_size is not positive integer.
- Supported Platforms:
Ascend
GPU
Examples
>>> import numpy as np >>> import mindspore as ms >>> from mindspore import dataset as ds >>> >>> data = {"x": np.ones((1,), dtype=np.int32), "y": np.ones((1,), dtype=np.int32)} >>> dataset = ds.NumpySlicesDataset(data=data) >>> >>> def func_net(x, y): ... out = x + y ... return out >>> >>> sink_process = ms.train.data_sink(func_net, dataset, steps=2, sink_size=1) >>> for _ in range(2): ... out = sink_process() ... print(out) 2 2