【问题标题】:What is the fastest method to count elements of a tensorflow.data.Datset?计算 tensorflow.data.Dataset 元素的最快方法是什么?
【发布时间】:2020-01-21 00:53:37
【问题描述】:

有没有比计算tensorflow.data.Dataset 的所有元素更快的方法

def count_elements(dataset: tf.data.Dataset):
    return dataset.reduce(0, lambda x, _ : x + 1).numpy()

“更快”意味着还要考虑内存使用情况,但执行时间是最重要的。据我所知,没有内置方法。

【问题讨论】:

    标签: python tensorflow2.0 tensorflow-datasets


    【解决方案1】:

    简短回答“否”。

    对于内存数据集,有:tf.data.experimental.cardinality(dataset),但 tf.data.Datasets 本质上是延迟加载的,并且可以是无限的,因此如果不遍历它,就无法知道 tf.data.Dataset 中有多少元素。

    信用:In TensorFlow 2.0, how can I see the number of elements in a dataset?

    【讨论】:

      猜你喜欢
      • 2016-12-20
      • 1970-01-01
      • 1970-01-01
      • 2017-06-27
      • 2011-02-25
      • 2013-07-02
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      相关资源
      最近更新 更多