Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model Binarized Problem #17

Closed
Zeshengx opened this issue Nov 9, 2020 · 6 comments
Closed

Model Binarized Problem #17

Zeshengx opened this issue Nov 9, 2020 · 6 comments

Comments

@Zeshengx
Copy link

Zeshengx commented Nov 9, 2020

Hi, I am trying to repeat the experiment in your paper, and meeting some problems in training part. I use the recommended command [python ssd/train_bidet_ssd.py --dataset="VOC" --data_root="D:\01DL\data\VOCdevkit" --basenet="D:\01DL\BiDet-master\ssd\pretrain\vgg16.pth"] to run the training and get the final model saved as " VOC_final.pth". However, the "VOC_final.pth", which I think is the parameters of the trained "BiDet_SSD model", is around 127MB. According to the paper, the output binary model should be around 20MB, since "bidet_ssd" build in bidet_ssd.py. I am confused whether I followed the incorrect way to run your code or missed any parameter setting.
In the test part, I got TypeError as follow:
ssd_voc_eval1
Hoping for your response, thanks.

@Wuziyi616
Copy link
Contributor

Hi! Thank you for your interest in our work! For the first question, I think you can refer to this issue #13 for the answer. To be brief, the saved weight (those state_dicts) still contain float-valued parameters because PyTorch doesn't support binary-value operations. Also, if you want to binarize the weight, you need to follow BiReal-Net to fix model weight and re-train BN layers to absorb the scaling factor.

For the second question, well, that's strange, I don't encounter such problem using the code. I guess it may be related to the PyTorch version you used. I recommend you use torch>=1.0. Also, you can use pdb to try to debug it, I don't think it is a big problem. If none of these helps, tell me and I will look into it and figure it out later.

@Zeshengx
Copy link
Author

Zeshengx commented Nov 9, 2020

Actually, the second problem botherd me for several days. I use torch 1.7.0, and when I run the inital "eval_voc.py", I get the RuntimeError:Legacy autograd function with non-static forward method is deprecated.
ssd_voc_eval2
I fixed it by adding "@staticmethod" on forward() in bidet_ssd.py. Then, the error I mentioned before just trigged.
bidet_ssd1
I am wondering if you have a trained bidet_ssd.pth, so I can check whether the error is caused by my training model or the other reasons with torch version.

@Wuziyi616
Copy link
Contributor

Wuziyi616 commented Nov 9, 2020

Hi! I am quite sure this is caused by PyTorch version. You can switch to for example torch1.2.0 and my original code will be OK.

On the other hand, if you want to set some function to be staticmethod in python, you also need to delete the "self" in its input parameter list (def forward(self, x) --> def forward(x)).

In addition, actually the error in the first image you post is related to this line. So you should add "@staticmethod" here. As you can see the error message points to "line 206, output = self.predict(", and self.detect is a function imported from ssd/layers/functions/detection.py.

@Wuziyi616
Copy link
Contributor

Wuziyi616 commented Nov 9, 2020

BTW about the pretrained BiDet weight, I didn't notice that I forgot to upload them! It's embarrassed that I didn't discover this after half a year, and I really apologize for this. I will managed to upload the pretrained weight of SSD and Faster R-CNN that can reproduce the mAP reported in the paper to this repo soon. (But you know, after CVPR and ICLR rebuttal DDL)

@Zeshengx
Copy link
Author

Thanks for your advise. I figured out the pytorch version problem by referring amdegroot/ssd.pytorch#444.
I made some changes in ssd/bidet_ssd.py and ssd/layers/functions/detection.py, and it works for me on pytorch 1.7.0.

changes-pytorch1.7.0.zip

@Wuziyi616
Copy link
Contributor

Sure! Thank you for your effort, I think I need to mention this in the README file of this repo. Thank you very much for figuring it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants