Multiple transformations in batch_tfms while creating an ImageDataLoader

I’m having trouble trying to use aug_transforms() and Normalize.from_stats(*imagenet_stats) in batch_tfms.

On the following code:

data = ImageDataLoaders.from_df(df=df_styles, path=pictures_dir,
                              label_col='style', fn_col='new_filename',
                              y_block=CategoryBlock(),
                              item_tfms=Resize(299),
                              batch_tfms=[aug_transforms(flip_vert=True, max_lighting=0, max_warp=0, p_lighting=0), Normalize.from_stats(*imagenet_stats)],
                              bs=64
                              )

I’m getting this error:

Could not do one pass in your dataloader, there is something wrong in it. Please see the stack trace below:
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-11-18df54108bfa> in <cell line: 1>()
----> 1 data = ImageDataLoaders.from_df(df=df_styles, path=pictures_dir,
      2                               label_col='style', fn_col='new_filename',
      3                               y_block=CategoryBlock(),
      4                               item_tfms=Resize(299),
      5                               batch_tfms=[aug_transforms(flip_vert=True, max_lighting=0, max_warp=0, p_lighting=0), Normalize.from_stats(*imagenet_stats)],

14 frames
/usr/local/lib/python3.10/dist-packages/fastcore/dispatch.py in __call__(self, *args, **kwargs)
    118         elif self.inst is not None: f = MethodType(f, self.inst)
    119         elif self.owner is not None: f = MethodType(f, self.owner)
--> 120         return f(*args, **kwargs)
    121 
    122     def __get__(self, inst, owner):

TypeError: 'list' object is not callable

If I use batch_tfms=aug_transforms(flip_vert=True, max_lighting=0, max_warp=0, p_lighting=0) or batch_tfms=Normalize.from_stats(*imagenet_stats) there is no problem, but I want to use both transformations. How can I do that?

Thanks in advance.

aug_transforms returns a list, so you need to unpack it into your batch_tfms list:

batch_tfms = [*aug_transforms(...), Normalize.from_stats(*imagenet_stats)]