tensorflow - 使用 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 文件。
解决方案
这适用于 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 期望的文件夹结构。
推荐阅读
- python - 安装张量流导致超时
- python - 如何在 PyQt5 应用程序中将自定义切换工具添加到 matplotlib 工具栏?
- sql - Presto 查询没有得到正确的值
- graphql - 如何将 gatsby-image 与对象数组一起使用?
- python-3.x - DataFrame 显示不符合预期
- sas - SG Panel (SAS 9.4) 中 x 轴上的不同值
- jquery - if/else 语句不能与 .html() 一起正常工作;和字体很棒的图标
- python - 如何在单元测试中创建假对象?
- awk - 使用 grep / sed 用分号替换列表中的值,换行作为分隔符
- javascript - 在 React 功能组件中取消异步 axios 请求的正确方法