Skip to content

Commit

Permalink
Add yolo_bbox2segment docs reference (ultralytics#7751)
Browse files Browse the repository at this point in the history
Signed-off-by: Glenn Jocher <[email protected]>
Co-authored-by: Muhammad Rizwan Munawar <[email protected]>
  • Loading branch information
glenn-jocher and RizwanMunawar authored Jan 22, 2024
1 parent cb72761 commit 12a741c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
26 changes: 14 additions & 12 deletions docs/build_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
from collections import defaultdict
from pathlib import Path

from ultralytics.utils import ROOT
# Get package root i.e. /Users/glennjocher/PycharmProjects/ultralytics/ultralytics
from ultralytics.utils import ROOT as PACKAGE_DIR

NEW_YAML_DIR = ROOT.parent
CODE_DIR = ROOT
REFERENCE_DIR = ROOT.parent / "docs/en/reference"
# Constants
REFERENCE_DIR = PACKAGE_DIR.parent / "docs/en/reference"
GITHUB_REPO = "ultralytics/ultralytics"


def extract_classes_and_functions(filepath: Path) -> tuple:
Expand Down Expand Up @@ -44,8 +45,8 @@ def create_markdown(py_filepath: Path, module_path: str, classes: list, function

module_name = module_path.replace(".__init__", "")
module_path = module_path.replace(".", "/")
url = f"https://github.com/ultralytics/ultralytics/blob/main/{module_path}.py"
edit = f"https://github.com/ultralytics/ultralytics/edit/main/{module_path}.py"
url = f"https://github.com/{GITHUB_REPO}/blob/main/{module_path}.py"
edit = f"https://github.com/{GITHUB_REPO}/edit/main/{module_path}.py"
title_content = (
f"# Reference for `{module_path}.py`\n\n"
f"!!! Note\n\n"
Expand All @@ -60,7 +61,7 @@ def create_markdown(py_filepath: Path, module_path: str, classes: list, function
md_filepath.parent.mkdir(parents=True, exist_ok=True)
md_filepath.write_text(md_content)

return md_filepath.relative_to(NEW_YAML_DIR)
return md_filepath.relative_to(PACKAGE_DIR.parent)


def nested_dict() -> defaultdict:
Expand All @@ -73,7 +74,7 @@ def sort_nested_dict(d: dict) -> dict:
return {key: sort_nested_dict(value) if isinstance(value, dict) else value for key, value in sorted(d.items())}


def create_nav_menu_yaml(nav_items: list):
def create_nav_menu_yaml(nav_items: list, save: bool = False):
"""Creates a YAML file for the navigation menu based on the provided list of items."""
nav_tree = nested_dict()

Expand Down Expand Up @@ -104,20 +105,21 @@ def _dict_to_yaml(d, level=0):
print("Scan complete, new mkdocs.yaml reference section is:\n\n", _dict_to_yaml(nav_tree_sorted))

# Save new YAML reference section
# (NEW_YAML_DIR / 'nav_menu_updated.yml').write_text(_dict_to_yaml(nav_tree_sorted))
if save:
(PACKAGE_DIR.parent / "nav_menu_updated.yml").write_text(_dict_to_yaml(nav_tree_sorted))


def main():
"""Main function to extract class and function names, create Markdown files, and generate a YAML navigation menu."""
nav_items = []

for py_filepath in CODE_DIR.rglob("*.py"):
for py_filepath in PACKAGE_DIR.rglob("*.py"):
classes, functions = extract_classes_and_functions(py_filepath)

if classes or functions:
py_filepath_rel = py_filepath.relative_to(CODE_DIR)
py_filepath_rel = py_filepath.relative_to(PACKAGE_DIR)
md_filepath = REFERENCE_DIR / py_filepath_rel
module_path = f"ultralytics.{py_filepath_rel.with_suffix('').as_posix().replace('/', '.')}"
module_path = f"{PACKAGE_DIR.name}.{py_filepath_rel.with_suffix('').as_posix().replace('/', '.')}"
md_rel_filepath = create_markdown(md_filepath, module_path, classes, functions)
nav_items.append(str(md_rel_filepath))

Expand Down
12 changes: 6 additions & 6 deletions docs/en/guides/heatmaps.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,15 @@ A heatmap generated with [Ultralytics YOLOv8](https://github.com/ultralytics/ult
model = YOLO("yolov8s.pt") # YOLOv8 custom/pretrained model

im0 = cv2.imread("path/to/image.png") # path to image file

h, w = im0.shape[:2] # image height and width
# Heatmap Init
heatmap_obj = heatmap.Heatmap()
heatmap_obj.set_args(colormap=cv2.COLORMAP_PARULA,
imw=im0.shape[0], # should same as im0 width
imh=im0.shape[1], # should same as im0 height
view_img=True,
shape="circle")

imw=w,
imh=h,
view_img=True,
shape="circle")

results = model.track(im0, persist=True)
im0 = heatmap_obj.generate_heatmap(im0, tracks=results)
Expand Down
4 changes: 4 additions & 0 deletions docs/en/reference/data/converter.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ keywords: Ultralytics, Data Converter, coco91_to_coco80_class, merge_multi_segme
## ::: ultralytics.data.converter.merge_multi_segment

<br><br>

## ::: ultralytics.data.converter.yolo_bbox2segment

<br><br>

0 comments on commit 12a741c

Please sign in to comment.