首页 > 解决方案 > 使用 tensorflow_datasets API 访问已下载的数据集

问题描述

我正在尝试使用最近发布的 tensorflow_dataset API 在 Open Images Dataset 上训练 Keras 模型。数据集大小约为 570 GB。我使用以下代码下载了数据:

import tensorflow_datasets as tfds
import tensorflow as tf

open_images_dataset = tfds.image.OpenImagesV4()
open_images_dataset.download_and_prepare(download_dir="/notebooks/dataset/")

下载完成后,与我的 jupyter notebook 的连接不知何故中断了,但提取似乎也完成了,至少所有下载的文件在“extracted”文件夹中都有对应的文件。但是,我现在无法访问下载的数据:

tfds.load(name="open_images_v4", data_dir="/notebooks/open_images_dataset/extracted/", download=False)

这只会给出以下错误:

AssertionError: Dataset open_images_v4: could not find data in /notebooks/open_images_dataset/extracted/. Please make sure to call dataset_builder.download_and_prepare(), or pass download=True to tfds.load() before trying to access the tf.data.Dataset object.

当我调用函数 download_and_prepare() 时,它只会再次下载整个数据集。

我在这里错过了什么吗?

编辑:下载后“extracted”下的文件夹有 18 个 .tar.gz 文件。

标签: tensorflowkerasdeep-learningdataset

解决方案


这适用于 tensorflow-datasets 1.0.1 和 tensorflow 2.0。

文件夹层次结构应该是这样的:

/notebooks/open_images_dataset/extracted/open_images_v4/0.1.0

所有数据集都有一个版本。然后可以像这样加载数据。

ds = tf.load('open_images_v4', data_dir='/notebooks/open_images_dataset/extracted', download=False)

我没有 open_images_v4 数据。我将 cifar10 数据放入名为 open_images_v4 的文件夹中,以检查 tensorflow_datasets 期望的文件夹结构。


推荐阅读