Pytorch-yolov3: Test and eval are not right! model(x) in eval mode output all nan.

Created on 31 Oct 2018  路  8Comments  路  Source: eriklindernoren/PyTorch-YOLOv3

The training stage seems good. But when detect and test, the output of model(x) are all nan even after the first conv layer? Anybody know why?

Most helpful comment

The save_weights and load_weights functions are not saving/loading all the weights. Some are left uninitialized, which most likely causes a division by zero somewhere. A workaround would be to save and load the state_dict instead of manually going through layers. E.g. torch.save(model.state_dict(), "model.weights") and model.load_state_dict(torch.load("model.weights")).

All 8 comments

I have the same problem.

I have the same issue, the detect.py doesn't work on the newly trained net. output 0s, through the train stage looks good.

The save_weights and load_weights functions are not saving/loading all the weights. Some are left uninitialized, which most likely causes a division by zero somewhere. A workaround would be to save and load the state_dict instead of manually going through layers. E.g. torch.save(model.state_dict(), "model.weights") and model.load_state_dict(torch.load("model.weights")).

thanks for the suggestion @jclevesque, I checked this works!

Thanks @jclevesque, it works in PyTorch 1.0. I wonder how it worked with load_weights at the first place. Maybe only on PyTorch 0.4.

Great observation @jclevesque . I have changed to saving and loading state dicts instead in master.This seems to solve the issue with checkpoint models producing junk when evaluated. There is probably an issue in Darknet.save_weights.

@eriklindernoren I am getting nan values in outputs during evaluation even with pre-trained yolo weights without any finetuning. Is it because I am trying to detect objects which are not in MS COCO dataset?

@eriklindernoren I could solve this issue by running my model in train mode. I have this issue only in eval mode. But could you please suggest why is it happening?

Was this page helpful?
0 / 5 - 0 ratings