如何让 tf.data.Dataset 在一次调用中返回所有元素? [英] How to make tf.data.Dataset return all of the elements in one call?

查看:30
本文介绍了如何让 tf.data.Dataset 在一次调用中返回所有元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法可以在 tf.data.Dataset 中获取整个元素集?即我想将数据集的批量大小设置为我的数据集的大小,而无需专门传递元素数.这对于验证数据集很有用,我想一次性测量整个数据集的准确性.我很惊讶没有一种方法可以获取 tf.data.Dataset

Is there an easy way to get the entire set of elements in a tf.data.Dataset? i.e. I want to set batch size of the Dataset to be the size of my dataset without specifically passing it the number of elements. This would be useful for validation dataset where I want to measure accuracy on the entire dataset in one go. I'm surprised there isn't a method to get the size of a tf.data.Dataset

推荐答案

Tensorflow 2.0

您可以使用 as_numpy_iterator 枚举数据集>

You can enumerate the dataset using as_numpy_iterator

for element in Xtrain.as_numpy_iterator(): 
  print(element) 

这篇关于如何让 tf.data.Dataset 在一次调用中返回所有元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆