Testing Data Not Working

Hello. I’m trying lesson one with my own data. I’ve ran the first model with my valid data set. I want to bring in resnet-50, and run with my test set as my valid dataset but it’s still pulling the original valid images.

Each set is in it’s own path:

path = ‘/home/jordan/Data/xrays/chest_xray/chest_xray/’
train_path = ‘/home/jordan/Data/xrays/chest_xray/chest_xray/train’
val_path = ‘/home/jordan/Data/xrays/chest_xray/chest_xray/val’
test_path = ‘/home/jordan/Data/xrays/chest_xray/chest_xray/test’

Then I tried to instanitiate a new imagedatabunch:

data_50 = ImageDataBunch.from_folder(train_path, train=train_path valid=test_path, ds_tfms = get_transforms(), size=224, bs=bs).normalize(imagenet_stats)

And I get the following error:


IndexError Traceback (most recent call last)
in
----> 1 data_50 = ImageDataBunch.from_folder(train_path, train=train_path, valid=test_path, ds_tfms = get_transforms(), size=224, bs=bs).normalize(imagenet_stats)

~/anaconda3/lib/python3.7/site-packages/fastai/vision/data.py in from_folder(cls, path, train, valid, valid_pct, classes, **kwargs)
108 if valid_pct is None: src = il.split_by_folder(train=train, valid=valid)
109 else: src = il.split_by_rand_pct(valid_pct)
–> 110 src = src.label_from_folder(classes=classes)
111 return cls.create_from_ll(src, **kwargs)
112

~/anaconda3/lib/python3.7/site-packages/fastai/data_block.py in _inner(*args, **kwargs)
470 assert isinstance(fv, Callable)
471 def _inner(*args, **kwargs):
–> 472 self.train = ft(*args, from_item_lists=True, **kwargs)
473 assert isinstance(self.train, LabelList)
474 kwargs[‘label_cls’] = self.train.y.class

~/anaconda3/lib/python3.7/site-packages/fastai/data_block.py in label_from_folder(self, label_cls, **kwargs)
299 “Give a label to each filename depending on its folder.”
300 return self.label_from_func(func=lambda o: (o.parts if isinstance(o, Path) else o.split(os.path.sep))[-2],
–> 301 label_cls=label_cls, **kwargs)
302
303 def label_from_re(self, pat:str, full_path:bool=False, label_cls:Callable=None, **kwargs)->‘LabelList’:

~/anaconda3/lib/python3.7/site-packages/fastai/data_block.py in label_from_func(self, func, label_cls, **kwargs)
294 def label_from_func(self, func:Callable, label_cls:Callable=None, **kwargs)->‘LabelList’:
295 “Apply func to every input to get its label.”
–> 296 return self._label_from_list([func(o) for o in self.items], label_cls=label_cls, **kwargs)
297
298 def label_from_folder(self, label_cls:Callable=None, **kwargs)->‘LabelList’:

~/anaconda3/lib/python3.7/site-packages/fastai/data_block.py in _label_from_list(self, labels, label_cls, from_item_lists, **kwargs)
269 raise Exception(“Your data isn’t split, if you don’t want a validation set, please use split_none.”)
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)

~/anaconda3/lib/python3.7/site-packages/fastai/data_block.py in get_label_cls(self, labels, label_cls, label_delim, **kwargs)
258 if self.label_cls is not None: return self.label_cls
259 if label_delim is not None: return MultiCategoryList
–> 260 it = index_row(labels,0)
261 if isinstance(it, (float, np.float32)): return FloatList
262 if isinstance(try_int(it), (str, Integral)): return CategoryList

~/anaconda3/lib/python3.7/site-packages/fastai/core.py in index_row(a, idxs)
258 if isinstance(res,(pd.DataFrame,pd.Series)): return res.copy()
259 return res
–> 260 return a[idxs]
261
262 def func_args(func)->bool:

IndexError: index 0 is out of bounds for axis 0 with size 0

Not sure what I’m doing wrong.

From what I understand, your path should be the root directory of the data. In your case, path.