Training with .mat files

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)
in
----> 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 split_by_rand_pct(self, valid_pct, seed)
220 if valid_pct==0.: return self.split_none()
221 if seed is not None: np.random.seed(seed)
–> 222 rand_idx = np.random.permutation(range_of(self))
223 cut = int(valid_pct * len(self))
224 return self.split_by_idx(rand_idx[:cut])

TypeError: len() of unsized object

you can not load mat files directly. you have to use scipy.io library and define a function for it. something like :

   from scipy.io import loadmat

   mat_files = get_files(path_mat)
   mat_names = set([os.path.splitext(f.name)[0] for f in mat_files]);mat_names

 for n in mat_names:
      lbz=[]; %variables
      lbz = loadmat(path_mat+'/'+n+'.mat')
      [do somethings for f in [*lbz]]

can u explain what that code does?

once you load a single mat file with loadmat it returns variables. So the code may be used to get variable names in a matlab file and do something with it.