andy-yun / pytorch-0.4-yolov3

Yet Another Implimentation of Pytroch 0.4.1 and YoloV3 on python3
MIT License
279 stars 72 forks source link

ValueError: only one element tensors can be converted to Python scalars #9

Closed olgapeled closed 6 years ago

olgapeled commented 6 years ago

Hi,

First of all, great job!!

Second, I am trying to train on voc data (or even my own data).

  1. In test function, when the batch size > 1 and len(gpus) > 1 then I receive the error:

Traceback (most recent call last): File "/home/o/workspace/pytorch-0.4-yolov3/train.py", line 350, in main() File "/home/o/workspace/pytorch-0.4-yolov3/train.py", line 144, in main fscore = test(epoch) File "/home/o/workspace/pytorch-0.4-yolov3/train.py", line 307, in test all_boxes = get_all_boxes(output, conf_thresh, num_classes, use_cuda=use_cuda) File "/home/o/workspace/pytorch-0.4-yolov3/utils.py", line 111, in get_all_boxes pred, anchors, num_anchors = output[i]['x'].data, output[i]['a'], output[i]['n'].item() ValueError: only one element tensors can be converted to Python scalars

The main problem is here : output[i]['n'].item() because output[i]['n'] contains two values and not only one...

How can I fix it?

  1. When I only do train without test, the loss is not reduced over epochs. Did someone succeeded to train on voc data? I want to succeed to train on voc data before I am starting with my own data.

Thank You!!!

Olgit

andy-yun commented 6 years ago

1) try output[i]['n'][0].item() 2) many people succeed voc data evaluations. please refer to https://github.com/marvis/pytorch-yolo2 or marvis/pytorch-yolo3 for detailed procedures. The same procedure can be applied.

andy-yun commented 6 years ago

I am sorry I am late. I am developed the program in my PC with one GPU. Therefore I did not find the problem. I upgraded the pytorch 0.3 to pytorch 0.4.1. on my linux machine with two GPUs. The case as you pointed is found. I fixed. Thank you for your reporting.