mindspore.connect_network_with_dataset

mindspore.connect_network_with_dataset(network, dataset_helper)[source]

Connect the network with dataset in dataset_helper.

This function wraps the input network with ‘GetNext’ so that the data can be fetched automatically from the data channel corresponding to the ‘queue_name’ and passed to the input network during forward computation.

Note

In the case of running the network on Ascend/GPU in graph mode, this function will wrap the input network with mindspore.ops.GetNext. In other cases, the input network will be returned with no change. The mindspore.ops.GetNext is required to get data only in sink mode, so this function is not applicable to no-sink mode. when dataset_helper’s dataset_sink_mode is True, it can only be connected to one network.

Parameters
  • network (Cell) – The training network for dataset.

  • dataset_helper (DatasetHelper) – A class to process the MindData dataset, it provides the type, shape and queue name of the dataset to wrap the GetNext.

Returns

Cell, a new network wrapped with ‘GetNext’ in the case of running the task on Ascend in graph mode, otherwise it is the input network.

Raises

RuntimeError – If the API was not called in dataset sink mode.

Supported Platforms:

Ascend GPU

Examples

>>> import numpy as np
>>> import mindspore as ms
>>> from mindspore import nn
>>> from mindspore import dataset as ds
>>>
>>> data = {"x": np.float32(np.random.rand(64, 10)), "y": np.random.randint(0, 5, (64,))}
>>> train_dataset = ds.NumpySlicesDataset(data=data).batch(32)
>>> dataset_helper = ms.DatasetHelper(train_dataset, dataset_sink_mode=True)
>>> net = nn.Dense(10, 5)
>>> net_with_get_next = ms.connect_network_with_dataset(net, dataset_helper)