I’m using Salamander.
Attempting to run:
np.random.seed(2)
pat = r'/([^/]+)_\d+.jpg$
data = ImageDataBunch.from_name_re(path_img, fnames, pat, ds_tfms=get_transforms(), size=24, bs=bs).normalize(imagenet_stats)
and i get this error:
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-126-ecaa07fc186b> in <module>
----> 1 data = ImageDataBunch.from_name_re(path_img, fnames, pat, ds_tfms=get_transforms(), size=24, bs=bs).normalize(imagenet_stats)
2
~/anaconda3/lib/python3.7/site-packages/fastai/vision/data.py in from_name_re(cls, path, fnames, pat, valid_pct, **kwargs)
156 assert res,f'Failed to find "{pat}" in "{fn}"'
157 return res.group(1)
--> 158 return cls.from_name_func(path, fnames, _get_label, valid_pct=valid_pct, **kwargs)
159
160 @staticmethod
~/anaconda3/lib/python3.7/site-packages/fastai/vision/data.py in from_name_func(cls, path, fnames, label_func, valid_pct, seed, **kwargs)
145 "Create from list of `fnames` in `path` with `label_func`."
146 src = ImageList(fnames, path=path).split_by_rand_pct(valid_pct, seed)
--> 147 return cls.create_from_ll(src.label_from_func(label_func), **kwargs)
148
149 @classmethod
~/anaconda3/lib/python3.7/site-packages/fastai/vision/data.py in create_from_ll(cls, lls, bs, val_bs, ds_tfms, num_workers, dl_tfms, device, test, collate_fn, size, no_check, resize_method, mult, padding_mode, mode, tfm_y)
95 "Create an `ImageDataBunch` from `LabelLists` `lls` with potential `ds_tfms`."
96 lls = lls.transform(tfms=ds_tfms, size=size, resize_method=resize_method, mult=mult, padding_mode=padding_mode,
---> 97 mode=mode, tfm_y=tfm_y)
98 if test is not None: lls.add_test_folder(test)
99 return lls.databunch(bs=bs, val_bs=val_bs, dl_tfms=dl_tfms, num_workers=num_workers, collate_fn=collate_fn,
~/anaconda3/lib/python3.7/site-packages/fastai/data_block.py in transform(self, tfms, **kwargs)
500 if not tfms: tfms=(None,None)
501 assert is_listy(tfms) and len(tfms) == 2, "Please pass a list of two lists of transforms (train and valid)."
--> 502 self.train.transform(tfms[0], **kwargs)
503 self.valid.transform(tfms[1], **kwargs)
504 if self.test: self.test.transform(tfms[1], **kwargs)
~/anaconda3/lib/python3.7/site-packages/fastai/data_block.py in transform(self, tfms, tfm_y, **kwargs)
719 def transform(self, tfms:TfmList, tfm_y:bool=None, **kwargs):
720 "Set the `tfms` and `tfm_y` value to be applied to the inputs and targets."
--> 721 _check_kwargs(self.x, tfms, **kwargs)
722 if tfm_y is None: tfm_y = self.tfm_y
723 tfms_y = None if tfms is None else list(filter(lambda t: getattr(t, 'use_on_y', True), listify(tfms)))
~/anaconda3/lib/python3.7/site-packages/fastai/data_block.py in _check_kwargs(ds, tfms, **kwargs)
588 if (tfms is None or len(tfms) == 0) and len(kwargs) == 0: return
589 if len(ds.items) >= 1:
--> 590 x = ds[0]
591 try: x.apply_tfms(tfms, **kwargs)
592 except Exception as e:
~/anaconda3/lib/python3.7/site-packages/fastai/data_block.py in __getitem__(self, idxs)
116 "returns a single item based if `idxs` is an integer or a new `ItemList` object if `idxs` is a range."
117 idxs = try_int(idxs)
--> 118 if isinstance(idxs, Integral): return self.get(idxs)
119 else: return self.new(self.items[idxs], inner_df=index_row(self.inner_df, idxs))
120
~/anaconda3/lib/python3.7/site-packages/fastai/vision/data.py in get(self, i)
269 def get(self, i):
270 fn = super().get(i)
--> 271 res = self.open(fn)
272 self.sizes[i] = res.size
273 return res
~/anaconda3/lib/python3.7/site-packages/fastai/vision/data.py in open(self, fn)
265 def open(self, fn):
266 "Open image in `fn`, subclass and overwrite for custom behavior."
--> 267 return open_image(fn, convert_mode=self.convert_mode, after_open=self.after_open)
268
269 def get(self, i):
~/anaconda3/lib/python3.7/site-packages/fastai/vision/image.py in open_image(fn, div, convert_mode, cls, after_open)
391 with warnings.catch_warnings():
392 warnings.simplefilter("ignore", UserWarning) # EXIF warning from TiffPlugin
--> 393 x = PIL.Image.open(fn).convert(convert_mode)
394 if after_open: x = after_open(x)
395 x = pil2tensor(x,np.float32)
~/anaconda3/lib/python3.7/site-packages/PIL/Image.py in open(fp, mode)
2703 warnings.warn(message)
2704 raise IOError("cannot identify image file %r"
-> 2705 % (filename if filename else fp))
2706
2707 #
OSError: cannot identify image file PosixPath('/home/ubuntu/.fastai/data/oxford-iiit-pet/images/saint_bernard_188.jpg')
anyone know why? I’m guessing its the issue with not being able to identify PosixPath but when i run this cell:
path.ls()
i get an output of:
[PosixPath('/home/ubuntu/.fastai/data/oxford-iiit-pet/images'),
PosixPath('/home/ubuntu/.fastai/data/oxford-iiit-pet/annotations')]
so i’m confused why i’m getting the issue with not being able to identify the image file PosixPath