BobLiu20 / YOLOv3_PyTorch

Full implementation of YOLOv3 in PyTorch
624 stars 191 forks source link

A possible bug in training.py #17

Open lee2430 opened 6 years ago

lee2430 commented 6 years ago

Dear @BobLiu20 , thanks for sharing your code. It's wonderful, however I think there might be a bug in the loss related block of training.py:

losses = [[]] * len(losses_name)
for i in range(3):
     _loss_item = yolo_losses[i](outputs[i], labels)
     for j, l in enumerate(_loss_item):
        losses[j].append(l)
losses = [sum(l) for l in losses]
loss = losses[0]

I suppose the losses should be a 7 3 list, but actually it appear to be of the size 7 21. Every time losses[j].append(l) is executed, l is appended to each sublist of losses. And after losses = [sum(l) for l in losses] is done, all the elements of 'losses' are identical. I doubt that this behavior is not like what the code is supposed to act. If I'm right, I think this issue can be addressed by changing losses = [[]] * len(losses_name) into:

losses = []
for i in range(len(losses_name)):
    losses.append([])

or something like that.

BobLiu20 commented 6 years ago

@lee2430 Hi, You are right! This is a bug.

sordonia120446 commented 6 years ago

Looks like the issue has been resolved. @BobLiu20 I leave you the honors to close this issue.