334 Star 1.5K Fork 864

MindSpore / docs

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
from_tensor_slices.md 1.92 KB
Copy Edit Raw Blame History
俞涵 authored 2023-01-29 16:21 . add mindquantum and modify url

Function Differences with tf.data.Dataset.from_tensor_slices

tf.data.Dataset.from_tensor_slices

@staticmethod
tf.data.Dataset.from_tensor_slices(
    tensors
)

For more information, see tf.data.Dataset.from_tensor_slices.

mindspore.dataset.NumpySlicesDataset

class mindspore.dataset.NumpySlicesDataset(
    data,
    column_names=None,
    num_samples=None,
    num_parallel_workers=1,
    shuffle=None,
    sampler=None,
    num_shards=None,
    shard_id=None
)

For more information, see mindspore.dataset.NumpySlicesDataset.

Differences

TensorFlow: A static method that creates Dataset with the specified tf.Tensor.

MindSpore: A dataset class that creates Dataset with the specified list , tuple , dict or numpy.ndarray.

Code Example

# The following implements NumpySlicesDataset with MindSpore.
import numpy as np
import mindspore.dataset as ds

data = np.array([[1, 2], [3, 4], [5, 6]])
dataset = ds.NumpySlicesDataset(data=data, column_names=["data"], shuffle=False)

for item in dataset.create_dict_iterator():
    print(item["data"])
# [1 2]
# [3 4]
# [5 6]

# The following implements from_tensor_slices with TensorFlow.
import tensorflow as tf
tf.compat.v1.enable_eager_execution()

data = tf.constant([[1, 2], [3, 4], [5, 6]])
dataset = tf.data.Dataset.from_tensor_slices(data)

for value in dataset:
    print(value)
# [1 2]
# [3 4]
# [5 6]
1
https://gitee.com/mindspore/docs.git
git@gitee.com:mindspore/docs.git
mindspore
docs
docs
r2.0.0-alpha

Search