2024-07-14T19:00:00Z
Given my code
##### Mixup Arguments
from timm.data.mixup import Mixup
mixup_args={
'mixup_alpha': 1., # for mixup augmentation
'cutmix_alpha': 1., # for cutmix augmentation
'prob': 1.,
'switch_prob': 0.5,
'mode': 'batch',
'label_smoothing': 0.1,
'num_classes': 4}
mixup = Mixup(**mixup_args)
dblock = DataBlock(
blocks=(ImageBlock, CategoryBlock),
get_items=get_image_files,
splitter=GrandparentSplitter(train_name='train', valid_name='valid'),
get_y=parent_label,
item_tfms=Resize(224),
batch_tfms=aug_transforms(
mult=2.0,
do_flip=True,
flip_vert=False,
max_rotate=10.0,
max_zoom=1.1,
max_lighting=0.2,
max_warp=0.2,
p_affine=0.75,
p_lighting=0.75
)
)
#### Create DataLoaders
dls = dblock.dataloaders(path, bs=16)
#### Create Vision Transformer Model
model_name = 'vit_base_patch16_224'
model = timm.create_model(model_name, pretrained=True, num_classes=dls.c)
#### Initialize Wandb
wandb.init(project=PROJECT, name='vit_basic_transforms')
#### Define Learner
learn = Learner(dls, model, loss_func=CrossEntropyLossFlat(), metrics=accuracy)
cbs = [MixedPrecision(), WandbCallback(log_preds=False), mixup]
learn.fine_tune(1, 1e-4, cbs=cbs)
I am getting following error.
>AttributeError Traceback (most recent call last)
<ipython-input-18-cea7aab980fc> in <cell line: 41>()
39
40 # Here callbacks are added with fine tuning model
---> 41 learn.fine_tune(1, 1e-4, cbs=cbs)
/usr/local/lib/python3.10/dist-packages/fastai/learner.py in add_cb(self, cb)
145 if isinstance(cb, type): cb = cb()
146 cb.learn = self
--> 147 setattr(self, cb.name, cb)
148 self.cbs.append(cb)
149 return self
> AttributeError: 'Mixup' object has no attribute 'name'
How to fix this issue?