mindspore.dataset.Dataset.sync_update
- Dataset.sync_update(condition_name, num_batch=None, data=None)[source]
Release a blocking condition and trigger callback with given data.
- Parameters
condition_name (str) – The condition name that is used to toggle sending next row.
num_batch (Union[int, None]) – The number of batches (rows) that are released. When num_batch is
None
, it will default to the number specified by the sync_wait operation. Default:None
.data (Any) – The data passed to the callback, user defined. Default:
None
.
Examples
>>> import numpy as np >>> import mindspore.dataset as ds >>> >>> def gen(): ... for i in range(100): ... yield (np.array(i),) >>> >>> class Augment: ... def __init__(self, loss): ... self.loss = loss ... ... def preprocess(self, input_): ... return input_ ... ... def update(self, data): ... self.loss = data["loss"] >>> >>> batch_size = 10 >>> dataset = ds.GeneratorDataset(gen, column_names=["input"]) >>> aug = Augment(0) >>> dataset = dataset.sync_wait(condition_name='', num_batch=1) >>> dataset = dataset.map(input_columns=["input"], operations=[aug.preprocess]) >>> dataset = dataset.batch(batch_size) >>> >>> count = 0 >>> for data in dataset.create_dict_iterator(num_epochs=1, output_numpy=True): ... count += 1 ... data = {"loss": count} ... dataset.sync_update(condition_name="", data=data)