mindspore.dataset.dataloader.default_convert
- mindspore.dataset.dataloader.default_convert(data)[source]
Default function for converting each NumPy array element into a
mindspore.Tensor
when batching is disabled inDataLoader
.If the input is a NumPy array and its dtype is not str, bytes or object, convert it into a
mindspore.Tensor
;If the input is a NumPy numeric or boolean scalar, convert it into a
mindspore.Tensor
;If the input is a
Mapping
, keep all the keys unchanged and convert the value of each key by calling this function recursively;If the input is a
Sequence
, convert the element at each position by calling this function recursively;Otherwise, leave it unchanged.
- Parameters
data (
Any
) – A single data to be converted.- Returns
Any
, the converted data.
Examples
>>> import numpy as np >>> from mindspore.dataset.dataloader import default_convert >>> >>> default_convert(np.array([0, 1, 2])) Tensor(shape=[3], dtype=Int64, value= [0, 1, 2]) >>> >>> default_convert(np.int32(0)) Tensor(shape=[], dtype=Int32, value= 0) >>> >>> default_convert({"data": np.array([0, 1, 2])}) {'data': Tensor(shape=[3], dtype=Int64, value= [0, 1, 2])} >>> >>> default_convert([np.array([0, 1, 2]), np.array([3, 4, 5])]) [Tensor(shape=[3], dtype=Int64, value= [0, 1, 2]), Tensor(shape=[3], dtype=Int64, value= [3, 4, 5])] >>> >>> default_convert(np.array(["text"])) array(['text'], dtype='<U4')