fastai v1
When I tried
data = ImageDataBunch.from_folder(path, ds_tfms=tfms, size=224)
came back with index error
My directory structure
Data_folder
– Folder1
– Folder2
– Folder3
– Folder4
IndexError: index 0 is out of bounds for axis 0 with size 0
full error report
IndexError Traceback (most recent call last)
in ()
----> 1 data = ImageDataBunch.from_folder(path, ds_tfms=tfms)
/usr/local/lib/python3.6/dist-packages/fastai/vision/data.py in from_folder(cls, path, train, valid, valid_pct, classes, **kwargs)
114 if valid_pct is None: src = il.split_by_folder(train=train, valid=valid)
115 else: src = il.random_split_by_pct(valid_pct)
–> 116 src = src.label_from_folder(classes=classes)
117 return cls.create_from_ll(src, **kwargs)
118
/usr/local/lib/python3.6/dist-packages/fastai/data_block.py in _inner(*args, **kwargs)
256 assert isinstance(fv, Callable)
257 def _inner(*args, **kwargs):
–> 258 self.train = ft(*args, **kwargs)
259 assert isinstance(self.train, LabelList)
260 self.valid = fv(*args, template=self.train.y, **kwargs)
/usr/local/lib/python3.6/dist-packages/fastai/data_block.py in label_from_folder(self, **kwargs)
200 def label_from_folder(self, **kwargs)->‘LabelList’:
201 “Give a label to each filename depending on its folder.”
–> 202 return self.label_from_func(func=lambda o: o.parent.name, **kwargs)
203
204 def label_from_re(self, pat:str, full_path:bool=False, **kwargs)->‘LabelList’:
/usr/local/lib/python3.6/dist-packages/fastai/data_block.py in label_from_func(self, func, **kwargs)
196 def label_from_func(self, func:Callable, **kwargs)->‘LabelList’:
197 “Apply func
to every input to get its label.”
–> 198 return self.label_from_list([func(o) for o in self.items], **kwargs)
199
200 def label_from_folder(self, **kwargs)->‘LabelList’:
/usr/local/lib/python3.6/dist-packages/fastai/data_block.py in label_from_list(self, labels, label_cls, template, **kwargs)
176 “Label self.items
with labels
using label_cls
and optionally template
.”
177 labels = array(labels, dtype=object)
–> 178 label_cls = self.label_cls(labels, label_cls)
179 y_bld = label_cls if template is None else template.new
180 y = y_bld(labels, **kwargs)
/usr/local/lib/python3.6/dist-packages/fastai/data_block.py in label_cls(self, labels, lc)
168 if lc is not None: return lc
169 if self._label_cls is not None: return self._label_cls
–> 170 it = try_int(index_row(labels,0))
171 if isinstance(it, (str,int)): return CategoryList
172 if isinstance(it, Collection): return MultiCategoryList
/usr/local/lib/python3.6/dist-packages/fastai/core.py in index_row(a, idxs)
227 if isinstance(res,(pd.DataFrame,pd.Series)): return res.copy()
228 return res
–> 229 return a[idxs]
230
231 def func_args(func)->bool:
IndexError: index 0 is out of bounds for axis 0 with size 0