kri*_*nab 6 tensorflow tfrecord
请在标记重复之前阅读帖子:
我一直在寻找一种有效的方法来计算 TFRecord 图像文件中的示例数量。由于 TFRecord 文件不保存有关文件本身的任何元数据,因此用户必须遍历文件才能计算此信息。
StackOverflow 上有几个不同的问题可以回答这个问题。问题是他们似乎都使用了 DEPRECATEDtf.python_io.tf_record_iterator命令,所以这不是一个稳定的解决方案。以下是现有帖子的示例:
从 Tensorflow 中的 .tfrecords 文件获取记录总数
所以我想知道是否有一种方法可以使用新的 Dataset API 来计算记录数。
类reduce下列出了一个方法Dataset。他们给出了使用以下方法计算记录的示例:
# generate the dataset (batch size and repeat must be 1, maybe avoid dataset manipulation like map and shard)
ds = tf.data.Dataset.range(5)
# count the examples by reduce
cnt = ds.reduce(np.int64(0), lambda x, _: x + 1)
## produces 5
Run Code Online (Sandbox Code Playgroud)
不知道这个方法是否比@krishnab 的 for 循环快。
| 归档时间: |
|
| 查看次数: |
2581 次 |
| 最近记录: |