From 0ebd3f2959992be55f65cfc908bdf2fd3b618cef Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 4 May 2023 01:27:00 +0200 Subject: [PATCH] `ultralytics 8.0.92` updates and fixes (#2361) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Yonghye Kwon Co-authored-by: introvin Co-authored-by: marinmarcillat <58145636+marinmarcillat@users.noreply.github.com> Co-authored-by: BIGBOSS-FOX <47949596+BIGBOSS-FOX@users.noreply.github.com> --- .pre-commit-config.yaml | 4 +-- docs/modes/train.md | 4 --- docs/overrides/partials/source-file.html | 26 +++++++++++++++++++ docs/quickstart.md | 2 +- docs/reference/yolo/utils/plotting.md | 5 ++++ docs/tasks/classify.md | 14 +++++++--- mkdocs.yml | 17 +++++++++--- setup.py | 11 ++++++-- ultralytics/__init__.py | 2 +- ultralytics/tracker/track.py | 2 +- ultralytics/vit/sam/modules/mask_generator.py | 4 +-- ultralytics/yolo/engine/predictor.py | 6 ++--- ultralytics/yolo/utils/__init__.py | 15 ++++++----- ultralytics/yolo/utils/plotting.py | 3 --- ultralytics/yolo/v8/detect/train.py | 2 +- 15 files changed, 82 insertions(+), 35 deletions(-) create mode 100644 docs/overrides/partials/source-file.html diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bb882501..60b2b305 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,7 +22,7 @@ repos: - id: detect-private-key - repo: https://github.com/asottile/pyupgrade - rev: v3.3.1 + rev: v3.3.2 hooks: - id: pyupgrade name: Upgrade code @@ -34,7 +34,7 @@ repos: name: Sort imports - repo: https://github.com/google/yapf - rev: v0.32.0 + rev: v0.33.0 hooks: - id: yapf name: YAPF formatting diff --git a/docs/modes/train.md b/docs/modes/train.md index a5c9de15..7a5a02d0 100644 --- a/docs/modes/train.md +++ b/docs/modes/train.md @@ -2,10 +2,6 @@ comments: true --- ---- -comments: true ---- - **Train mode** is used for training a YOLOv8 model on a custom dataset. In this mode, the model is trained using the diff --git a/docs/overrides/partials/source-file.html b/docs/overrides/partials/source-file.html new file mode 100644 index 00000000..95cc6051 --- /dev/null +++ b/docs/overrides/partials/source-file.html @@ -0,0 +1,26 @@ +{% import "partials/language.html" as lang with context %} + + + +
+
+ + + + {% if page.meta.git_revision_date_localized %} + 📅 {{ lang.t("source.file.date.updated") }}: + {{ page.meta.git_revision_date_localized }} + {% if page.meta.git_creation_date_localized %} +
+ 🎂 {{ lang.t("source.file.date.created") }}: + {{ page.meta.git_creation_date_localized }} + {% endif %} + + + {% elif page.meta.revision_date %} + 📅 {{ lang.t("source.file.date.updated") }}: + {{ page.meta.revision_date }} + {% endif %} +
+
diff --git a/docs/quickstart.md b/docs/quickstart.md index d31972df..25cebf62 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -96,7 +96,7 @@ CLI requires no customization or Python code. You can simply run all tasks from !!! warning "Warning" - Arguments must be passed as `arg=val` pairs, split by an equals `=` sign and delimited by spaces ` ` between pairs. Do not use `--` argument prefixes or commas `,` beteen arguments. + Arguments must be passed as `arg=val` pairs, split by an equals `=` sign and delimited by spaces ` ` between pairs. Do not use `--` argument prefixes or commas `,` between arguments. - `yolo predict model=yolov8n.pt imgsz=640 conf=0.25`   ✅ - `yolo predict model yolov8n.pt imgsz 640 conf 0.25`   ❌ diff --git a/docs/reference/yolo/utils/plotting.md b/docs/reference/yolo/utils/plotting.md index 04164ef0..a84e17ad 100644 --- a/docs/reference/yolo/utils/plotting.md +++ b/docs/reference/yolo/utils/plotting.md @@ -32,3 +32,8 @@ --- :::ultralytics.yolo.utils.plotting.output_to_target

+ +# feature_visualization +--- +:::ultralytics.yolo.utils.plotting.feature_visualization +

diff --git a/docs/tasks/classify.md b/docs/tasks/classify.md index 4ce4bb8f..d7333069 100644 --- a/docs/tasks/classify.md +++ b/docs/tasks/classify.md @@ -77,10 +77,16 @@ see the [Configuration](../usage/cfg.md) page. The YOLO classification dataset format is same as the torchvision format. Each class of images has its own folder and you have to simply pass the path of the dataset folder, i.e, `yolo classify train data="path/to/dataset"` ``` dataset/ -├── class1/ -├── class2/ -├── class3/ -├── ... +├── train/ +├──── class1/ +├──── class2/ +├──── class3/ +├──── ... +├── val/ +├──── class1/ +├──── class2/ +├──── class3/ +├──── ... ``` ## Val diff --git a/mkdocs.yml b/mkdocs.yml index cff952fd..804ef623 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -12,6 +12,8 @@ theme: custom_dir: docs/overrides logo: https://github.com/ultralytics/assets/raw/main/logo/Ultralytics_Logotype_Reverse.svg favicon: assets/favicon.ico + icon: + repo: fontawesome/brands/github font: text: Roboto code: Roboto Mono @@ -55,6 +57,7 @@ copyright: Ultralytics 2023.=6.0', 'openvino-dev>=2022.3', 'tensorflowjs'], # automatically installs tensorflow }, classifiers=[ diff --git a/ultralytics/__init__.py b/ultralytics/__init__.py index 1f4fb753..a6121429 100644 --- a/ultralytics/__init__.py +++ b/ultralytics/__init__.py @@ -1,6 +1,6 @@ # Ultralytics YOLO 🚀, AGPL-3.0 license -__version__ = '8.0.91' +__version__ = '8.0.92' from ultralytics.hub import start from ultralytics.vit.sam import SAM diff --git a/ultralytics/tracker/track.py b/ultralytics/tracker/track.py index b160f397..d08abfc7 100644 --- a/ultralytics/tracker/track.py +++ b/ultralytics/tracker/track.py @@ -47,7 +47,7 @@ def on_predict_postprocess_end(predictor): tracks = predictor.trackers[i].update(det, im0s[i]) if len(tracks) == 0: continue - idx = tracks[:, -1].tolist() + idx = tracks[:, -1].astype(int) predictor.results[i] = predictor.results[i][idx] predictor.results[i].update(boxes=torch.as_tensor(tracks[:, :-1])) diff --git a/ultralytics/vit/sam/modules/mask_generator.py b/ultralytics/vit/sam/modules/mask_generator.py index f0146080..61575346 100644 --- a/ultralytics/vit/sam/modules/mask_generator.py +++ b/ultralytics/vit/sam/modules/mask_generator.py @@ -82,8 +82,8 @@ class SamAutomaticMaskGenerator: memory. """ - assert (points_per_side is None) != (point_grids is - None), 'Exactly one of points_per_side or point_grid must be provided.' + assert (points_per_side is None) != (point_grids is None), \ + 'Exactly one of points_per_side or point_grid must be provided.' if points_per_side is not None: self.point_grids = build_all_layer_point_grids( points_per_side, diff --git a/ultralytics/yolo/engine/predictor.py b/ultralytics/yolo/engine/predictor.py index 957e97d0..e0763e21 100644 --- a/ultralytics/yolo/engine/predictor.py +++ b/ultralytics/yolo/engine/predictor.py @@ -115,10 +115,8 @@ class BasePredictor: im (torch.Tensor | List(np.ndarray)): (N, 3, h, w) for tensor, [(h, w, 3) x N] for list. """ if not isinstance(im, torch.Tensor): - auto = all(x.shape == im[0].shape for x in im) and self.model.pt - if not auto: - LOGGER.warning( - 'WARNING ⚠️ Source shapes differ. For optimal performance supply similarly-shaped sources.') + same_shapes = all(x.shape == im[0].shape for x in im) + auto = same_shapes and self.model.pt im = np.stack([LetterBox(self.imgsz, auto=auto, stride=self.model.stride)(image=x) for x in im]) im = im[..., ::-1].transpose((0, 3, 1, 2)) # BGR to RGB, BHWC to BCHW, (n, 3, h, w) im = np.ascontiguousarray(im) # contiguous diff --git a/ultralytics/yolo/utils/__init__.py b/ultralytics/yolo/utils/__init__.py index 90ebe63a..992897c8 100644 --- a/ultralytics/yolo/utils/__init__.py +++ b/ultralytics/yolo/utils/__init__.py @@ -259,13 +259,14 @@ def yaml_save(file='data.yaml', data=None): # Create parent directories if they don't exist file.parent.mkdir(parents=True, exist_ok=True) + # Convert Path objects to strings + for k, v in data.items(): + if isinstance(v, Path): + dict[k] = str(v) + + # Dump data to file in YAML format with open(file, 'w') as f: - # Dump data to file in YAML format, converting Path objects to strings - yaml.safe_dump({k: str(v) if isinstance(v, Path) else v - for k, v in data.items()}, - f, - sort_keys=False, - allow_unicode=True) + yaml.safe_dump(data, f, sort_keys=False, allow_unicode=True) def yaml_load(file='data.yaml', append_filename=False): @@ -759,7 +760,7 @@ ENVIRONMENT = 'Colab' if is_colab() else 'Kaggle' if is_kaggle() else 'Jupyter' TESTS_RUNNING = is_pytest_running() or is_github_actions_ci() set_sentry() -# OpenCV Multilanguage-friendly functions ------------------------------------------------------------------------------------ +# OpenCV Multilanguage-friendly functions ------------------------------------------------------------------------------ imshow_ = cv2.imshow # copy to avoid recursion errors diff --git a/ultralytics/yolo/utils/plotting.py b/ultralytics/yolo/utils/plotting.py index 0b352d81..a804c304 100644 --- a/ultralytics/yolo/utils/plotting.py +++ b/ultralytics/yolo/utils/plotting.py @@ -481,9 +481,6 @@ def feature_visualization(x, module_type, stage, n=32, save_dir=Path('runs/detec stage (int): Module stage within the model. n (int, optional): Maximum number of feature maps to plot. Defaults to 32. save_dir (Path, optional): Directory to save results. Defaults to Path('runs/detect/exp'). - - Returns: - None: This function does not return any value; it saves the visualization to the specified directory. """ for m in ['Detect', 'Pose', 'Segment']: if m in module_type: diff --git a/ultralytics/yolo/v8/detect/train.py b/ultralytics/yolo/v8/detect/train.py index ad49c8ae..af521a16 100644 --- a/ultralytics/yolo/v8/detect/train.py +++ b/ultralytics/yolo/v8/detect/train.py @@ -212,7 +212,6 @@ class Loss: pred_scores.detach().sigmoid(), (pred_bboxes.detach() * stride_tensor).type(gt_bboxes.dtype), anchor_points * stride_tensor, gt_labels, gt_bboxes, mask_gt) - target_bboxes /= stride_tensor target_scores_sum = max(target_scores.sum(), 1) # cls loss @@ -221,6 +220,7 @@ class Loss: # bbox loss if fg_mask.sum(): + target_bboxes /= stride_tensor loss[0], loss[2] = self.bbox_loss(pred_distri, pred_bboxes, anchor_points, target_bboxes, target_scores, target_scores_sum, fg_mask)