diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index d71ce40e..9066e036 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -104,8 +104,11 @@ If all previous checks (flake8, mypy, unit tests) are passing, please send a PR. ```bash git remote add upstream https://github.com/zhiqwang/yolov5-rt-stack.git git fetch upstream - git checkout feature # <----- replace 'feature' with local branch name - git merge upstream/main + git rebase upstream/main + git checkout -b feature # <--- REPLACE 'feature' WITH YOUR LOCAL BRANCH NAME + # ADD YOUR PROPOSED CHANGES HERE + git add . + git commit -m "YOUR REVISION MESSAGE" git push origin feature ``` diff --git a/notebooks/inference-pytorch-export-libtorch.ipynb b/notebooks/inference-pytorch-export-libtorch.ipynb index 9b219eae..620194e3 100644 --- a/notebooks/inference-pytorch-export-libtorch.ipynb +++ b/notebooks/inference-pytorch-export-libtorch.ipynb @@ -16,8 +16,8 @@ "import cv2\n", "import torch\n", "\n", - "from yolort.utils import cv2_imshow, get_image_from_url, read_image_to_tensor\n", - "from yolort.utils.image_utils import color_list, plot_one_box" + "from yolort.utils import Visualizer, get_image_from_url, read_image_to_tensor\n", + "from yolort.v5.utils.downloads import safe_download" ] }, { @@ -238,56 +238,64 @@ "First let get the labels of COCO datasets." ] }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [], - "source": [ - "# Get label names\n", - "import requests\n", - "\n", - "labels = []\n", - "response = requests.get(\"https://huggingface.co/spaces/zhiqwang/assets/resolve/main/coco.names\")\n", - "names = response.text\n", - "\n", - "for label in names.strip().split('\\n'):\n", - " labels.append(label)" - ] - }, { "cell_type": "markdown", "metadata": {}, "source": [ - "The labels can also be obtained by\n", - "\n", - "```python\n", - "from yolort.utils.image_utils import load_names\n", - "labels = load_names('../notebooks/assets/coco.names')\n", - "```" + "Get label names first." ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Downloading https://huggingface.co/spaces/zhiqwang/assets/resolve/main/coco.names to coco.names...\n" + ] + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "b73354af7f8748c4884aeaaa37a0b95d", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + " 0%| | 0.00/621 [00:00" + "" ] }, "metadata": {}, @@ -295,7 +303,9 @@ } ], "source": [ - "cv2_imshow(img_raw, imshow_scale=0.5)" + "v = Visualizer(img_raw, metalabels=label_path)\n", + "v.draw_instance_predictions(model_out[0])\n", + "v.imshow(scale=0.5)" ] }, { @@ -307,14 +317,14 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Starting TorchScript export with torch 1.10.1+cu113...\n" + "Starting TorchScript export with torch 1.10.2+cu113...\n" ] } ], @@ -326,26 +336,9 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 15, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/opt/conda/lib/python3.8/site-packages/torch/jit/_recursive.py:614: LightningDeprecationWarning: The `LightningModule.loaded_optimizer_states_dict` property is deprecated in v1.4 and will be removed in v1.6.\n", - " item = getattr(mod, name, None)\n", - "/opt/conda/lib/python3.8/site-packages/torch/jit/_recursive.py:614: LightningDeprecationWarning: The `LightningModule.model_size` property was deprecated in v1.5 and will be removed in v1.7. Please use the `pytorch_lightning.utilities.memory.get_model_size_mb`.\n", - " item = getattr(mod, name, None)\n", - "/opt/conda/lib/python3.8/site-packages/torch/jit/_recursive.py:701: LightningDeprecationWarning: The `LightningModule.model_size` property was deprecated in v1.5 and will be removed in v1.7. Please use the `pytorch_lightning.utilities.memory.get_model_size_mb`.\n", - " item = getattr(nn_module, name, None)\n", - "/opt/conda/lib/python3.8/site-packages/torch/jit/_recursive.py:501: LightningDeprecationWarning: The `LightningModule.model_size` property was deprecated in v1.5 and will be removed in v1.7. Please use the `pytorch_lightning.utilities.memory.get_model_size_mb`.\n", - " item = getattr(nn_module, name, None)\n", - "/opt/conda/lib/python3.8/site-packages/torch/jit/_recursive.py:584: LightningDeprecationWarning: The `LightningModule.model_size` property was deprecated in v1.5 and will be removed in v1.7. Please use the `pytorch_lightning.utilities.memory.get_model_size_mb`.\n", - " item = getattr(nn_module, name, None)\n" - ] - } - ], + "outputs": [], "source": [ "model_script = torch.jit.script(model)\n", "model_script.eval()\n", @@ -354,7 +347,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ @@ -371,16 +364,16 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "/opt/conda/lib/python3.8/site-packages/yolort/models/yolo.py:179: UserWarning: YOLO always returns a (Losses, Detections) tuple in scripting.\n", + "/coding/yolov5-rt-stack/yolort/models/yolo.py:179: UserWarning: YOLO always returns a (Losses, Detections) tuple in scripting.\n", " warnings.warn(\"YOLO always returns a (Losses, Detections) tuple in scripting.\")\n", - "/opt/conda/lib/python3.8/site-packages/yolort/models/yolo_module.py:142: UserWarning: YOLOv5 always returns a (Losses, Detections) tuple in scripting.\n", + "/coding/yolov5-rt-stack/yolort/models/yolov5.py:180: UserWarning: YOLOv5 always returns a (Losses, Detections) tuple in scripting.\n", " warnings.warn(\"YOLOv5 always returns a (Losses, Detections) tuple in scripting.\")\n" ] } @@ -401,7 +394,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 18, "metadata": {}, "outputs": [ { @@ -435,14 +428,14 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "13.7 ms ± 412 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n" + "23.8 ms ± 3.64 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n" ] } ], @@ -461,7 +454,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ @@ -472,14 +465,14 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "8.7 ms ± 310 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" + "14 ms ± 564 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" ] } ], diff --git a/notebooks/onnx-graphsurgeon-inference-tensorrt.ipynb b/notebooks/onnx-graphsurgeon-inference-tensorrt.ipynb index 69635f55..32b5e963 100644 --- a/notebooks/onnx-graphsurgeon-inference-tensorrt.ipynb +++ b/notebooks/onnx-graphsurgeon-inference-tensorrt.ipynb @@ -106,7 +106,7 @@ "source": [ "import cv2\n", "\n", - "from yolort.utils import cv2_imshow\n", + "from yolort.utils import Visualizer\n", "from yolort.utils.image_utils import plot_one_box, color_list\n", "from yolort.v5 import attempt_download\n", "from yolort.v5.utils.downloads import safe_download" @@ -154,7 +154,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "91389b7251a3428f876c221705098153", + "model_id": "f043a9e0e6aa42a49273981f17d27f9b", "version_major": 2, "version_minor": 0 }, @@ -236,54 +236,16 @@ "name": "stderr", "output_type": "stream", "text": [ - "\n", - " from n params module arguments \n", - " 0 -1 1 1760 yolort.v5.models.common.Conv [3, 16, 6, 2, 2] \n", - " 1 -1 1 4672 yolort.v5.models.common.Conv [16, 32, 3, 2] \n", - " 2 -1 1 4800 yolort.v5.models.common.C3 [32, 32, 1] \n", - " 3 -1 1 18560 yolort.v5.models.common.Conv [32, 64, 3, 2] \n", - " 4 -1 2 29184 yolort.v5.models.common.C3 [64, 64, 2] \n", - " 5 -1 1 73984 yolort.v5.models.common.Conv [64, 128, 3, 2] \n", - " 6 -1 3 156928 yolort.v5.models.common.C3 [128, 128, 3] \n", - " 7 -1 1 221568 yolort.v5.models.common.Conv [128, 192, 3, 2] \n", - " 8 -1 1 167040 yolort.v5.models.common.C3 [192, 192, 1] \n", - " 9 -1 1 442880 yolort.v5.models.common.Conv [192, 256, 3, 2] \n", - " 10 -1 1 296448 yolort.v5.models.common.C3 [256, 256, 1] \n", - " 11 -1 1 164608 yolort.v5.models.common.SPPF [256, 256, 5] \n", - " 12 -1 1 49536 yolort.v5.models.common.Conv [256, 192, 1, 1] \n", - " 13 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] \n", - " 14 [-1, 8] 1 0 yolort.v5.models.common.Concat [1] \n", - " 15 -1 1 203904 yolort.v5.models.common.C3 [384, 192, 1, False] \n", - " 16 -1 1 24832 yolort.v5.models.common.Conv [192, 128, 1, 1] \n", - " 17 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] \n", - " 18 [-1, 6] 1 0 yolort.v5.models.common.Concat [1] \n", - " 19 -1 1 90880 yolort.v5.models.common.C3 [256, 128, 1, False] \n", - " 20 -1 1 8320 yolort.v5.models.common.Conv [128, 64, 1, 1] \n", - " 21 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] \n", - " 22 [-1, 4] 1 0 yolort.v5.models.common.Concat [1] \n", - " 23 -1 1 22912 yolort.v5.models.common.C3 [128, 64, 1, False] \n", - " 24 -1 1 36992 yolort.v5.models.common.Conv [64, 64, 3, 2] \n", - " 25 [-1, 20] 1 0 yolort.v5.models.common.Concat [1] \n", - " 26 -1 1 74496 yolort.v5.models.common.C3 [128, 128, 1, False] \n", - " 27 -1 1 147712 yolort.v5.models.common.Conv [128, 128, 3, 2] \n", - " 28 [-1, 16] 1 0 yolort.v5.models.common.Concat [1] \n", - " 29 -1 1 179328 yolort.v5.models.common.C3 [256, 192, 1, False] \n", - " 30 -1 1 332160 yolort.v5.models.common.Conv [192, 192, 3, 2] \n", - " 31 [-1, 12] 1 0 yolort.v5.models.common.Concat [1] \n", - " 32 -1 1 329216 yolort.v5.models.common.C3 [384, 256, 1, False] \n", - " 33 [23, 26, 29, 32] 1 164220 yolort.v5.models.yolo.Detect [80, [[19, 27, 44, 40, 38, 94], [96, 68, 86, 152, 180, 137], [140, 301, 303, 264, 238, 542], [436, 615, 739, 380, 925, 792]], [64, 128, 192, 256]]\n", + "Loaded saved model from yolov5n6.pt\n", "/opt/conda/lib/python3.8/site-packages/torch/functional.py:445: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:2157.)\n", " return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined]\n", - "Model Summary: 355 layers, 3246940 parameters, 3246940 gradients, 4.6 GFLOPs\n", - "\n", - "Loaded saved model from yolov5n6.pt\n", "/coding/yolov5-rt-stack/yolort/models/anchor_utils.py:45: TracerWarning: torch.as_tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.\n", " anchors = torch.as_tensor(self.anchor_grids, dtype=torch.float32, device=device).to(dtype=dtype)\n", "/coding/yolov5-rt-stack/yolort/models/anchor_utils.py:46: TracerWarning: torch.as_tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.\n", " strides = torch.as_tensor(self.strides, dtype=torch.float32, device=device).to(dtype=dtype)\n", - "/coding/yolov5-rt-stack/yolort/relaying/logits_decoder.py:45: TracerWarning: torch.as_tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.\n", + "/coding/yolov5-rt-stack/yolort/relay/logits_decoder.py:45: TracerWarning: torch.as_tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.\n", " strides = torch.as_tensor(self.strides, dtype=torch.float32, device=device).to(dtype=dtype)\n", - "/coding/yolov5-rt-stack/yolort/models/box_head.py:333: TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results).\n", + "/coding/yolov5-rt-stack/yolort/models/box_head.py:335: TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results).\n", " for head_output, grid, shift, stride in zip(head_outputs, grids, shifts, strides):\n", "PyTorch2ONNX graph created successfully\n" ] @@ -316,34 +278,34 @@ "name": "stdout", "output_type": "stream", "text": [ - "[02/12/2022-17:42:08] [TRT] [I] [MemUsageChange] Init CUDA: CPU +176, GPU +0, now: CPU 405, GPU 4987 (MiB)\n", - "[02/12/2022-17:42:09] [TRT] [I] ----------------------------------------------------------------\n", - "[02/12/2022-17:42:09] [TRT] [I] Input filename: yolov5n6.onnx\n", - "[02/12/2022-17:42:09] [TRT] [I] ONNX IR version: 0.0.8\n", - "[02/12/2022-17:42:09] [TRT] [I] Opset version: 11\n", - "[02/12/2022-17:42:09] [TRT] [I] Producer name: \n", - "[02/12/2022-17:42:09] [TRT] [I] Producer version: \n", - "[02/12/2022-17:42:09] [TRT] [I] Domain: \n", - "[02/12/2022-17:42:09] [TRT] [I] Model version: 0\n", - "[02/12/2022-17:42:09] [TRT] [I] Doc string: \n", - "[02/12/2022-17:42:09] [TRT] [I] ----------------------------------------------------------------\n", - "[02/12/2022-17:42:09] [TRT] [W] parsers/onnx/onnx2trt_utils.cpp:364: Your ONNX model has been generated with INT64 weights, while TensorRT does not natively support INT64. Attempting to cast down to INT32.\n", - "[02/12/2022-17:42:09] [TRT] [W] parsers/onnx/onnx2trt_utils.cpp:392: One or more weights outside the range of INT32 was clamped\n", - "[02/12/2022-17:42:09] [TRT] [W] parsers/onnx/onnx2trt_utils.cpp:392: One or more weights outside the range of INT32 was clamped\n", - "[02/12/2022-17:42:09] [TRT] [W] parsers/onnx/onnx2trt_utils.cpp:392: One or more weights outside the range of INT32 was clamped\n", - "[02/12/2022-17:42:09] [TRT] [W] parsers/onnx/onnx2trt_utils.cpp:392: One or more weights outside the range of INT32 was clamped\n", - "[02/12/2022-17:42:09] [TRT] [W] parsers/onnx/onnx2trt_utils.cpp:392: One or more weights outside the range of INT32 was clamped\n", - "[02/12/2022-17:42:09] [TRT] [I] No importer registered for op: EfficientNMS_TRT. Attempting to import as plugin.\n", - "[02/12/2022-17:42:09] [TRT] [I] Searching for plugin: EfficientNMS_TRT, plugin_version: 1, plugin_namespace: \n", - "[02/12/2022-17:42:09] [TRT] [I] Successfully created plugin: EfficientNMS_TRT\n", - "[02/12/2022-17:42:09] [TRT] [I] [MemUsageSnapshot] Builder begin: CPU 477 MiB, GPU 4987 MiB\n", - "[02/12/2022-17:42:10] [TRT] [W] TensorRT was linked against cuBLAS/cuBLAS LT 11.6.1 but loaded cuBLAS/cuBLAS LT 11.5.1\n", - "[02/12/2022-17:42:10] [TRT] [I] [MemUsageChange] Init cuBLAS/cuBLASLt: CPU +232, GPU +94, now: CPU 711, GPU 5081 (MiB)\n", - "[02/12/2022-17:42:10] [TRT] [I] [MemUsageChange] Init cuDNN: CPU +188, GPU +84, now: CPU 899, GPU 5165 (MiB)\n", - "[02/12/2022-17:42:10] [TRT] [I] Local timing cache in use. Profiling results in this builder pass will not be stored.\n", - "[02/12/2022-17:42:53] [TRT] [I] [BlockAssignment] Algorithm Linear took 0.054667ms to assign 150 blocks to 150 nodes requiring 13011862528 bytes.\n", - "[02/12/2022-17:42:53] [TRT] [I] Total Activation Memory: 126960640\n", - "[02/12/2022-17:42:53] [TRT] [I] Detected 1 inputs and 4 output network tensors.\n" + "[03/08/2022-22:14:50] [TRT] [I] [MemUsageChange] Init CUDA: CPU +177, GPU +0, now: CPU 356, GPU 8823 (MiB)\n", + "[03/08/2022-22:14:50] [TRT] [I] ----------------------------------------------------------------\n", + "[03/08/2022-22:14:50] [TRT] [I] Input filename: yolov5n6.onnx\n", + "[03/08/2022-22:14:50] [TRT] [I] ONNX IR version: 0.0.8\n", + "[03/08/2022-22:14:50] [TRT] [I] Opset version: 11\n", + "[03/08/2022-22:14:50] [TRT] [I] Producer name: \n", + "[03/08/2022-22:14:50] [TRT] [I] Producer version: \n", + "[03/08/2022-22:14:50] [TRT] [I] Domain: \n", + "[03/08/2022-22:14:50] [TRT] [I] Model version: 0\n", + "[03/08/2022-22:14:50] [TRT] [I] Doc string: \n", + "[03/08/2022-22:14:50] [TRT] [I] ----------------------------------------------------------------\n", + "[03/08/2022-22:14:50] [TRT] [W] parsers/onnx/onnx2trt_utils.cpp:364: Your ONNX model has been generated with INT64 weights, while TensorRT does not natively support INT64. Attempting to cast down to INT32.\n", + "[03/08/2022-22:14:50] [TRT] [W] parsers/onnx/onnx2trt_utils.cpp:392: One or more weights outside the range of INT32 was clamped\n", + "[03/08/2022-22:14:50] [TRT] [W] parsers/onnx/onnx2trt_utils.cpp:392: One or more weights outside the range of INT32 was clamped\n", + "[03/08/2022-22:14:50] [TRT] [W] parsers/onnx/onnx2trt_utils.cpp:392: One or more weights outside the range of INT32 was clamped\n", + "[03/08/2022-22:14:50] [TRT] [W] parsers/onnx/onnx2trt_utils.cpp:392: One or more weights outside the range of INT32 was clamped\n", + "[03/08/2022-22:14:50] [TRT] [W] parsers/onnx/onnx2trt_utils.cpp:392: One or more weights outside the range of INT32 was clamped\n", + "[03/08/2022-22:14:50] [TRT] [I] No importer registered for op: EfficientNMS_TRT. Attempting to import as plugin.\n", + "[03/08/2022-22:14:50] [TRT] [I] Searching for plugin: EfficientNMS_TRT, plugin_version: 1, plugin_namespace: \n", + "[03/08/2022-22:14:50] [TRT] [I] Successfully created plugin: EfficientNMS_TRT\n", + "[03/08/2022-22:14:50] [TRT] [I] [MemUsageSnapshot] Builder begin: CPU 428 MiB, GPU 8823 MiB\n", + "[03/08/2022-22:14:52] [TRT] [W] TensorRT was linked against cuBLAS/cuBLAS LT 11.6.1 but loaded cuBLAS/cuBLAS LT 11.5.1\n", + "[03/08/2022-22:14:52] [TRT] [I] [MemUsageChange] Init cuBLAS/cuBLASLt: CPU +232, GPU +94, now: CPU 662, GPU 8917 (MiB)\n", + "[03/08/2022-22:14:53] [TRT] [I] [MemUsageChange] Init cuDNN: CPU +188, GPU +84, now: CPU 850, GPU 9001 (MiB)\n", + "[03/08/2022-22:14:53] [TRT] [I] Local timing cache in use. Profiling results in this builder pass will not be stored.\n", + "[03/08/2022-22:16:22] [TRT] [I] [BlockAssignment] Algorithm Linear took 0.048343ms to assign 150 blocks to 150 nodes requiring 13011862528 bytes.\n", + "[03/08/2022-22:16:22] [TRT] [I] Total Activation Memory: 126960640\n", + "[03/08/2022-22:16:22] [TRT] [I] Detected 1 inputs and 4 output network tensors.\n" ] }, { @@ -357,15 +319,15 @@ "name": "stdout", "output_type": "stream", "text": [ - "[02/12/2022-17:42:58] [TRT] [I] Total Host Persistent Memory: 169904\n", - "[02/12/2022-17:42:58] [TRT] [I] Total Device Persistent Memory: 11788800\n", - "[02/12/2022-17:42:58] [TRT] [I] Total Scratch Memory: 48960768\n", - "[02/12/2022-17:42:58] [TRT] [I] [MemUsageStats] Peak memory usage of TRT CPU/GPU memory allocators: CPU 3 MiB, GPU 2096 MiB\n", - "[02/12/2022-17:42:58] [TRT] [I] [BlockAssignment] Algorithm ShiftNTopDown took 29.751ms to assign 8 blocks to 151 nodes requiring 66721280 bytes.\n", - "[02/12/2022-17:42:58] [TRT] [W] TensorRT was linked against cuBLAS/cuBLAS LT 11.6.1 but loaded cuBLAS/cuBLAS LT 11.5.1\n", - "[02/12/2022-17:42:58] [TRT] [I] [MemUsageChange] Init cuBLAS/cuBLASLt: CPU +0, GPU +8, now: CPU 2794, GPU 6061 (MiB)\n", - "[02/12/2022-17:42:58] [TRT] [I] [MemUsageChange] Init cuDNN: CPU +0, GPU +8, now: CPU 2794, GPU 6069 (MiB)\n", - "[02/12/2022-17:42:58] [TRT] [I] [MemUsageSnapshot] Builder end: CPU 2793 MiB, GPU 6035 MiB\n" + "[03/08/2022-22:16:28] [TRT] [I] Total Host Persistent Memory: 158656\n", + "[03/08/2022-22:16:28] [TRT] [I] Total Device Persistent Memory: 11637760\n", + "[03/08/2022-22:16:28] [TRT] [I] Total Scratch Memory: 48960768\n", + "[03/08/2022-22:16:28] [TRT] [I] [MemUsageStats] Peak memory usage of TRT CPU/GPU memory allocators: CPU 3 MiB, GPU 2096 MiB\n", + "[03/08/2022-22:16:28] [TRT] [I] [BlockAssignment] Algorithm ShiftNTopDown took 29.5911ms to assign 8 blocks to 151 nodes requiring 66721280 bytes.\n", + "[03/08/2022-22:16:28] [TRT] [W] TensorRT was linked against cuBLAS/cuBLAS LT 11.6.1 but loaded cuBLAS/cuBLAS LT 11.5.1\n", + "[03/08/2022-22:16:28] [TRT] [I] [MemUsageChange] Init cuBLAS/cuBLASLt: CPU +0, GPU +8, now: CPU 2744, GPU 9897 (MiB)\n", + "[03/08/2022-22:16:28] [TRT] [I] [MemUsageChange] Init cuDNN: CPU +1, GPU +8, now: CPU 2745, GPU 9905 (MiB)\n", + "[03/08/2022-22:16:29] [TRT] [I] [MemUsageSnapshot] Builder end: CPU 2744 MiB, GPU 9871 MiB\n" ] } ], @@ -418,20 +380,20 @@ "name": "stdout", "output_type": "stream", "text": [ - "[02/12/2022-17:42:58] [TRT] [I] The logger passed into createInferRuntime differs from one already provided for an existing builder, runtime, or refitter. Uses of the global logger, returned by nvinfer1::getLogger(), will return the existing value.\n", + "[03/08/2022-22:16:29] [TRT] [I] The logger passed into createInferRuntime differs from one already provided for an existing builder, runtime, or refitter. Uses of the global logger, returned by nvinfer1::getLogger(), will return the existing value.\n", "\n", - "[02/12/2022-17:42:58] [TRT] [I] [MemUsageChange] Init CUDA: CPU +0, GPU +0, now: CPU 2779, GPU 6003 (MiB)\n", - "[02/12/2022-17:42:58] [TRT] [I] Loaded engine size: 18 MiB\n", - "[02/12/2022-17:42:58] [TRT] [I] [MemUsageSnapshot] deserializeCudaEngine begin: CPU 2797 MiB, GPU 6003 MiB\n", - "[02/12/2022-17:42:58] [TRT] [W] TensorRT was linked against cuBLAS/cuBLAS LT 11.6.1 but loaded cuBLAS/cuBLAS LT 11.5.1\n", - "[02/12/2022-17:42:58] [TRT] [I] [MemUsageChange] Init cuBLAS/cuBLASLt: CPU +1, GPU +10, now: CPU 2810, GPU 6031 (MiB)\n", - "[02/12/2022-17:42:58] [TRT] [I] [MemUsageChange] Init cuDNN: CPU +0, GPU +8, now: CPU 2810, GPU 6039 (MiB)\n", - "[02/12/2022-17:42:58] [TRT] [I] [MemUsageSnapshot] deserializeCudaEngine end: CPU 2809 MiB, GPU 6021 MiB\n", - "[02/12/2022-17:42:58] [TRT] [I] [MemUsageSnapshot] ExecutionContext creation begin: CPU 2791 MiB, GPU 6043 MiB\n", - "[02/12/2022-17:42:58] [TRT] [W] TensorRT was linked against cuBLAS/cuBLAS LT 11.6.1 but loaded cuBLAS/cuBLAS LT 11.5.1\n", - "[02/12/2022-17:42:58] [TRT] [I] [MemUsageChange] Init cuBLAS/cuBLASLt: CPU +0, GPU +10, now: CPU 2791, GPU 6053 (MiB)\n", - "[02/12/2022-17:42:58] [TRT] [I] [MemUsageChange] Init cuDNN: CPU +0, GPU +8, now: CPU 2791, GPU 6061 (MiB)\n", - "[02/12/2022-17:42:58] [TRT] [I] [MemUsageSnapshot] ExecutionContext creation end: CPU 2793 MiB, GPU 6145 MiB\n" + "[03/08/2022-22:16:29] [TRT] [I] [MemUsageChange] Init CUDA: CPU +0, GPU +0, now: CPU 2730, GPU 9839 (MiB)\n", + "[03/08/2022-22:16:29] [TRT] [I] Loaded engine size: 18 MiB\n", + "[03/08/2022-22:16:29] [TRT] [I] [MemUsageSnapshot] deserializeCudaEngine begin: CPU 2748 MiB, GPU 9839 MiB\n", + "[03/08/2022-22:16:29] [TRT] [W] TensorRT was linked against cuBLAS/cuBLAS LT 11.6.1 but loaded cuBLAS/cuBLAS LT 11.5.1\n", + "[03/08/2022-22:16:29] [TRT] [I] [MemUsageChange] Init cuBLAS/cuBLASLt: CPU +0, GPU +10, now: CPU 2760, GPU 9867 (MiB)\n", + "[03/08/2022-22:16:29] [TRT] [I] [MemUsageChange] Init cuDNN: CPU +0, GPU +8, now: CPU 2760, GPU 9875 (MiB)\n", + "[03/08/2022-22:16:29] [TRT] [I] [MemUsageSnapshot] deserializeCudaEngine end: CPU 2760 MiB, GPU 9857 MiB\n", + "[03/08/2022-22:16:29] [TRT] [I] [MemUsageSnapshot] ExecutionContext creation begin: CPU 2742 MiB, GPU 9879 MiB\n", + "[03/08/2022-22:16:29] [TRT] [W] TensorRT was linked against cuBLAS/cuBLAS LT 11.6.1 but loaded cuBLAS/cuBLAS LT 11.5.1\n", + "[03/08/2022-22:16:29] [TRT] [I] [MemUsageChange] Init cuBLAS/cuBLASLt: CPU +0, GPU +10, now: CPU 2742, GPU 9889 (MiB)\n", + "[03/08/2022-22:16:29] [TRT] [I] [MemUsageChange] Init cuDNN: CPU +0, GPU +8, now: CPU 2742, GPU 9897 (MiB)\n", + "[03/08/2022-22:16:29] [TRT] [I] [MemUsageSnapshot] ExecutionContext creation end: CPU 2743 MiB, GPU 9981 MiB\n" ] } ], @@ -487,9 +449,9 @@ "[{'scores': tensor([0.88487, 0.84572, 0.78537, 0.72515], device='cuda:0'),\n", " 'labels': tensor([5, 0, 0, 0], device='cuda:0', dtype=torch.int32),\n", " 'boxes': tensor([[ 35.89635, 226.08698, 808.98145, 739.60950],\n", - " [ 50.38255, 387.47092, 240.80370, 898.42114],\n", + " [ 50.38258, 387.47092, 240.80365, 898.42114],\n", " [677.84216, 380.34561, 809.81213, 876.44397],\n", - " [224.94446, 391.35855, 347.93188, 866.14307]], device='cuda:0')}]" + " [224.94440, 391.35861, 347.93188, 866.14319]], device='cuda:0')}]" ] }, "execution_count": 13, @@ -524,52 +486,7 @@ "execution_count": 15, "id": "24a84c3d-4ea3-4e26-9245-0d6d9abbb55c", "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\n", - " from n params module arguments \n", - " 0 -1 1 1760 yolort.v5.models.common.Conv [3, 16, 6, 2, 2] \n", - " 1 -1 1 4672 yolort.v5.models.common.Conv [16, 32, 3, 2] \n", - " 2 -1 1 4800 yolort.v5.models.common.C3 [32, 32, 1] \n", - " 3 -1 1 18560 yolort.v5.models.common.Conv [32, 64, 3, 2] \n", - " 4 -1 2 29184 yolort.v5.models.common.C3 [64, 64, 2] \n", - " 5 -1 1 73984 yolort.v5.models.common.Conv [64, 128, 3, 2] \n", - " 6 -1 3 156928 yolort.v5.models.common.C3 [128, 128, 3] \n", - " 7 -1 1 221568 yolort.v5.models.common.Conv [128, 192, 3, 2] \n", - " 8 -1 1 167040 yolort.v5.models.common.C3 [192, 192, 1] \n", - " 9 -1 1 442880 yolort.v5.models.common.Conv [192, 256, 3, 2] \n", - " 10 -1 1 296448 yolort.v5.models.common.C3 [256, 256, 1] \n", - " 11 -1 1 164608 yolort.v5.models.common.SPPF [256, 256, 5] \n", - " 12 -1 1 49536 yolort.v5.models.common.Conv [256, 192, 1, 1] \n", - " 13 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] \n", - " 14 [-1, 8] 1 0 yolort.v5.models.common.Concat [1] \n", - " 15 -1 1 203904 yolort.v5.models.common.C3 [384, 192, 1, False] \n", - " 16 -1 1 24832 yolort.v5.models.common.Conv [192, 128, 1, 1] \n", - " 17 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] \n", - " 18 [-1, 6] 1 0 yolort.v5.models.common.Concat [1] \n", - " 19 -1 1 90880 yolort.v5.models.common.C3 [256, 128, 1, False] \n", - " 20 -1 1 8320 yolort.v5.models.common.Conv [128, 64, 1, 1] \n", - " 21 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] \n", - " 22 [-1, 4] 1 0 yolort.v5.models.common.Concat [1] \n", - " 23 -1 1 22912 yolort.v5.models.common.C3 [128, 64, 1, False] \n", - " 24 -1 1 36992 yolort.v5.models.common.Conv [64, 64, 3, 2] \n", - " 25 [-1, 20] 1 0 yolort.v5.models.common.Concat [1] \n", - " 26 -1 1 74496 yolort.v5.models.common.C3 [128, 128, 1, False] \n", - " 27 -1 1 147712 yolort.v5.models.common.Conv [128, 128, 3, 2] \n", - " 28 [-1, 16] 1 0 yolort.v5.models.common.Concat [1] \n", - " 29 -1 1 179328 yolort.v5.models.common.C3 [256, 192, 1, False] \n", - " 30 -1 1 332160 yolort.v5.models.common.Conv [192, 192, 3, 2] \n", - " 31 [-1, 12] 1 0 yolort.v5.models.common.Concat [1] \n", - " 32 -1 1 329216 yolort.v5.models.common.C3 [384, 256, 1, False] \n", - " 33 [23, 26, 29, 32] 1 164220 yolort.v5.models.yolo.Detect [80, [[19, 27, 44, 40, 38, 94], [96, 68, 86, 152, 180, 137], [140, 301, 303, 264, 238, 542], [436, 615, 739, 380, 925, 792]], [64, 128, 192, 256]]\n", - "Model Summary: 355 layers, 3246940 parameters, 3246940 gradients, 4.6 GFLOPs\n", - "\n" - ] - } - ], + "outputs": [], "source": [ "model = YOLOv5.load_from_yolov5(\n", " model_path,\n", @@ -644,50 +561,66 @@ ] }, { - "cell_type": "code", - "execution_count": 18, - "id": "de81eb10-d918-4f23-bacb-321e1536d583", + "cell_type": "markdown", + "id": "11223bcd-bda4-4876-98e2-74cc8115a656", "metadata": {}, - "outputs": [], "source": [ - "# Get label names\n", - "import requests\n", - "\n", - "# label_path = \"https://raw.githubusercontent.com/zhiqwang/yolov5-rt-stack/main/notebooks/assets/coco.names\"\n", - "label_path = \"https://huggingface.co/spaces/zhiqwang/assets/resolve/main/coco.names\"\n", - "response = requests.get(label_path)\n", - "names = response.text\n", - "\n", - "LABELS = []\n", - "\n", - "for label in names.strip().split('\\n'):\n", - " LABELS.append(label)\n", - "\n", - "COLORS = color_list()" + "Get label names first." ] }, { "cell_type": "code", - "execution_count": 19, - "id": "8c9b641c-4ead-4208-971f-1b7459fb69c4", + "execution_count": 18, + "id": "de81eb10-d918-4f23-bacb-321e1536d583", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Downloading https://huggingface.co/spaces/zhiqwang/assets/resolve/main/coco.names to coco.names...\n" + ] + }, + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "c6849a4a70674e0cbece42c431b688d2", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + " 0%| | 0.00/621 [00:00" + "" ] }, "metadata": {}, @@ -695,7 +628,9 @@ } ], "source": [ - "cv2_imshow(img_raw, imshow_scale=0.5)" + "v = Visualizer(img_raw, metalabels=label_path)\n", + "v.draw_instance_predictions(predictions_trt[0])\n", + "v.imshow(scale=0.5)" ] } ],