我正在尝试遵循在Planet Amazon数据集here上对图像进行分类的教程(也在fastai's documentation中进行了介绍),但是在使用函数label_from_df(label_delim=' ')
时遇到了问题,导致错误TypeError: argument 1 must be an iterator
。
在寻找解决方案时,我在this question上看到了SO,但是csv文件处理已在fastai上完成,所以我认为它不适合这里。
代码的上下文如下:
src = (ImageList.from_csv(path, 'data.csv', folder='images', suffix='.jpg')
.split_by_rand_pct()
.label_from_df(label_delim=' ')
)
如果需要更多代码行来理解该问题,可以提供它。
我正在使用自己的数据集在Google Colab上进行培训,尽管有可能,但我不认为csv文件或images文件夹中存在问题。
运行上述行时的错误是:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-18-69a35763cde8> in <module>()
2 src = (ImageList.from_csv(path, 'data.csv', folder='images', suffix='.jpg')
3 .split_by_rand_pct()
----> 4 .label_from_df(label_delim=' ')
5 )
3 frames
/usr/local/lib/python3.6/dist-packages/fastai/data_block.py in _inner(*args, **kwargs)
473 assert isinstance(self.train, LabelList)
474 kwargs['label_cls'] = self.train.y.__class__
--> 475 self.valid = fv(*args, from_item_lists=True, **kwargs)
476 self.__class__ = LabelLists
477 self.process()
/usr/local/lib/python3.6/dist-packages/fastai/data_block.py in label_from_df(self, cols, label_cls, **kwargs)
281 new_kwargs,label_cls = dict(one_hot=True, classes= cols),MultiCategoryList
282 kwargs = {**new_kwargs, **kwargs}
--> 283 return self._label_from_list(_maybe_squeeze(labels), label_cls=label_cls, **kwargs)
284
285 def label_const(self, const:Any=0, label_cls:Callable=None, **kwargs)->'LabelList':
/usr/local/lib/python3.6/dist-packages/fastai/data_block.py in _label_from_list(self, labels, label_cls, from_item_lists, **kwargs)
270 labels = array(labels, dtype=object)
271 label_cls = self.get_label_cls(labels, label_cls=label_cls, **kwargs)
--> 272 y = label_cls(labels, path=self.path, **kwargs)
273 res = self._label_list(x=self, y=y)
274 return res
/usr/local/lib/python3.6/dist-packages/fastai/data_block.py in __init__(self, items, classes, label_delim, one_hot, **kwargs)
407 _processor=MultiCategoryProcessor
408 def __init__(self, items:Iterator, classes:Collection=None, label_delim:str=None, one_hot:bool=False, **kwargs):
--> 409 if label_delim is not None: items = array(csv.reader(items.astype(str), delimiter=label_delim))
410 super().__init__(items, classes=classes, **kwargs)
411 if one_hot:
TypeError: argument 1 must be an iterator