mmclassification/docs/tools/pytorch2torchscript.md
Ma Zerun 42b99be9b2
[Docs] rearrange docs and add multiple translation docs. (#320)
* Move tools docs to `tools` folder.

* Fix link error in model_serving.md

* Fix typo in CONTRIBUTING.md

* Add Chinese translation of CONTRIBUTING.md

* Add translation of `onnx2tensorrt.md`, `pytorch2onnx.md`,
`model_serving.md` and `pytorch2torchscript.md`.

* Improve tools docs.

* Add docs about installing mmcls via mim.
2021-06-30 20:53:09 +08:00

1.7 KiB

Pytorch to TorchScript (Experimental)

How to convert models from Pytorch to TorchScript

Usage

python tools/deployment/pytorch2torchscript.py \
    ${CONFIG_FILE} \
    --checkpoint ${CHECKPOINT_FILE} \
    --output-file ${OUTPUT_FILE} \
    --shape ${IMAGE_SHAPE} \
    --verify \

Description of all arguments

  • config : The path of a model config file.
  • --checkpoint : The path of a model checkpoint file.
  • --output-file: The path of output TorchScript model. If not specified, it will be set to tmp.pt.
  • --shape: The height and width of input tensor to the model. If not specified, it will be set to 224 224.
  • --verify: Determines whether to verify the correctness of an exported model. If not specified, it will be set to False.

Example:

python tools/deployment/pytorch2onnx.py \
    configs/resnet/resnet18_b16x8_cifar10.py \
    --checkpoint checkpoints/resnet/resnet18_b16x8_cifar10.pth \
    --output-file checkpoints/resnet/resnet18_b16x8_cifar10.pt \
    --verify \

Notes:

  • All models are tested with Pytorch==1.8.1

Reminders

  • For torch.jit.is_tracing() is only supported after v1.6. For users with pytorch v1.3-v1.5, we suggest early returning tensors manually.
  • If you meet any problem with the models in this repo, please create an issue and it would be taken care of soon.

FAQs

  • None