335 Star 1.5K Fork 860

MindSpore / docs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
from_tensor_slices.md 1.92 KB
一键复制 编辑 原始数据 按行查看 历史
俞涵 提交于 2023-01-29 16:21 . add mindquantum and modify url

比较与tf.data.Dataset.from_tensor_slices的功能差异

tf.data.Dataset.from_tensor_slices

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

更多内容详见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
)

更多内容详见mindspore.dataset.NumpySlicesDataset

使用方式

TensorFlow:一个静态方法,使用指定的 tf.Tensor 创建数据集。

MindSpore:一个数据集类,使用指定的 listtupledictnumpy.ndarray 创建数据集。

代码示例

# 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

搜索帮助