ssd.pytorch icon indicating copy to clipboard operation
ssd.pytorch copied to clipboard

non-static forward method will be removed in 1.3

Open BingkunZhao opened this issue 5 years ago • 18 comments
trafficstars

Hi, the version of my pytorch is 1.3. and the python version is 3.6. when I run the code

y = net(x)

which is for the detection. the warning is arise: UserWarning: Legacy autograd function with non-static forward method is deprecated and will be removed in 1.3. Please use new-style autograd function with static forward method. (Example: https://pytorch.org/docs/stable/autograd.html#torch.autograd.Function)

I am very confused about how to solve that problem, so is there anyone have a clue?

BingkunZhao avatar Dec 11 '19 03:12 BingkunZhao

I have same problem like you. my torch version is 1.4.0. But it seems that the problem has no effect to training. have you solve it?

qcy007 avatar Feb 28 '20 15:02 qcy007

Degrade the pytorch version to 1.2.0 or below will solve this problem.

kevinchan04 avatar Apr 29 '20 06:04 kevinchan04

Hi, the version of my pytorch is 1.3. and the python version is 3.6. when I run the code

y = net(x)

which is for the detection. the warning is arise: UserWarning: Legacy autograd function with non-static forward method is deprecated and will be removed in 1.3. Please use new-style autograd function with static forward method. (Example: https://pytorch.org/docs/stable/autograd.html#torch.autograd.Function)

I am very confused about how to solve that problem, so is there anyone have a clue? Did you get the solution ?

brijhub avatar May 04 '20 17:05 brijhub

Hi, version of colab is PyTorch1.5.0, I modified detection.py and ssd.py. so that it works without warning and error.

Since detection.py have torch.autograd.Function, I delete def init() and add @staticmethod. I also add output = self.detect.apply() in ssd.py.

I share my code and you can find in '# PyTorch1.5.0 support new-style autograd function' in source. https://github.com/miyamotok0105/pytorch_handbook/blob/master/chapter7/layers/functions/detection.py

ayukat1016 avatar May 08 '20 00:05 ayukat1016

@ayukat1016 hello.I have modified the detection file.I am confused about where to add output = self.detection. apply() in the ssd.py file.

fywsjz avatar May 22 '20 01:05 fywsjz

@fywsjz Hello. You can find in line 63, 123. https://github.com/miyamotok0105/pytorch_handbook/blob/master/chapter7/ssd.py

ayukat1016 avatar May 22 '20 02:05 ayukat1016

@ayukat1016 Thank you very much. It worked

fywsjz avatar May 22 '20 03:05 fywsjz

Hi, version of colab is PyTorch1.5.0, I modified detection.py and ssd.py. so that it works without warning and error.

Since detection.py have torch.autograd.Function, I delete def init() and add @staticmethod. I also add output = self.detect.apply() in ssd.py.

I share my code and you can find in '# PyTorch1.5.0 support new-style autograd function' in source. https://github.com/miyamotok0105/pytorch_handbook/blob/master/chapter7/layers/functions/detection.py

うまく動作する様になりました、ありがとうございます!

decoli avatar May 28 '20 03:05 decoli

Hi, version of colab is PyTorch1.5.0, I modified detection.py and ssd.py. so that it works without warning and error.

Since detection.py have torch.autograd.Function, I delete def init() and add @staticmethod. I also add output = self.detect.apply() in ssd.py.

I share my code and you can find in '# PyTorch1.5.0 support new-style autograd function' in source. https://github.com/miyamotok0105/pytorch_handbook/blob/master/chapter7/layers/functions/detection.py

Hi, it can work well like below:

Finished loading model!
im_detect: 1/4952 1.888s
im_detect: 2/4952 0.145s
...

Evaluating detections
Writing aeroplane VOC results file
Writing bicycle VOC results file
...

VOC07 metric? Yes

But after that, it will error: Exception has occurred: KeyError at 317, eval.py R = class_recs[image_ids[d]]

And here:

class_recs
{}

image_ids
['000002', '000002', '000002', '000002', '000002', '000002', '000003']

d
0

Do you know what here happening and can you help me? For the time being, I opened new issue here

decoli avatar May 28 '20 08:05 decoli

I have not encountered the problem you described, you can try to find the answer in the issues at github, sorry for not being able to help you

| | 封亚炜 | | [email protected] | 签名由网易邮箱大师定制 On 5/28/2020 16:43,Shirui Zhang[email protected] wrote:

Hi, version of colab is PyTorch1.5.0, I modified detection.py and ssd.py. so that it works without warning and error.

Since detection.py have torch.autograd.Function, I delete def init() and add @staticmethod. I also add output = self.detect.apply() in ssd.py.

I share my code and you can find in '# PyTorch1.5.0 support new-style autograd function' in source. https://github.com/miyamotok0105/pytorch_handbook/blob/master/chapter7/layers/functions/detection.py

Hi, it can work well like below:

Finished loading model! im_detect: 1/4952 1.888s im_detect: 2/4952 0.145s ...

Evaluating detections Writing aeroplane VOC results file Writing bicycle VOC results file ...

VOC07 metric? Yes

But after that, it will error: Exception has occurred: KeyError at 317, eval.py R = class_recs[image_ids[d]]

And here:

class_recs {}

image_ids ['000002', '000002', '000002', '000002', '000002', '000002', '000003']

d 0

Do you know what here happening and can you help me?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

fywsjz avatar May 28 '20 09:05 fywsjz

I have not encountered the problem you described, you can try to find the answer in the issues at github, sorry for not being able to help you | | 封亚炜 | | [email protected] | 签名由网易邮箱大师定制 On 5/28/2020 16:43,Shirui Zhang[email protected] wrote: Hi, version of colab is PyTorch1.5.0, I modified detection.py and ssd.py. so that it works without warning and error. Since detection.py have torch.autograd.Function, I delete def init() and add @staticmethod. I also add output = self.detect.apply() in ssd.py. I share my code and you can find in '# PyTorch1.5.0 support new-style autograd function' in source. https://github.com/miyamotok0105/pytorch_handbook/blob/master/chapter7/layers/functions/detection.py Hi, it can work well like below: Finished loading model! im_detect: 1/4952 1.888s im_detect: 2/4952 0.145s ... Evaluating detections Writing aeroplane VOC results file Writing bicycle VOC results file ... VOC07 metric? Yes But after that, it will error: Exception has occurred: KeyError at 317, eval.py R = class_recs[image_ids[d]] And here: class_recs {} image_ids ['000002', '000002', '000002', '000002', '000002', '000002', '000003'] d 0 Do you know what here happening and can you help me? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

Thanks anyway.

decoli avatar May 28 '20 12:05 decoli

Hi, version of colab is PyTorch1.5.0, I modified detection.py and ssd.py. so that it works without warning and error.

Since detection.py have torch.autograd.Function, I delete def init() and add @staticmethod. I also add output = self.detect.apply() in ssd.py.

I share my code and you can find in '# PyTorch1.5.0 support new-style autograd function' in source. https://github.com/miyamotok0105/pytorch_handbook/blob/master/chapter7/layers/functions/detection.py

Hi, I modified detection.py and ssd.py as yours.

Then I tried running eval.py, and actually got this problem:

RuntimeError: CUDA out of memory. Tried to allocate 4.08 GiB (GPU 0; 8.00 GiB total capacity; 200.34 MiB already allocated; 5.04 GiB free; 958.00 MiB reserved in total by PyTorch)

The GPU on the machine is 2070 super. In my opinion, its performance should be sufficient.

Then also I tried running eval.py by --cuda False, and it can run: ... im_detect: 997/4952 0.320s im_detect: 998/4952 0.343s ...

Why can't it run on GPU? Do you have any ideas?


Win 10 Python 3.6.8 Pytorch 1.5.1 Cuda V11.0.167

decoli avatar Jun 19 '20 16:06 decoli

@fywsjz Hello. You can find in line 63, 123. https://github.com/miyamotok0105/pytorch_handbook/blob/master/chapter7/ssd.py

Hi, version of colab is PyTorch1.5.0, I modified detection.py and ssd.py. so that it works without warning and error. Since detection.py have torch.autograd.Function, I delete def init() and add @staticmethod. I also add output = self.detect.apply() in ssd.py. I share my code and you can find in '# PyTorch1.5.0 support new-style autograd function' in source. https://github.com/miyamotok0105/pytorch_handbook/blob/master/chapter7/layers/functions/detection.py

うまく動作する様になりました、ありがとうございます!

thank you so much for solving this error!!

Badaniao avatar Jul 13 '20 08:07 Badaniao

Hi, version of colab is PyTorch1.5.0, I modified detection.py and ssd.py. so that it works without warning and error.

Since detection.py have torch.autograd.Function, I delete def init() and add @staticmethod. I also add output = self.detect.apply() in ssd.py.

I share my code and you can find in '# PyTorch1.5.0 support new-style autograd function' in source. https://github.com/miyamotok0105/pytorch_handbook/blob/master/chapter7/layers/functions/detection.py

Thank you so much!

actruce avatar Aug 01 '20 13:08 actruce

I got a easy way out: just mordify the base class of Detect to 'object', and then modify the code in ssd.py: if self.phase == "test": with torch.no_grad(): output = self.detect.forward( loc.view(loc.size(0), -1, 4), # loc preds self.softmax(conf.view(conf.size(0), -1, self.num_classes)), # conf preds self.priors.type(type(x.data)) # default boxes )

Howietzh avatar Aug 06 '20 10:08 Howietzh

@fywsjz Hello. You can find in line 63, 123. https://github.com/miyamotok0105/pytorch_handbook/blob/master/chapter7/ssd.py

thanks,i solve my issue

cotyyang avatar Sep 24 '20 11:09 cotyyang

Hi, version of colab is PyTorch1.5.0, I modified detection.py and ssd.py. so that it works without warning and error.

Since detection.py have torch.autograd.Function, I delete def init() and add @staticmethod. I also add output = self.detect.apply() in ssd.py.

I share my code and you can find in '# PyTorch1.5.0 support new-style autograd function' in source. https://github.com/miyamotok0105/pytorch_handbook/blob/master/chapter7/layers/functions/detection.py

I have question, in pytorch1.5.0, must implement backward, but the class Detect() has no backward function,why? RuntimeError: You must implement the backward function for custom autograd.Function.

bruce1408 avatar Oct 12 '20 13:10 bruce1408

FYI: I heard from my colleague that this error was circumvented by changing

self.detect = Detect(num_classes, 0, 200, 0.01, 0.45)

to

self.detect = Detect(num_classes, 0, 200, 0.01, 0.45).forward

(i.e., just attaching .foward) in ssd.py. https://github.com/amdegroot/ssd.pytorch/blob/master/ssd.py#L48

tetsu-kikuchi avatar Dec 14 '20 04:12 tetsu-kikuchi