densenet-pytorch icon indicating copy to clipboard operation
densenet-pytorch copied to clipboard

IndexError: : invalid index of a 0-dim tensor

Open NeNeSakura opened this issue 3 years ago • 1 comments

Hello there! Very happy to use your code, I have a question looking forward to your reply! In ``train.py"

losses.update(loss.data[0], input.size(0)) top1.update(prec1[0], input.size(0))

loss.data seems just a number (torch.Size([])) and does no have index 0.

NeNeSakura avatar Aug 16 '21 23:08 NeNeSakura

I couldn't do it with a similar error. I fixed the following 4 places and it worked. Delete the indexes on lines 168,169 and 214,215. losses.update(loss.data, input.size(0)) top1.update(prec1, input.size(0))

In my environment, I also changed the following two places. target = target.cuda() on lines 157,203 Removed the argument async=True .

environment: pip3 list|grep torch torch 1.10.0+cu113 torchaudio 0.10.0+cu113 torchsummary 1.5.1 torchvision 0.11.1+cu113

Thank you.

nis243 avatar Jan 06 '22 06:01 nis243