从TensorFlow数据集中提取元素
我有一个包含我所有数据和标签的TensorFlow数据集。 前20个元素使用以下代码提取到另一个数据集中:
train_dataset = big_dataset.take(20)
但是如何将BIG_DATASET的最后20个元素提取到新数据集中?
谢谢,我进步了!
编辑: 以下代码显示了我如何定义big_dataset:
big_dataset = tf.data.Dataset.from_tensor_slices((all_points, all_labels))
现在有效获取第一个elemets的是以下代码(train_size as eg 20):
train_dataset = big_dataset.take(train_size)
train_dataset = train_dataset.shuffle(train_size).map(augment).batch(BATCH_SIZE)
但是使用.skip()。
I have a tensorflow dataset containing all my data and labels.
The first 20 elements are extracted into another dataset using following code:
train_dataset = big_dataset.take(20)
But how do i extract for example the last 20 elements from big_dataset into a new dataset?
Thanks i advance!
EDIT:
The following code shows how i define the big_dataset:
big_dataset = tf.data.Dataset.from_tensor_slices((all_points, all_labels))
What works now to get the first elemets is the following code (where train_size is e.g. 20):
train_dataset = big_dataset.take(train_size)
train_dataset = train_dataset.shuffle(train_size).map(augment).batch(BATCH_SIZE)
But using the .skip().take() results in an empty database
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
跳过
。例如,假设您有120个数据示例和一个批次示例1,而您尚未将数据改组,那么您可以尝试以下内容:对于特定数据集,请尝试:
Try using
skip
. For example, suppose you have 120 data samples and a batch_size of 1 and you have not shuffled your data, then you can try something like the following:For your specific dataset, try: