AutoShape() models as DetectMultiBackend() instances (#5845)
* Update AutoShape() * autodownload ONNX * Cleanup * Finish updates * Add Usage * Update * Update * Update * Update * Update * Update * Update * Update * Update * Update * Update * Update * Update * Update * Update * Update * Update * fix device * Update hubconf.py * Update common.py * smart param selection * autodownload all formats * autopad only pytorch models * new_shape edits * stride tensor fix * Cleanup
This commit is contained in:
1 parent
d885799c71
commit
7bf04d9bbf
4 files changed
+35
-25
No files matched your search
+7
-7
@@ -5,6 +5,7 @@ PyTorch Hub models https://pytorch.org/hub/ultralytics_yolov5/
|
||||
Usage:
|
||||
import torch
|
||||
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
|
||||
model = torch.hub.load('ultralytics/yolov5:master', 'custom', 'path/to/yolov5s.onnx') # file from branch
|
||||
"""
|
||||
|
||||
import torch
|
||||
@@ -27,26 +28,25 @@ def _create(name, pretrained=True, channels=3, classes=80, autoshape=True, verbo
|
||||
"""
|
||||
from pathlib import Path
|
||||
|
||||
from models.common import AutoShape
|
||||
from models.experimental import attempt_load
|
||||
from models.common import AutoShape, DetectMultiBackend
|
||||
from models.yolo import Model
|
||||
from utils.downloads import attempt_download
|
||||
from utils.general import check_requirements, intersect_dicts, set_logging
|
||||
from utils.torch_utils import select_device
|
||||
|
||||
file = Path(__file__).resolve()
|
||||
check_requirements(exclude=('tensorboard', 'thop', 'opencv-python'))
|
||||
set_logging(verbose=verbose)
|
||||
|
||||
save_dir = Path('') if str(name).endswith('.pt') else file.parent
|
||||
path = (save_dir / name).with_suffix('.pt') # checkpoint path
|
||||
name = Path(name)
|
||||
path = name.with_suffix('.pt') if name.suffix == '' else name # checkpoint path
|
||||
try:
|
||||
device = select_device(('0' if torch.cuda.is_available() else 'cpu') if device is None else device)
|
||||
|
||||
if pretrained and channels == 3 and classes == 80:
|
||||
model = attempt_load(path, map_location=device) # download/load FP32 model
|
||||
model = DetectMultiBackend(path, device=device) # download/load FP32 model
|
||||
# model = models.experimental.attempt_load(path, map_location=device) # download/load FP32 model
|
||||
else:
|
||||
cfg = list((Path(__file__).parent / 'models').rglob(f'{name}.yaml'))[0] # model.yaml path
|
||||
cfg = list((Path(__file__).parent / 'models').rglob(f'{path.name}.yaml'))[0] # model.yaml path
|
||||
model = Model(cfg, channels, classes) # create model
|
||||
if pretrained:
|
||||
ckpt = torch.load(attempt_download(path), map_location=device) # load
|
||||
|
||||
Reference in new issue
Block a user