I had run this code with a very simple regular expression as you can see /d{4} . But i am getting a error which says Failed to find {pat}
in the log. Does this mean my reg expression is wrong?. Also the error says len() of unsized object.
I am not sure what caused this error. Pls let me know where i went wrong. Thanks for any help
%reload_ext autoreload
%autoreload 2
%matplotlib inline
from fastai.vision import *
from fastai.metrics import error_rate
from mat4py import loadmat
from pylab import*
import matplotlib
import os
import numpy as np # linear algebra
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
os.chdir('/Users/Ashi/Downloads/TrainingSet2')
for dirname,_,filenames in os.walk('/Users/Ashi/Downloads/TrainingSet2' ):
for filename in filenames:
print(os.path.join(dirname, filename))
path = ('/Users/Ashi/Downloads/TrainingSet2')
np.random.seed(2)
pat = r'\d{4}'
data = ImageDataBunch.from_name_re(path, filename, pat, ds_tfms=get_transforms(), size=224)
data.normalize(imagenet_stats)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-64-020843a0540e> in <module>
----> 1 data = ImageDataBunch.from_name_re(path, filename, pat, ds_tfms=get_transforms(), size=224)
2 #data.normalize(imagenet_stats)
~/opt/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
~/opt/anaconda3/lib/python3.7/site-packages/fastai/vision/data.py in from_name_func(cls, path, fnames, label_func, valid_pct, seed, **kwargs)
144 **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
........
~/opt/anaconda3/lib/python3.7/site-packages/fastai/data_block.py in _len_(self)
70 self.copy_new = ['x', 'label_cls', 'path']
71
---> 72 def _len_(self)->int: return len(self.items) or 1
73 def get(self, i)->Any:
74 "Subclass if you want to customize how to create item `i` from `self.items`."
TypeError: len() of unsized object