abeardear / pytorch-YOLO-v1

an experiment for yolo-v1, including training and testing.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

I don't konw where is wrong

ladybirdhui opened this issue · comments

commented

i use pytorch1.0
I encountered some warnings and errors.
I don't know if they are important .Maybe when i tried to correct them the logic is wrong
here are the warnings and errors

1 UserWarning: nn.functional.sigmoid is deprecated. Use torch.sigmoid instead.
I replaced F.sigmoid() with torch,sigmoid in resnet_yolo.py and net.py
2 UserWarning: size_average and reduce args will be deprecated, please use reduction='sum' instead.
I replaced size_average=False with reduction='sum' in yoloLoss.py
3 IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number
I replaced loss.data[0] with loss.item() in train.py
4 UserWarning: volatile was removed and now has no effect. Use with torch.no_grad(): instead. images = Variable(images,volatile=True)
i just change it to images = images.detach()
i don't konw if it's right

My result is bad .
so anyone can tell me why
thanks

Hi, this code in repo is implemented by <pytorch 1.0, so some code in old version pytorch(such as pytorch 0.4) have been deprecated, you should change your code by using pytorch 1.0

From point 1-3 you're right, but for point 4 is not exactly right, you should change as below:
original:
images = Variable(images,volatile=True)
change to:
with torch.no_grad():
images = Variable(image)
Only this can you change directly, for ' images.detach()', after you define you variable and feed into your network, and then you don't want to optimize the variable while backward, so you need to detach this variable, and it will happen on evaluation not train, like this way:

#use it during the evaluation
output = model(input)
image = Variable(images)
image.detach()

In conclusion, after you change all code(upon all is just UserWarning, not error), you should run your network fluently, but if you can not get your expected result, please double check you dataloader or hyperparameter, thanks.

after torch0.4, volatile=true was deprecated, you should try 'with torch.no_grad()', or just reduce your batch_size, but it's just not use best of your memory