使用tensorflow_datasets API访问已下载的数据集

时间:2019-04-02 13:10:49

标签: tensorflow keras deep-learning dataset

我正在尝试使用最近发布的tensorflow_dataset API来在开放图像数据集上训练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笔记本电脑的连接以某种方式中断了,但提取似乎也已完成,至少所有下载的文件在“提取的”文件夹中都有对应的文件。但是,我现在无法访问下载的数据:

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()时,它只会再次下载整个数据集。

我在这里想念东西吗?

编辑: 下载后,“解压缩”下的文件夹包含18个.tar.gz文件。

2 个答案:

答案 0 :(得分:1)

这是带有tensorflow数据集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期望的文件夹结构。

答案 1 :(得分:0)

解决方案是在初始化数据集时也使用“ data_dir”参数:

builder = tfds.image.OpenImagesV4(data_dir="/raid/openimages/dataset")
builder.download_and_prepare(download_dir="/raid/openimages/dataset")

这样,将数据集卸载并提取到同一目录中。以前,(对我而言,这是不明显的)提取到默认目录,该目录位于/home/.../下。这就是导致错误的原因,因为主目录下没有足够的空间。 提取后,文件夹结构与Manoj-Mohan完全相同。