Convert RepVGG from training-time to inference-time structure
mainRepVGG models use structural re-parameterization. To convert a training-time model (which has identity and 1x1 branches) into an efficient inference-time model (deploy mode), you can use one of two methods:
- Manual conversion: Iterate through the model modules and call
switch_to_deploy()on every RepVGG block. - Scripted conversion: Use the provided
convert.pyscript.
After conversion, you must build the model with the --deploy flag to use the inference-optimized structure.
# Method 1: Manual conversion via switch_to_deploy
for module in model.modules():
if hasattr(module, 'switch_to_deploy'):
module.switch_to_deploy()# Method 2: Using the conversion script
python convert.py RepVGGplus-L2pse-train256-acc84.06.pth RepVGGplus-L2pse-deploy.pth -a RepVGGplus-L2pse
# Then run inference with the --deploy flag
python -m torch.distributed.launch --nproc_per_node 1 --master_port 12349 main.py --arch RepVGGplus-L2pse --data-path [/path/to/imagenet] --batch-size 32 --tag test --eval --resume RepVGGplus-L2pse-deploy.pth --deploy --opts DATA.DATASET imagenet DATA.IMG_SIZE [224 or 320]