| @@ -2294,11 +2294,11 @@ def _iter_fn(dataset, num_samples): | |||||
| except StopIteration: | except StopIteration: | ||||
| return | return | ||||
| # convert output tensors to ndarrays | # convert output tensors to ndarrays | ||||
| yield tuple([np.array(x) for x in val]) | |||||
| yield tuple([np.array(x, copy=False) for x in val]) | |||||
| else: | else: | ||||
| for val in dataset: | for val in dataset: | ||||
| # convert output tensors to ndarrays | # convert output tensors to ndarrays | ||||
| yield tuple([np.array(x) for x in val]) | |||||
| yield tuple([np.array(x, copy=False) for x in val]) | |||||
| def _generator_fn(generator, num_samples): | def _generator_fn(generator, num_samples): | ||||
| @@ -2332,12 +2332,12 @@ def _py_sampler_fn(sampler, num_samples, dataset): | |||||
| return | return | ||||
| val = dataset[idx] | val = dataset[idx] | ||||
| # convert output tensors to ndarrays | # convert output tensors to ndarrays | ||||
| yield tuple([np.array(x) for x in val]) | |||||
| yield tuple([np.array(x, copy=False) for x in val]) | |||||
| else: | else: | ||||
| for i in sampler: | for i in sampler: | ||||
| val = dataset[i] | val = dataset[i] | ||||
| # convert output tensors to ndarrays | # convert output tensors to ndarrays | ||||
| yield tuple([np.array(x) for x in val]) | |||||
| yield tuple([np.array(x, copy=False) for x in val]) | |||||
| def _cpp_sampler_fn(sampler, dataset): | def _cpp_sampler_fn(sampler, dataset): | ||||
| @@ -2348,7 +2348,7 @@ def _cpp_sampler_fn(sampler, dataset): | |||||
| for i in indices: | for i in indices: | ||||
| val = dataset[i] | val = dataset[i] | ||||
| # convert output tensors to ndarrays | # convert output tensors to ndarrays | ||||
| yield tuple([np.array(x) for x in val]) | |||||
| yield tuple([np.array(x, copy=False) for x in val]) | |||||
| def _cpp_sampler_fn_mp(sampler, dataset, num_worker): | def _cpp_sampler_fn_mp(sampler, dataset, num_worker): | ||||
| @@ -2437,7 +2437,7 @@ def _sampler_fn_mp(indices, dataset, num_worker): | |||||
| # Set eoe event once all indices are sent | # Set eoe event once all indices are sent | ||||
| if idx_cursor == len(indices) and not eoe.is_set(): | if idx_cursor == len(indices) and not eoe.is_set(): | ||||
| eoe.set() | eoe.set() | ||||
| yield tuple([np.array(x) for x in result]) | |||||
| yield tuple([np.array(x, copy=False) for x in result]) | |||||
| def _generator_worker_loop(dataset, idx_queue, result_queue, eoe): | def _generator_worker_loop(dataset, idx_queue, result_queue, eoe): | ||||
| @@ -2549,35 +2549,35 @@ class GeneratorDataset(SourceDataset): | |||||
| when num_shards is also specified. Random accessible input is required. | when num_shards is also specified. Random accessible input is required. | ||||
| Examples: | Examples: | ||||
| >>> import mindspore.dataengine as de | |||||
| >>> import mindspore.dataset as ds | |||||
| >>> # 1) Multidimensional generator function as callable input | >>> # 1) Multidimensional generator function as callable input | ||||
| >>> def generator_md(): | >>> def generator_md(): | ||||
| >>> for i in range(64): | >>> for i in range(64): | ||||
| >>> yield (np.array([[i, i + 1], [i + 2, i + 3]]),) | >>> yield (np.array([[i, i + 1], [i + 2, i + 3]]),) | ||||
| >>> # create multi_dimension_generator_dataset with GeneratorMD and column name "multi_dimensional_data" | >>> # create multi_dimension_generator_dataset with GeneratorMD and column name "multi_dimensional_data" | ||||
| >>> multi_dimension_generator_dataset = de.GeneratorDataset(generator_md, ["multi_dimensional_data"]) | |||||
| >>> multi_dimension_generator_dataset = ds.GeneratorDataset(generator_md, ["multi_dimensional_data"]) | |||||
| >>> # 2) Multi-column generator function as callable input | >>> # 2) Multi-column generator function as callable input | ||||
| >>> def generator_mc(maxid = 64): | >>> def generator_mc(maxid = 64): | ||||
| >>> for i in range(maxid): | >>> for i in range(maxid): | ||||
| >>> yield (np.array([i]), np.array([[i, i + 1], [i + 2, i + 3]])) | >>> yield (np.array([i]), np.array([[i, i + 1], [i + 2, i + 3]])) | ||||
| >>> # create multi_column_generator_dataset with GeneratorMC and column names "col1" and "col2" | >>> # create multi_column_generator_dataset with GeneratorMC and column names "col1" and "col2" | ||||
| >>> multi_column_generator_dataset = de.GeneratorDataset(generator_mc, ["col1", "col2"]) | |||||
| >>> multi_column_generator_dataset = ds.GeneratorDataset(generator_mc, ["col1", "col2"]) | |||||
| >>> # 3) Iterable dataset as iterable input | >>> # 3) Iterable dataset as iterable input | ||||
| >>> class MyIterable(): | >>> class MyIterable(): | ||||
| >>> def __iter__(self): | >>> def __iter__(self): | ||||
| >>> return # User implementation | >>> return # User implementation | ||||
| >>> # create iterable_generator_dataset with MyIterable object | >>> # create iterable_generator_dataset with MyIterable object | ||||
| >>> iterable_generator_dataset = de.GeneratorDataset(MyIterable(), ["col1"]) | |||||
| >>> iterable_generator_dataset = ds.GeneratorDataset(MyIterable(), ["col1"]) | |||||
| >>> # 4) Random accessible dataset as Random accessible input | >>> # 4) Random accessible dataset as Random accessible input | ||||
| >>> class MyRA(): | >>> class MyRA(): | ||||
| >>> def __getitem__(self, index): | >>> def __getitem__(self, index): | ||||
| >>> return # User implementation | >>> return # User implementation | ||||
| >>> # create ra_generator_dataset with MyRA object | >>> # create ra_generator_dataset with MyRA object | ||||
| >>> ra_generator_dataset = de.GeneratorDataset(MyRA(), ["col1"]) | |||||
| >>> ra_generator_dataset = ds.GeneratorDataset(MyRA(), ["col1"]) | |||||
| >>> # List/Dict/Tuple is also random accessible | >>> # List/Dict/Tuple is also random accessible | ||||
| >>> list_generator = de.GeneratorDataset([(np.array(0),), (np.array(1)), (np.array(2))], ["col1"]) | |||||
| >>> list_generator = ds.GeneratorDataset([(np.array(0),), (np.array(1)), (np.array(2))], ["col1"]) | |||||
| >>> # 5) Built-in Sampler | >>> # 5) Built-in Sampler | ||||
| >>> my_generator = de.GeneratorDataset(my_ds, ["img", "label"], sampler=samplers.RandomSampler()) | |||||
| >>> my_generator = ds.GeneratorDataset(my_ds, ["img", "label"], sampler=samplers.RandomSampler()) | |||||
| >>> | >>> | ||||
| """ | """ | ||||