mirror of
				https://github.com/THU-MIG/yolov10.git
				synced 2025-11-04 17:05:40 +08:00 
			
		
		
		
	Accept model=yolov5*u.yaml arguments (#4230)
				
					
				
			This commit is contained in:
		
							parent
							
								
									7dcdca3bf4
								
							
						
					
					
						commit
						f5fc807fa7
					
				@ -26,12 +26,10 @@ You can use many of these models directly in the Command Line Interface (CLI) or
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
## Usage
 | 
					## Usage
 | 
				
			||||||
 | 
					
 | 
				
			||||||
You can use RT-DETR for object detection tasks using the `ultralytics` pip package. The following is a sample code snippet showing how to use RT-DETR models for training and inference:
 | 
					    This example provides simple inference code for YOLO, SAM and RTDETR models. For more options including handling inference results see [Predict](../modes/predict.md) mode. For using models with additional modes see [Train](../modes/train.md), [Val](../modes/val.md) and [Export](../modes/export.md).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
!!! example ""
 | 
					!!! example ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    This example provides simple inference code for YOLO, SAM and RTDETR models. For more options including handling inference results see [Predict](../modes/predict.md) mode. For using models with additional modes see [Train](../modes/train.md), [Val](../modes/val.md) and [Export](../modes/export.md).
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    === "Python"
 | 
					    === "Python"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        PyTorch pretrained `*.pt` models as well as configuration `*.yaml` files can be passed to the `YOLO()`, `SAM()`, `NAS()` and `RTDETR()` classes to create a model instance in python:
 | 
					        PyTorch pretrained `*.pt` models as well as configuration `*.yaml` files can be passed to the `YOLO()`, `SAM()`, `NAS()` and `RTDETR()` classes to create a model instance in python:
 | 
				
			||||||
 | 
				
			|||||||
@ -1,3 +1,5 @@
 | 
				
			|||||||
 | 
					# Ultralytics YOLO 🚀, AGPL-3.0 license
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from pathlib import Path
 | 
					from pathlib import Path
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from ultralytics import SAM, YOLO
 | 
					from ultralytics import SAM, YOLO
 | 
				
			||||||
 | 
				
			|||||||
@ -1,3 +1,5 @@
 | 
				
			|||||||
 | 
					# Ultralytics YOLO 🚀, AGPL-3.0 license
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import json
 | 
					import json
 | 
				
			||||||
from collections import defaultdict
 | 
					from collections import defaultdict
 | 
				
			||||||
from pathlib import Path
 | 
					from pathlib import Path
 | 
				
			||||||
 | 
				
			|||||||
@ -1,4 +1,5 @@
 | 
				
			|||||||
# Ultralytics YOLO 🚀, AGPL-3.0 license
 | 
					# Ultralytics YOLO 🚀, AGPL-3.0 license
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import signal
 | 
					import signal
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
from pathlib import Path
 | 
					from pathlib import Path
 | 
				
			||||||
 | 
				
			|||||||
@ -1,4 +1,5 @@
 | 
				
			|||||||
# Ultralytics YOLO 🚀, GPL-3.0 license
 | 
					# Ultralytics YOLO 🚀, GPL-3.0 license
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import pkg_resources as pkg
 | 
					import pkg_resources as pkg
 | 
				
			||||||
 | 
				
			|||||||
@ -1,4 +1,5 @@
 | 
				
			|||||||
# Ultralytics YOLO 🚀, AGPL-3.0 license
 | 
					# Ultralytics YOLO 🚀, AGPL-3.0 license
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from ultralytics.utils import SETTINGS, TESTS_RUNNING
 | 
					from ultralytics.utils import SETTINGS, TESTS_RUNNING
 | 
				
			||||||
from ultralytics.utils.torch_utils import model_info_for_loggers
 | 
					from ultralytics.utils.torch_utils import model_info_for_loggers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -341,15 +341,19 @@ def check_suffix(file='yolov8n.pt', suffix='.pt', msg=''):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
def check_yolov5u_filename(file: str, verbose: bool = True):
 | 
					def check_yolov5u_filename(file: str, verbose: bool = True):
 | 
				
			||||||
    """Replace legacy YOLOv5 filenames with updated YOLOv5u filenames."""
 | 
					    """Replace legacy YOLOv5 filenames with updated YOLOv5u filenames."""
 | 
				
			||||||
    if ('yolov3' in file or 'yolov5' in file) and 'u' not in file:
 | 
					    if 'yolov3' in file or 'yolov5' in file:
 | 
				
			||||||
        original_file = file
 | 
					        if 'u.yaml' in file:
 | 
				
			||||||
        file = re.sub(r'(.*yolov5([nsmlx]))\.pt', '\\1u.pt', file)  # i.e. yolov5n.pt -> yolov5nu.pt
 | 
					            file = file.replace('u.yaml', '.yaml')  # i.e. yolov5nu.yaml -> yolov5n.yaml
 | 
				
			||||||
        file = re.sub(r'(.*yolov5([nsmlx])6)\.pt', '\\1u.pt', file)  # i.e. yolov5n6.pt -> yolov5n6u.pt
 | 
					        elif '.pt' in file and 'u' not in file:
 | 
				
			||||||
        file = re.sub(r'(.*yolov3(|-tiny|-spp))\.pt', '\\1u.pt', file)  # i.e. yolov3-spp.pt -> yolov3-sppu.pt
 | 
					            original_file = file
 | 
				
			||||||
        if file != original_file and verbose:
 | 
					            file = re.sub(r'(.*yolov5([nsmlx]))\.pt', '\\1u.pt', file)  # i.e. yolov5n.pt -> yolov5nu.pt
 | 
				
			||||||
            LOGGER.info(f"PRO TIP 💡 Replace 'model={original_file}' with new 'model={file}'.\nYOLOv5 'u' models are "
 | 
					            file = re.sub(r'(.*yolov5([nsmlx])6)\.pt', '\\1u.pt', file)  # i.e. yolov5n6.pt -> yolov5n6u.pt
 | 
				
			||||||
                        f'trained with https://github.com/ultralytics/ultralytics and feature improved performance vs '
 | 
					            file = re.sub(r'(.*yolov3(|-tiny|-spp))\.pt', '\\1u.pt', file)  # i.e. yolov3-spp.pt -> yolov3-sppu.pt
 | 
				
			||||||
                        f'standard YOLOv5 models trained with https://github.com/ultralytics/yolov5.\n')
 | 
					            if file != original_file and verbose:
 | 
				
			||||||
 | 
					                LOGGER.info(
 | 
				
			||||||
 | 
					                    f"PRO TIP 💡 Replace 'model={original_file}' with new 'model={file}'.\nYOLOv5 'u' models are "
 | 
				
			||||||
 | 
					                    f'trained with https://github.com/ultralytics/ultralytics and feature improved performance vs '
 | 
				
			||||||
 | 
					                    f'standard YOLOv5 models trained with https://github.com/ultralytics/yolov5.\n')
 | 
				
			||||||
    return file
 | 
					    return file
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,4 +1,5 @@
 | 
				
			|||||||
# Ultralytics YOLO 🚀, AGPL-3.0 license
 | 
					# Ultralytics YOLO 🚀, AGPL-3.0 license
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import math
 | 
					import math
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import platform
 | 
					import platform
 | 
				
			||||||
 | 
				
			|||||||
@ -1,4 +1,5 @@
 | 
				
			|||||||
# Ultralytics YOLO 🚀, AGPL-3.0 license
 | 
					# Ultralytics YOLO 🚀, AGPL-3.0 license
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from ultralytics.cfg import TASK2DATA, TASK2METRIC
 | 
					from ultralytics.cfg import TASK2DATA, TASK2METRIC
 | 
				
			||||||
from ultralytics.utils import DEFAULT_CFG_DICT, LOGGER, NUM_THREADS
 | 
					from ultralytics.utils import DEFAULT_CFG_DICT, LOGGER, NUM_THREADS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user