gpt4 book ai didi

python - 类型对象 'Food101' 没有属性 'load_data'

转载 作者:行者123 更新时间:2023-12-01 07:23:30 25 4
gpt4 key购买 nike

我写了这段代码:

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'

我应该怎样做才能克服这个错误?

最佳答案

从 Tensorflow 页面加载数据集的正确方法是:

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

因此,在您的代码中您应该加载它:

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

如果这不起作用,加载它的构建器:

builder = tfds.builder("tfds.image.food101.Food101")
builder.download_and_prepare()
datasets = builder.as_dataset()

Reference Dataset

关于python - 类型对象 'Food101' 没有属性 'load_data',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57561668/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com