mirror of
				https://github.com/THU-MIG/yolov10.git
				synced 2025-10-29 04:45:40 +08:00 
			
		
		
		
	Add yolo_bbox2segment docs reference (#7751)
				
					
				
			Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com> Co-authored-by: Muhammad Rizwan Munawar <chr043416@gmail.com>
This commit is contained in:
		
							parent
							
								
									cb72761a3b
								
							
						
					
					
						commit
						12a741c76f
					
				| @ -10,11 +10,12 @@ import re | |||||||
| from collections import defaultdict | from collections import defaultdict | ||||||
| from pathlib import Path | 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 | # Constants | ||||||
| CODE_DIR = ROOT | REFERENCE_DIR = PACKAGE_DIR.parent / "docs/en/reference" | ||||||
| REFERENCE_DIR = ROOT.parent / "docs/en/reference" | GITHUB_REPO = "ultralytics/ultralytics" | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def extract_classes_and_functions(filepath: Path) -> tuple: | def extract_classes_and_functions(filepath: Path) -> tuple: | ||||||
| @ -44,8 +45,8 @@ def create_markdown(py_filepath: Path, module_path: str, classes: list, function | |||||||
| 
 | 
 | ||||||
|     module_name = module_path.replace(".__init__", "") |     module_name = module_path.replace(".__init__", "") | ||||||
|     module_path = module_path.replace(".", "/") |     module_path = module_path.replace(".", "/") | ||||||
|     url = f"https://github.com/ultralytics/ultralytics/blob/main/{module_path}.py" |     url = f"https://github.com/{GITHUB_REPO}/blob/main/{module_path}.py" | ||||||
|     edit = f"https://github.com/ultralytics/ultralytics/edit/main/{module_path}.py" |     edit = f"https://github.com/{GITHUB_REPO}/edit/main/{module_path}.py" | ||||||
|     title_content = ( |     title_content = ( | ||||||
|         f"# Reference for `{module_path}.py`\n\n" |         f"# Reference for `{module_path}.py`\n\n" | ||||||
|         f"!!! Note\n\n" |         f"!!! Note\n\n" | ||||||
| @ -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.parent.mkdir(parents=True, exist_ok=True) | ||||||
|     md_filepath.write_text(md_content) |     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: | def nested_dict() -> defaultdict: | ||||||
| @ -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())} |     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.""" |     """Creates a YAML file for the navigation menu based on the provided list of items.""" | ||||||
|     nav_tree = nested_dict() |     nav_tree = nested_dict() | ||||||
| 
 | 
 | ||||||
| @ -104,20 +105,21 @@ def create_nav_menu_yaml(nav_items: list): | |||||||
|     print("Scan complete, new mkdocs.yaml reference section is:\n\n", _dict_to_yaml(nav_tree_sorted)) |     print("Scan complete, new mkdocs.yaml reference section is:\n\n", _dict_to_yaml(nav_tree_sorted)) | ||||||
| 
 | 
 | ||||||
|     # Save new YAML reference section |     # 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(): | def main(): | ||||||
|     """Main function to extract class and function names, create Markdown files, and generate a YAML navigation menu.""" |     """Main function to extract class and function names, create Markdown files, and generate a YAML navigation menu.""" | ||||||
|     nav_items = [] |     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) |         classes, functions = extract_classes_and_functions(py_filepath) | ||||||
| 
 | 
 | ||||||
|         if classes or functions: |         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 |             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) |             md_rel_filepath = create_markdown(md_filepath, module_path, classes, functions) | ||||||
|             nav_items.append(str(md_rel_filepath)) |             nav_items.append(str(md_rel_filepath)) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -182,15 +182,15 @@ A heatmap generated with [Ultralytics YOLOv8](https://github.com/ultralytics/ult | |||||||
|         model = YOLO("yolov8s.pt")   # YOLOv8 custom/pretrained model |         model = YOLO("yolov8s.pt")   # YOLOv8 custom/pretrained model | ||||||
| 
 | 
 | ||||||
|         im0 = cv2.imread("path/to/image.png")  # path to image file |         im0 = cv2.imread("path/to/image.png")  # path to image file | ||||||
|  |         h, w = im0.shape[:2]  # image height and width | ||||||
|          |          | ||||||
|         # Heatmap Init |         # Heatmap Init | ||||||
|         heatmap_obj = heatmap.Heatmap() |         heatmap_obj = heatmap.Heatmap() | ||||||
|         heatmap_obj.set_args(colormap=cv2.COLORMAP_PARULA, |         heatmap_obj.set_args(colormap=cv2.COLORMAP_PARULA, | ||||||
|                                      imw=im0.shape[0],  # should same as im0 width |                              imw=w, | ||||||
|                                      imh=im0.shape[1],  # should same as im0 height |                              imh=h, | ||||||
|                                      view_img=True, |                              view_img=True, | ||||||
|                                      shape="circle") |                              shape="circle") | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
|         results = model.track(im0, persist=True) |         results = model.track(im0, persist=True) | ||||||
|         im0 = heatmap_obj.generate_heatmap(im0, tracks=results) |         im0 = heatmap_obj.generate_heatmap(im0, tracks=results) | ||||||
|  | |||||||
| @ -34,3 +34,7 @@ keywords: Ultralytics, Data Converter, coco91_to_coco80_class, merge_multi_segme | |||||||
| ## ::: ultralytics.data.converter.merge_multi_segment | ## ::: ultralytics.data.converter.merge_multi_segment | ||||||
| 
 | 
 | ||||||
| <br><br> | <br><br> | ||||||
|  | 
 | ||||||
|  | ## ::: ultralytics.data.converter.yolo_bbox2segment | ||||||
|  | 
 | ||||||
|  | <br><br> | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Glenn Jocher
						Glenn Jocher