From 218c428c7fc2310d6a4014e594c7b1b0a7171b33 Mon Sep 17 00:00:00 2001 From: Zhiqiang Wang Date: Thu, 20 May 2021 22:07:22 +0800 Subject: [PATCH] Add missing copyright, cleanup and fix docs (#110) * Add missing copyright and cleanup files * Fixing the labels in bug-report.md * Add symbolic link of notebooks in docs * Revert of adding symbolic link of notebooks in docs * Add symbolic link of notebooks in docs --- .github/ISSUE_TEMPLATE/bug-report.md | 2 +- .../notebooks/export_onnx_inference_onnxruntime.ipynb | 1 + .../source/notebooks/export_relay_inference_tvm.ipynb | 1 + .../notebooks/inference_pytorch_export_libtorch.ipynb | 1 + docs/source/notebooks/load_model_as_ultralytics.ipynb | 1 + docs/source/notebooks/visualize_jit_models.ipynb | 1 + yolort/utils/graph_utils.py | 8 +++++++- yolort/utils/image_utils.py | 8 +++++--- yolort/utils/yolo2coco.py | 11 ++++++----- 9 files changed, 24 insertions(+), 10 deletions(-) create mode 120000 docs/source/notebooks/export_onnx_inference_onnxruntime.ipynb create mode 120000 docs/source/notebooks/export_relay_inference_tvm.ipynb create mode 120000 docs/source/notebooks/inference_pytorch_export_libtorch.ipynb create mode 120000 docs/source/notebooks/load_model_as_ultralytics.ipynb create mode 120000 docs/source/notebooks/visualize_jit_models.ipynb diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md index f0df2fea..eef2c154 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.md +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -2,7 +2,7 @@ name: "\U0001F41B Bug Report" about: Create a report to help us improve torchvision title: '' -labels: bug +labels: bug / fix assignees: '' --- diff --git a/docs/source/notebooks/export_onnx_inference_onnxruntime.ipynb b/docs/source/notebooks/export_onnx_inference_onnxruntime.ipynb new file mode 120000 index 00000000..b32c66a6 --- /dev/null +++ b/docs/source/notebooks/export_onnx_inference_onnxruntime.ipynb @@ -0,0 +1 @@ +../../../notebooks/export-onnx-inference-onnxruntime.ipynb \ No newline at end of file diff --git a/docs/source/notebooks/export_relay_inference_tvm.ipynb b/docs/source/notebooks/export_relay_inference_tvm.ipynb new file mode 120000 index 00000000..ae432eea --- /dev/null +++ b/docs/source/notebooks/export_relay_inference_tvm.ipynb @@ -0,0 +1 @@ +../../../notebooks/export-relay-inference-tvm.ipynb \ No newline at end of file diff --git a/docs/source/notebooks/inference_pytorch_export_libtorch.ipynb b/docs/source/notebooks/inference_pytorch_export_libtorch.ipynb new file mode 120000 index 00000000..5f698948 --- /dev/null +++ b/docs/source/notebooks/inference_pytorch_export_libtorch.ipynb @@ -0,0 +1 @@ +../../../notebooks/inference-pytorch-export-libtorch.ipynb \ No newline at end of file diff --git a/docs/source/notebooks/load_model_as_ultralytics.ipynb b/docs/source/notebooks/load_model_as_ultralytics.ipynb new file mode 120000 index 00000000..25ebacfe --- /dev/null +++ b/docs/source/notebooks/load_model_as_ultralytics.ipynb @@ -0,0 +1 @@ +../../../notebooks/load-model-as-ultralytics.ipynb \ No newline at end of file diff --git a/docs/source/notebooks/visualize_jit_models.ipynb b/docs/source/notebooks/visualize_jit_models.ipynb new file mode 120000 index 00000000..30a566d1 --- /dev/null +++ b/docs/source/notebooks/visualize_jit_models.ipynb @@ -0,0 +1 @@ +../../../notebooks/visualize-jit-models.ipynb \ No newline at end of file diff --git a/yolort/utils/graph_utils.py b/yolort/utils/graph_utils.py index a87ed1cc..a6b9090a 100644 --- a/yolort/utils/graph_utils.py +++ b/yolort/utils/graph_utils.py @@ -1,6 +1,12 @@ +# Copyright (c) 2020, Thomas Viehmann. All Rights Reserved. """ -Plotting a graph with bad gradient nodes marked in red. +Visualizing JIT Modules + Mostly copy-paste from https://github.com/t-vi/pytorch-tvmisc/tree/master/hacks +with license under the CC-BY-SA 4.0. + +Please link to Thomas's blog post or the original github source (linked from the +blog post) with the attribution notice. """ from graphviz import Digraph diff --git a/yolort/utils/image_utils.py b/yolort/utils/image_utils.py index 46fc5c9a..80603e51 100644 --- a/yolort/utils/image_utils.py +++ b/yolort/utils/image_utils.py @@ -11,13 +11,13 @@ import torch from torch import Tensor -from torchvision import transforms + from torchvision.ops.boxes import box_convert from typing import Optional import logging -logger = logging.getLogger(__name__) + def plot_one_box(box, img, color=None, label=None, line_thickness=None): @@ -47,7 +47,7 @@ def cv2_imshow( convert_bgr_to_rgb: bool = True, ) -> None: """ - A replacement for cv2.imshow() for use in Jupyter notebooks. + A replacement of cv2.imshow() for using in Jupyter notebooks. Args: image (np.ndarray):. shape (N, M) or (N, M, 1) is an NxM grayscale image. shape (N, M, 3) @@ -194,6 +194,8 @@ def load_names(category_path): @torch.no_grad() def overlay_boxes(detections, path, time_consume, args): + logger = logging.getLogger(__name__) + img = cv2.imread(path) if args.save_img else None for i, pred in enumerate(detections): # detections per image diff --git a/yolort/utils/yolo2coco.py b/yolort/utils/yolo2coco.py index 7dbc2f8d..18532cc3 100644 --- a/yolort/utils/yolo2coco.py +++ b/yolort/utils/yolo2coco.py @@ -1,3 +1,4 @@ +# Copyright (c) 2020, Zhiqiang Wang. All Rights Reserved. from pathlib import Path import argparse @@ -7,7 +8,7 @@ from .builtin_meta import COCO_CATEGORIES -class Yolo2Coco: +class YOLO2COCO: def __init__(self, root, split): self.info = { @@ -24,8 +25,8 @@ def __init__(self, root, split): self.type = 'instances' self.split = split self.root_path = Path(root) - self.label_path = self.root_path.joinpath('labels') - self.annotation_root = self.root_path.joinpath('annotations') + self.label_path = self.root_path / 'labels' + self.annotation_root = self.root_path / 'annotations' Path(self.annotation_root).mkdir(parents=True, exist_ok=True) self.categories = [{ @@ -48,7 +49,7 @@ def generate(self, coco_type='instances', annotation_format='bbox'): 'annotations': annotations, 'categories': self.categories, } - output_path = self.annotation_root.joinpath(f'{coco_type}_{self.split}.json') + output_path = self.annotation_root / f'{coco_type}_{self.split}.json' with open(output_path, 'w') as json_file: json.dump(json_data, json_file, sort_keys=True) @@ -124,5 +125,5 @@ def _get_annotation(vertex_info, height, width): args = parser.parse_args() - converter = Yolo2Coco(args.data_path, args.split) + converter = YOLO2COCO(args.data_path, args.split) converter.generate()