2021-12-23 09:51:48 +08:00
# Test a model
## NAS
To test nas method, you can use following command
```bash
python tools/${task}/test_${task}.py ${CONFIG_FILE} ${CHECKPOINT_PATH} --cfg-options algorithm.mutable_cfg=${MUTABLE_CFG_PATH} [optional arguments]
```
2022-05-31 16:21:53 +08:00
- `task` : one of `mmcls` 、`mmdet` and `mmseg`
2021-12-23 12:02:39 +08:00
- `MUTABLE_CFG_PATH` : Path of `mutable_cfg` . `mutable_cfg` represents **config for mutable of the subnet searched out** , used to specify different subnets for testing. An example for `mutable_cfg` can be found [here ](https://github.com/open-mmlab/mmrazor/blob/master/configs/nas/spos/SPOS_SHUFFLENETV2_330M_IN1k_PAPER.yaml ).
2021-12-23 09:51:48 +08:00
The usage of optional arguments are the same as corresponding tasks like mmclassification, mmdetection and mmsegmentation.
2022-04-02 19:30:50 +08:00
For example,
< pre >
python tools/mmcls/test_mmcls.py \
configs/nas/spos/spos_subnet_shufflenetv2_8xb128_in1k.py \
< em > your_subnet_checkpoint_path< / em > \
--cfg-options algorithm.mutable_cfg=configs/nas/spos/SPOS_SHUFFLENETV2_330M_IN1k_PAPER.yaml
< / pre >
2021-12-23 09:51:48 +08:00
## Pruning
2021-12-23 10:35:32 +08:00
### Split Checkpoint(Optional)
2022-05-31 16:21:53 +08:00
2021-12-24 15:40:40 +08:00
If you train a slimmable model during retraining, checkpoints of different subnets are
2021-12-23 10:35:32 +08:00
actually fused in only one checkpoint. You can split this checkpoint to
2021-12-24 15:40:40 +08:00
multiple independent checkpoints by using the following command
2021-12-23 10:35:32 +08:00
```bash
python tools/model_converters/split_checkpoint.py ${CONFIG_FILE} ${CHECKPOINT_PATH} --channel-cfgs ${CHANNEL_CFG_PATH} [optional arguments]
```
- `CHANNEL_CFG_PATH` : A list of paths of `channel_cfg` . For example, when you
2022-05-31 16:21:53 +08:00
retrain a slimmable model, your command will be like `--cfg-options algorithm.channel_cfg=cfg1,cfg2,cfg3` .
And your command here should be `--channel-cfgs cfg1 cfg2 cfg3` . The order of them should be the same.
2021-12-23 10:35:32 +08:00
2022-04-02 19:30:50 +08:00
For example,
< pre >
python tools/model_converters/split_checkpoint.py \
configs/pruning/autoslim/autoslim_mbv2_subnet_8xb256_in1k.py \
< em > your_retraining_checkpoint_path< / em > \
--channel-cfgs configs/pruning/autoslim/AUTOSLIM_MBV2_530M_OFFICIAL.yaml configs/pruning/autoslim/AUTOSLIM_MBV2_320M_OFFICIAL.yaml configs/pruning/autoslim/AUTOSLIM_MBV2_220M_OFFICIAL.yaml
< / pre >
2021-12-23 10:35:32 +08:00
### Test
2021-12-23 09:51:48 +08:00
To test pruning method, you can use following command
```bash
python tools/${task}/test_${task}.py ${CONFIG_FILE} ${CHECKPOINT_PATH} --cfg-options algorithm.channel_cfg=${CHANNEL_CFG_PATH} [optional arguments]
```
2022-05-31 16:21:53 +08:00
- `task` : one of `mmcls` 、`mmdet` and `mmseg`
2021-12-23 12:02:39 +08:00
- `CHANNEL_CFG_PATH` : Path of `channel_cfg` . `channel_cfg` represents **config for channel of the subnet searched out** , used to specify different subnets for testing. An example for `channel_cfg` can be found [here ](https://github.com/open-mmlab/mmrazor/blob/master/configs/pruning/autoslim/AUTOSLIM_MBV2_220M_OFFICIAL.yaml ), and the usage can be found [here ](https://github.com/open-mmlab/mmrazor/blob/master/configs/pruning/autoslim/README.md#test-a-subnet ).
2021-12-23 09:51:48 +08:00
2022-04-02 19:30:50 +08:00
For example,
< pre >
python ./tools/mmcls/test_mmcls.py \
configs/pruning/autoslim/autoslim_mbv2_subnet_8xb256_in1k.py \
< em > your_splitted_checkpoint_path< / em > --metrics accuracy \
--cfg-options algorithm.channel_cfg=configs/pruning/autoslim/AUTOSLIM_MBV2_530M_OFFICIAL.yaml
< / pre >
2021-12-23 09:51:48 +08:00
## Distillation
2021-12-24 15:40:40 +08:00
To test distillation method, you can use the following command
2021-12-23 09:51:48 +08:00
```bash
python tools/${task}/test_${task}.py ${CONFIG_FILE} ${CHECKPOINT_PATH} [optional arguments]
```
2022-04-02 19:30:50 +08:00
2022-05-31 16:21:53 +08:00
- `task` : one of `mmcls` 、`mmdet` and `mmseg`
2022-04-02 19:30:50 +08:00
For example,
< pre >
python ./tools/mmseg/test_mmseg.py \
configs/distill/cwd/cwd_cls_head_pspnet_r101_d8_pspnet_r18_d8_512x1024_cityscapes_80k.py \
< em > your_splitted_checkpoint_path< / em > --show
< / pre >