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

IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number

Open 595448755 opened this issue 5 years ago • 1 comments

Run the command : CUDA_VISIBLE_DEVICES=0,1 python main.py something RGB
--arch BNInception --num_segments 3
--consensus_type TRN --batch-size 64 IT woud be error

Freezing BatchNorm2D except the first one. Traceback (most recent call last): File "main.py", line 322, in main() File "main.py", line 128, in main train(train_loader, model, criterion, optimizer, epoch, log_training) File "main.py", line 175, in train losses.update(loss.data[0], input.size(0)) IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number

the one takes error ubuntu18 + rtx2080ti + cuda10 + cudnn7.4.2 + pytorch 1.0 + python3.6

the other one won't error ubuntu16 + gtx1080ti + cuda8 + cudnn5.1.10 + pytorch 0.3.1 + python3.5

595448755 avatar May 15 '19 08:05 595448755

modify main.py line 175-177
#losses.update(loss.data[0], input.size(0)) #top1.update(prec1[0], input.size(0)) #top5.update(prec5[0], input.size(0))

to losses.update(loss.item(), input.size(0)) top1.update(loss.item(), input.size(0)) top5.update(loss.item(), input.size(0))

then won't be error, start the iteration.

595448755 avatar May 15 '19 08:05 595448755