snu-mllab / PuzzleMix

Official PyTorch implementation of "Puzzle Mix: Exploiting Saliency and Local Statistics for Optimal Mixup" (ICML'20)
MIT License
157 stars 17 forks source link

TypeError: forward() takes 2 positional arguments but 3 were given #13

Closed khawar-islam closed 1 year ago

khawar-islam commented 1 year ago

Hello @Janghyun1230

I am training PuzzleMix with ResNet18 and I imported resnet model from torchvision class. I made very simple chanegd net = models.__dict__[args.arch]().cuda()`` import torchvision.models as models Unfortunately, it gives an error

Traceback (most recent call last):
  File "/media/cvpr/CM_22/PuzzleMix/main.py", line 680, in <module>
    main()
  File "/media/cvpr/CM_22/PuzzleMix/main.py", line 620, in main
    tr_acc, tr_acc5, tr_los = train(train_loader, net, optimizer, epoch, args, log, mp=mp)
  File "/media/cvpr/CM_22/PuzzleMix/main.py", line 342, in train
    output, reweighted_target = model(input_var, target_var)
  File "/home/cvpr/anaconda3/envs/ICCV2023/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
    return forward_call(*input, **kwargs)
TypeError: forward() takes 2 positional arguments but 3 were given
Janghyun1230 commented 1 year ago

Hello, Khawar!

This is because our model in CIFAR experiments takes an image and a target as inputs. (see models folder)

If you want to use only an image as input, then you can refer ImageNet training code in imagenet/train.py. (you may adjust hyperparameters in imagenet/train.py for CIFAR experiments):
https://github.com/snu-mllab/PuzzleMix/blob/e2dbf3a2371026411d5741d129f46bf3eb3d3465/imagenet/train.py#L412