I tried to create a databunch
by using ImageItemList
by following the documentation
(https://docs.fast.ai/data_block.html)
Here are the extract:
I could create dataloader for train_dl and train_ds but not test_dl and test_ds.
The full error message for data is:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
~/anaconda3/envs/fastai/lib/python3.6/site-packages/PIL/Image.py in open(fp, mode)
2612 try:
-> 2613 fp.seek(0)
2614 except (AttributeError, io.UnsupportedOperation):
AttributeError: 'Image' object has no attribute 'seek'
During handling of the above exception, another exception occurred:
AttributeError Traceback (most recent call last)
<timed exec> in <module>
~/fastai/fastai/data_block.py in add_test_folder(self, test_folder, label)
380 "Add test set containing items from folder `test_folder` and an arbitrary `label`."
381 items = self.x.__class__.from_folder(self.path/test_folder)
--> 382 return self.add_test(items.items, label=label)
383
384 class LabelList(Dataset):
~/fastai/fastai/data_block.py in add_test(self, items, label)
374 labels = [label for _ in range_of(items)]
375 if isinstance(items, ItemList): self.test = self.valid.new(items.items, labels, xtra=items.xtra)
--> 376 else: self.test = self.valid.new(items, labels)
377 return self
378
~/fastai/fastai/data_block.py in new(self, x, y, **kwargs)
405 return self.__class__(x, y, tfms=self.tfms, tfm_y=self.tfm_y, **self.tfmargs)
406 else:
--> 407 return self.new(self.x.new(x, **kwargs), self.y.new(y, **kwargs)).process()
408
409 def __getattr__(self,k:str)->Any:
~/fastai/fastai/data_block.py in new(self, x, y, **kwargs)
405 return self.__class__(x, y, tfms=self.tfms, tfm_y=self.tfm_y, **self.tfmargs)
406 else:
--> 407 return self.new(self.x.new(x, **kwargs), self.y.new(y, **kwargs)).process()
408
409 def __getattr__(self,k:str)->Any:
~/fastai/fastai/data_block.py in new(self, x, y, **kwargs)
405 return self.__class__(x, y, tfms=self.tfms, tfm_y=self.tfm_y, **self.tfmargs)
406 else:
--> 407 return self.new(self.x.new(x, **kwargs), self.y.new(y, **kwargs)).process()
408
409 def __getattr__(self,k:str)->Any:
~/fastai/fastai/data_block.py in new(self, items, processor, **kwargs)
77 def new(self, items:Iterator, processor:PreProcessor=None, **kwargs)->'ItemList':
78 processor = ifnone(processor, self.processor)
---> 79 return self.__class__(items=items, processor=processor, path=self.path, x=self.x, **kwargs)
80
81 def __getitem__(self,idxs:int)->Any:
~/fastai/fastai/data_block.py in __init__(self, items, path, label_cls, xtra, processor, x, **kwargs)
43 self.path = Path(path)
44 self.num_parts = len(self.path.parts)
---> 45 self.items,self.x = array(items, dtype=object),x
46 self.label_cls,self.xtra,self.processor = ifnone(label_cls,self._label_cls),xtra,processor
47 self._label_list,self._split = LabelList,ItemLists
~/fastai/fastai/core.py in array(a, *args, **kwargs)
218 "Same as `np.array` but also handles generators"
219 if not isinstance(a, collections.Sized): a = list(a)
--> 220 return np.array(a, *args, **kwargs)
221
222 class Category(ItemBase):
~/fastai/fastai/data_block.py in __getitem__(self, idxs)
80
81 def __getitem__(self,idxs:int)->Any:
---> 82 if isinstance(try_int(idxs), int): return self.get(idxs)
83 else: return self.new(self.items[idxs], xtra=index_row(self.xtra, idxs))
84
~/fastai/fastai/vision/data.py in get(self, i)
288 def get(self, i):
289 fn = super().get(i)
--> 290 res = self.open(fn)
291 self.sizes[i] = res.size
292 return res
~/fastai/fastai/vision/data.py in open(self, fn)
284 self.sizes={}
285
--> 286 def open(self, fn): return open_image(fn)
287
288 def get(self, i):
~/fastai/fastai/vision/image.py in open_image(fn, div, convert_mode, cls)
440 "Return `Image` object created from image in file `fn`."
441 #fn = getattr(fn, 'path', fn)
--> 442 x = PIL.Image.open(fn).convert(convert_mode)
443 x = pil2tensor(x,np.float32)
444 if div: x.div_(255)
~/anaconda3/envs/fastai/lib/python3.6/site-packages/PIL/Image.py in open(fp, mode)
2613 fp.seek(0)
2614 except (AttributeError, io.UnsupportedOperation):
-> 2615 fp = io.BytesIO(fp.read())
2616 exclusive_fp = True
2617
AttributeError: 'Image' object has no attribute 'read'
I have the “train” and “test” folders as required.
PS. I did git pull few minutes ago before running these codes (v.1.0.28).