From ea6e608031705ea14657bb11f6ca63716c9dffbf Mon Sep 17 00:00:00 2001 From: zhiqiang Date: Tue, 2 Nov 2021 15:05:43 +0800 Subject: [PATCH 1/2] Fix docstring for jit scripting --- deployment/libtorch/README.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/deployment/libtorch/README.md b/deployment/libtorch/README.md index 3829252c..0029c09b 100644 --- a/deployment/libtorch/README.md +++ b/deployment/libtorch/README.md @@ -37,10 +37,14 @@ The LibTorch inference for `yolort`, both GPU and CPU are supported. Unlike [ultralytics's](https://github.com/ultralytics/yolov5/blob/8ee9fd1/export.py) `torch.jit.trace` mechanism, We're using `torch.jit.script` to trace the YOLOv5 models which containing the whole pre-processing (especially with the [`letterbox`](https://github.com/ultralytics/yolov5/blob/8ee9fd1/utils/augmentations.py#L85-L115) ops) and post-processing (especially with the `nms` ops) procedures, as such you don't need to rewrite manually the C++ codes of pre-processing and post-processing. - ```bash - git clone https://github.com/zhiqwang/yolov5-rt-stack.git - cd yolov5-rt-stack - python -m test.tracing.trace_model + ```python + from yolort.models import yolov5n + + model = yolov5n(pretrained=True) + model.eval() + + traced_model = torch.jit.script(model) + traced_model.save("yolov5n.torchscript.pt") ``` 1. Then compile the source code. @@ -56,7 +60,7 @@ The LibTorch inference for `yolort`, both GPU and CPU are supported. ```bash ./yolo_inference [--input_source ../../../test/assets/zidane.jpg] - [--checkpoint ../../../test/tracing/yolov5s.torchscript.pt] + [--checkpoint ../../../test/tracing/yolov5n.torchscript.pt] [--labelmap ../../../notebooks/assets/coco.names] [--gpu] # GPU switch, which is optional, and set False as default ``` From 72b7ddc9e0921ca6c03f2231ce25616044ec3d84 Mon Sep 17 00:00:00 2001 From: zhiqiang Date: Tue, 2 Nov 2021 15:08:54 +0800 Subject: [PATCH 2/2] Minor fix to the model path --- deployment/libtorch/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/libtorch/README.md b/deployment/libtorch/README.md index 0029c09b..a8864437 100644 --- a/deployment/libtorch/README.md +++ b/deployment/libtorch/README.md @@ -60,7 +60,7 @@ The LibTorch inference for `yolort`, both GPU and CPU are supported. ```bash ./yolo_inference [--input_source ../../../test/assets/zidane.jpg] - [--checkpoint ../../../test/tracing/yolov5n.torchscript.pt] + [--checkpoint ../yolov5n.torchscript.pt] [--labelmap ../../../notebooks/assets/coco.names] [--gpu] # GPU switch, which is optional, and set False as default ```