Skip to content

Commit 03f2a25

Browse files
authored
more docs about tools pytorch2torchscript and print_config (open-mmlab#499)
* Description of arguments about tools pytorch2torchscript and print_config * fix docs lint
1 parent 27342fd commit 03f2a25

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

docs/useful_tools.md

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,40 @@ Description of arguments:
7979
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.
8080

8181
```shell
82-
python tools/pytorch2torchscript.py ${CONFIG_FILE} --checkpoint ${CHECKPOINT_FILE} --output-file ${ONNX_FILE} [--shape ${INPUT_SHAPE} --verify]
82+
python tools/pytorch2torchscript.py \
83+
${CONFIG_FILE} \
84+
--checkpoint ${CHECKPOINT_FILE} \
85+
--output-file ${ONNX_FILE}
86+
--shape ${INPUT_SHAPE}
87+
--verify \
88+
--show
8389
```
8490

91+
Description of arguments:
92+
93+
- `config` : The path of a pytorch model config file.
94+
- `--checkpoint` : The path of a pytorch model checkpoint file.
95+
- `--output-file`: The path of output TorchScript model. If not specified, it will be set to `tmp.pt`.
96+
- `--input-img` : The path of an input image for conversion and visualize.
97+
- `--shape`: The height and width of input tensor to the model. If not specified, it will be set to `512 512`.
98+
- `--show`: Determines whether to print the traced graph of the exported model. If not specified, it will be set to `False`.
99+
- `--verify`: Determines whether to verify the correctness of an exported model. If not specified, it will be set to `False`.
100+
85101
**Note**: It's only support PyTorch>=1.8.0 for now.
86102

87103
**Note**: This tool is still experimental. Some customized operators are not supported for now.
88104

105+
Examples:
106+
107+
- Convert the cityscapes PSPNet pytorch model.
108+
109+
```shell
110+
python tools/pytorch2torchscript.py configs/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes.py \
111+
--checkpoint checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth \
112+
--output-file checkpoints/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pt \
113+
--shape 512 1024
114+
```
115+
89116
## Miscellaneous
90117

91118
### Print the entire config
@@ -94,12 +121,21 @@ python tools/pytorch2torchscript.py ${CONFIG_FILE} --checkpoint ${CHECKPOINT_FIL
94121
imports.
95122

96123
```shell
97-
python tools/print_config.py ${CONFIG} [-h] [--options ${OPTIONS [OPTIONS...]}]
124+
python tools/print_config.py \
125+
${CONFIG} \
126+
--graph \
127+
--options ${OPTIONS [OPTIONS...]} \
98128
```
99129

130+
Description of arguments:
131+
132+
- `config` : The path of a pytorch model config file.
133+
- `--graph` : Determines whether to print the models graph.
134+
- `--options`: Custom options to replace the config file.
135+
100136
### Plot training logs
101137

102-
`tools/analyze_logs.py` plot s loss/mIoU curves given a training log file. `pip install seaborn` first to install the dependency.
138+
`tools/analyze_logs.py` plots loss/mIoU curves given a training log file. `pip install seaborn` first to install the dependency.
103139

104140
```shell
105141
python tools/analyze_logs.py xxx.log.json [--keys ${KEYS}] [--legend ${LEGEND}] [--backend ${BACKEND}] [--style ${STYLE}] [--out ${OUT_FILE}]

0 commit comments

Comments
 (0)