open-mmlab / mmrazor

OpenMMLab Model Compression Toolbox and Benchmark.
https://mmrazor.readthedocs.io/en/latest/
Apache License 2.0
1.47k stars 227 forks source link

how to use mmrazor1.x #367

Closed wwjwy closed 1 year ago

wwjwy commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Thank you for your help!

wwjwy commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Thanks

TinyTigerPan commented 1 year ago

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 commented 1 year ago

Thank you very much for your help!

TinyTigerPan commented 1 year ago

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