首页 > 解决方案 > 为什么我的 AutoKeras ImageClassifier 的输入为空?

问题描述

我正在尝试使用AutoKeras使用ImageClassifier类构建图像分类模型。我使用的数据集可以在这里找到。

与输入图像相关的文件结构如下所示(相对于我运行代码的位置):

'../repo/DVf/examples/datasets/pneumonia_classification'
    -train
        -NORMAL
            -image1.jpeg
            -...
        -PNEUMONIA
            -image1.jpeg
            -...

根据image_dataset_from_directory() 的文档,目录结构用于推断类标签。

这是我的代码:

import os
import autokeras as ak

# create training data set
imgs_train = ak.image_dataset_from_directory(
    os.path.join('../repo/DVf/examples/datasets/pneumonia_classification', 'train'), 
    subset='training',
    seed=1234
)
print(f"Train images: {imgs_train}")

# create the ImageClassifier
classifier = ak.ImageClassifier()
classifier.fit(imgs_train)

创建数据集的输出向我表明已找到图像,并且还检测到了两个类:

Found 5216 files belonging to 2 classes.
Train images: <BatchDataset shapes: ((None, 256, 256, 3), (None,)), types: (tf.float32, tf.string)>

这是错误和堆栈跟踪:

InvalidArgumentError: Input is empty.
     [[{{node decode_image/DecodeImage}}]] [Op:IteratorGetNext]
---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-87-e294e0af2f6a> in <module>
     12 # create the ImageClassifier
     13 classifier = ak.ImageClassifier()
---> 14 classifier.fit(imgs_train)

/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/autokeras/tasks/image.py in fit(self, x, y, epochs, callbacks, validation_split, validation_data, **kwargs)
    162                 validation loss values and validation metrics values (if applicable).
    163         """
--> 164         history = super().fit(
    165             x=x,
    166             y=y,

/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/autokeras/auto_model.py in fit(self, x, y, batch_size, epochs, callbacks, validation_split, validation_data, verbose, **kwargs)
    273             x=x, y=y, validation_data=validation_data, batch_size=batch_size
    274         )
--> 275         self._analyze_data(dataset)
    276         self._build_hyper_pipeline(dataset)
    277 

/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/autokeras/auto_model.py in _analyze_data(self, dataset)
    359         output_analysers = [head.get_analyser() for head in self._heads]
    360         analysers = input_analysers + output_analysers
--> 361         for x, y in dataset:
    362             x = nest.flatten(x)
    363             y = nest.flatten(y)

/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/tensorflow/python/data/ops/iterator_ops.py in __next__(self)
    759   def __next__(self):
    760     try:
--> 761       return self._next_internal()
    762     except errors.OutOfRangeError:
    763       raise StopIteration

/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/tensorflow/python/data/ops/iterator_ops.py in _next_internal(self)
    742     # to communicate that there is no more data to iterate over.
    743     with context.execution_mode(context.SYNC):
--> 744       ret = gen_dataset_ops.iterator_get_next(
    745           self._iterator_resource,
    746           output_types=self._flat_output_types,

/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/tensorflow/python/ops/gen_dataset_ops.py in iterator_get_next(iterator, output_types, output_shapes, name)
   2726       return _result
   2727     except _core._NotOkStatusException as e:
-> 2728       _ops.raise_from_not_ok_status(e, name)
   2729     except _core._FallbackException:
   2730       pass

/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/tensorflow/python/framework/ops.py in raise_from_not_ok_status(e, name)
   6895   message = e.message + (" name: " + name if name is not None else "")
   6896   # pylint: disable=protected-access
-> 6897   six.raise_from(core._status_to_exception(e.code, message), None)
   6898   # pylint: enable=protected-access
   6899 

~/Library/Python/3.9/lib/python/site-packages/six.py in raise_from(value, from_value)

InvalidArgumentError: Input is empty.
     [[{{node decode_image/DecodeImage}}]] [Op:IteratorGetNext]

在我看来,数据集实际上并不是空的,所以我不确定这里出了什么问题。任何人都可以帮忙吗?

标签: auto-keras

解决方案


推荐阅读