sail-sg / volo

VOLO: Vision Outlooker for Visual Recognition

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AttributeError: 'tuple' object has no attribute 'log_softmax'

SamratSahoo opened this issue · comments

I was trying to train VOLO on some custom data using the following command

!python3 main.py -data_dir "/content/dataset" --dataset "ImageFolder" --train-split "train" --val-split "valid" --num-classes 3 --epochs 100 --batch-size 64

Unfortunately, I keep on getting the following error:

Traceback (most recent call last):
  File "main.py", line 948, in <module>
    main()
  File "main.py", line 664, in main
    optimizers=optimizers)
  File "main.py", line 783, in train_one_epoch
    loss = loss_fn(output, target)
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/timm/loss/cross_entropy.py", line 35, in forward
    loss = torch.sum(-target * F.log_softmax(x, dim=-1), dim=-1)
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/functional.py", line 1768, in log_softmax
    ret = input.log_softmax(dim)
AttributeError: 'tuple' object has no attribute 'log_softmax'

Any advice on how I can go about fixing this or what is causing this error to occur?

I was trying to train VOLO on some custom data using the following command

!python3 main.py -data_dir "/content/dataset" --dataset "ImageFolder" --train-split "train" --val-split "valid" --num-classes 3 --epochs 100 --batch-size 64

Unfortunately, I keep on getting the following error:

Traceback (most recent call last):
  File "main.py", line 948, in <module>
    main()
  File "main.py", line 664, in main
    optimizers=optimizers)
  File "main.py", line 783, in train_one_epoch
    loss = loss_fn(output, target)
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/timm/loss/cross_entropy.py", line 35, in forward
    loss = torch.sum(-target * F.log_softmax(x, dim=-1), dim=-1)
  File "/usr/local/lib/python3.7/dist-packages/torch/nn/functional.py", line 1768, in log_softmax
    ret = input.log_softmax(dim)
AttributeError: 'tuple' object has no attribute 'log_softmax'

Any advice on how I can go about fixing this or what is causing this error to occur?

Try to use output[0] when you run it without token labeling. Because in the line 645 in volo.py, it returns a tuple(x_cls, x_aux, (bbx1, bby1, bbx2, bby2), or you can just comment out the last two variables and only return x_cls or x_aux.mean()

Thank you, that worked