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

how to use mmrazor1.x #367

Closed
wwjwy opened this issue Dec 1, 2022 · 11 comments
Closed

how to use mmrazor1.x #367

wwjwy opened this issue Dec 1, 2022 · 11 comments
Labels

Comments

@wwjwy
Copy link

wwjwy commented Dec 1, 2022

Based on my own dataset, I trained a model using mmseg1.x. Now I want to realize knowledge distillation, resnet101+deeplab--->resnet18+deeplab.
I configured the mmrazor environment, but in the distill config file https://github.com/open-mmlab/mmrazor/blob/bbb58f1a5c2fe2878484856767dba540092bc7bf/configs/distill /mmseg/cwd/cwd_logits_pspnet_r101-d8_pspnet_r18-d8_4xb2-80k_cityscapes-512x1024.py#L2
I don't know where I can modify the default settings of mmseg, such as the number of categories to be segmented, data set selection, etc.?
Can you give me some help?

@TinyTigerPan
Copy link
Contributor

The config in MMRazor only define the distillation configuration. If you want modify settings of MMSeg, you can modify config in MMSeg, then import them to MMRazor config by mmseg::_base_/datasets/cityscapes_modify.py in the front.
As for how to change MMSeg config, you can refer mmseg doc

@wwjwy
Copy link
Author

wwjwy commented Dec 1, 2022

The config in MMRazor only define the distillation configuration. If you want modify settings of MMSeg, you can modify config in MMSeg, then import them to MMRazor config by mmseg::_base_/datasets/cityscapes_modify.py in the front. As for how to change MMSeg config, you can refer mmseg doc

Thank you for your help! it runs well now.

@wwjwy
Copy link
Author

wwjwy commented Dec 1, 2022

When i distill transformer seg models --->CNN seg model, there is something wrong.
assert preds_S.shape[-2:] == preds_T.shape[-2:]
The transformer and CNN has different output shape, can you show me how to modify the config file?

@TinyTigerPan
Copy link
Contributor

assert preds_S.shape[-2:] == preds_T.shape[-2:] used to make sure feature shape between teacher and student are the same, to make sure the KD loss can be calculate. For example, MSE(Tensor shape [2, 3, 4, 4], Tensor shape [2, 3, 5, 5]) can not get a result. As far as I know, many Transformer based backbone like PVT, Swin, ..., their backbone output is also with shape [B, C, H, W], it can used to distill with CNN based backbone.
So, my advice is

  1. check your preds_S.shape and preds_T.shape, make sure preds_S.shape[-2:] == preds_T.shape[-2:], if not, check your config, make sure your recorders get right feature.
  2. if shape between teacher and student are different, but you still want to distill them, you can align dimension by using connector in MMRazor, example config

@wwjwy
Copy link
Author

wwjwy commented Dec 2, 2022

Thank you for your help!

@wwjwy
Copy link
Author

wwjwy commented Dec 5, 2022

After training the cwd model, i run the tools/test.py, but i can only get evaluation metrics. How can i get the segmentation images predicted by the distilled student model?

@TinyTigerPan
Copy link
Contributor

MMRazor tools/test.py seems not provide --show, but MMSeg provide, like this. You can try use MMSeg tools/test.py with --show, or if your server has no GUI, you can save the image to disk by --show-dir.

@wwjwy
Copy link
Author

wwjwy commented Dec 5, 2022

Thanks

@TinyTigerPan
Copy link
Contributor

I have noticed your question about how to transfer distill model to student only model, however, there are no such tools in MMRazor now. I may develop some tools to meet this requirement later.

@wwjwy
Copy link
Author

wwjwy commented Dec 5, 2022

Thank you very much for your help!

@TinyTigerPan
Copy link
Contributor

Hi, I add tools to convert distill model to student only model, you can refer #381.

@pppppM pppppM added the v-1.x label Dec 12, 2022
@pppppM pppppM closed this as completed Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants