From aef3803d1596960414630ea51976a35a85daa3f6 Mon Sep 17 00:00:00 2001 From: sshuair Date: Tue, 20 Apr 2021 15:58:40 +0800 Subject: [PATCH 1/2] Description of arguments about tools pytorch2torchscript and print_config --- docs/useful_tools.md | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/docs/useful_tools.md b/docs/useful_tools.md index 81cbeb8662..ea2bedfc06 100644 --- a/docs/useful_tools.md +++ b/docs/useful_tools.md @@ -79,13 +79,40 @@ Description of arguments: We also provide a script to convert model to [TorchScript](https://pytorch.org/docs/stable/jit.html) format. You can use the pytorch C++ API [LibTorch](https://pytorch.org/docs/stable/cpp_index.html) inference the trained model. The converted model could be visualized by tools like [Netron](https://github.com/lutzroeder/netron). Besides, we also support comparing the output results between Pytorch and TorchScript model. ```shell -python tools/pytorch2torchscript.py ${CONFIG_FILE} --checkpoint ${CHECKPOINT_FILE} --output-file ${ONNX_FILE} [--shape ${INPUT_SHAPE} --verify] +python tools/pytorch2torchscript.py \ + ${CONFIG_FILE} \ + --checkpoint ${CHECKPOINT_FILE} \ + --output-file ${ONNX_FILE} + --shape ${INPUT_SHAPE} + --verify \ + --show ``` +Description of arguments: + +- `config` : The path of a pytorch model config file. +- `--checkpoint` : The path of a pytorch model checkpoint file. +- `--output-file`: The path of output TorchScript model. If not specified, it will be set to `tmp.pt`. +- `--input-img` : The path of an input image for conversion and visualize. +- `--shape`: The height and width of input tensor to the model. If not specified, it will be set to `512 512`. +- `--show`: Determines whether to print the traced graph of the exported model. If not specified, it will be set to `False`. +- `--verify`: Determines whether to verify the correctness of an exported model. If not specified, it will be set to `False`. + **Note**: It's only support PyTorch>=1.8.0 for now. **Note**: This tool is still experimental. Some customized operators are not supported for now. +Examples: + +- Convert the cityscapes PSPNet pytorch model. + + ```shell + python tools/pytorch2torchscript.py configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py \ + --checkpoint checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth \ + --output-file checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pt \ + --shape 512 1024 + ``` + ## Miscellaneous ### Print the entire config @@ -94,12 +121,21 @@ python tools/pytorch2torchscript.py ${CONFIG_FILE} --checkpoint ${CHECKPOINT_FIL imports. ```shell -python tools/print_config.py ${CONFIG} [-h] [--options ${OPTIONS [OPTIONS...]}] +python tools/print_config.py \ + ${CONFIG} \ + --graph \ + --options ${OPTIONS [OPTIONS...]} \ ``` +Description of arguments: + +- `config` : The path of a pytorch model config file. +- `--graph` : Determines whether to print the models graph. +- `--options`: Custom options to replace the config file. + ### Plot training logs -`tools/analyze_logs.py` plot s loss/mIoU curves given a training log file. `pip install seaborn` first to install the dependency. +`tools/analyze_logs.py` plots loss/mIoU curves given a training log file. `pip install seaborn` first to install the dependency. ```shell python tools/analyze_logs.py xxx.log.json [--keys ${KEYS}] [--legend ${LEGEND}] [--backend ${BACKEND}] [--style ${STYLE}] [--out ${OUT_FILE}] From 50bb05254169164435b504be987d51efb796719c Mon Sep 17 00:00:00 2001 From: sshuair Date: Tue, 20 Apr 2021 17:36:55 +0800 Subject: [PATCH 2/2] fix docs lint --- docs/useful_tools.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/useful_tools.md b/docs/useful_tools.md index ea2bedfc06..3e53152855 100644 --- a/docs/useful_tools.md +++ b/docs/useful_tools.md @@ -82,8 +82,8 @@ We also provide a script to convert model to [TorchScript](https://pytorch.org/d python tools/pytorch2torchscript.py \ ${CONFIG_FILE} \ --checkpoint ${CHECKPOINT_FILE} \ - --output-file ${ONNX_FILE} - --shape ${INPUT_SHAPE} + --output-file ${ONNX_FILE} + --shape ${INPUT_SHAPE} --verify \ --show ```