0

I'm trying to use fastai to train a model however I get this error when I try to normalize my data using imagenet stats. After searching for a while, I can't find any valid substitute for this line.

Do you have a solution?

def train():
    data_directory = Path('Data_spec/')
    data = ImageDataLoaders.from_folder(data_directory, ds_tfms=[], size=16)
    data.normalize(imagenet_stats) # HERE
    learn = cnn_learner(data, models.resnet34, metrics=error_rate)
    learn.fit_one_cycle(3)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-138-2da0ffaf5447> in <module>()
----> 1 train()

4 frames /usr/local/lib/python3.7/dist-packages/fastcore/transform.py in gather_attrs(o, k, nm) 171 att = getattr(o,nm) 172 res = [t for t in att.attrgot(k) if t is not None] --> 173 if not res: raise AttributeError(k) 174 return res[0] if len(res)==1 else L(res) 175

AttributeError: normalize ```

n_prime
  • 65
  • 6

1 Answers1

0

This is the solution I found.

batch_tfms = [IntToFloatTensor(), Normalize.from_stats(*imagenet_stats)]
data = ImageDataLoaders.from_folder(data_directory, ds_tfms=batch_tfms, size=16)
n_prime
  • 65
  • 6