类型对象“ Food101”没有属性“ load_data”

时间:2019-08-19 17:48:11

标签: python tensorflow

我写了这段代码:

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf

import tensorflow_datasets as tfds

food = tfds.image.food101.Food101
(train_images, train_labels), (test_images, test_labels) = food.load_data()

我收到以下错误:

AttributeError
Traceback (most recent call last)
<ipython-input-10-92f141508c7c> in <module>()
            9 import tensorflow_datasets as tfds
         1  0 food = tfds.image.food101.Food101
      ---> 11 (train_images, train_labels), (test_images, test_labels) = 
      food.load_data()
AttributeError: type object 'Food101' has no attribute 'load_data'

我该怎么做才能克服此错误?

2 个答案:

答案 0 :(得分:1)

在Tensorflow页面上,加载数据集的正确方法是:

49

因此,在您的代码中应使用以下代码加载它:

data, info = tfds.load("desired_dataset", with_info=True)

如果这不起作用,请加载其构建器

food, info = tfds.load("food101", with_info=True)

Reference Dataset

答案 1 :(得分:0)

用于加载TensorFlow数据集的代码如下:

import tensorflow_datasets as tfds

food_images, food_labels = tfds.load(name='food101', split=tfds.Split.TRAIN)

但是不幸的是,在当前最新版本的TensorFlow数据集(1.1.0)中,不存在Food101数据集。 您可以1.1.0 GitHub version检查一下food101.py文件是否丢失,但是如果更改为master分支,则会出现food101.py。如果您需要food101.py,则必须从源代码构建TensorFlow数据集,或者直接从下载链接下载数据集。