Two dimensional size=(h,w) AutoShape support (#9072)
* Two dimensional `size=(h,w)` AutoShape support May resolve https://github.com/ultralytics/yolov5/issues/9039 Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com> * Update hubconf.py Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
db2ee5fa0c
commit
262187e95d
2 files changed
+12
-6
No files matched your search
+7
-3
@@ -30,7 +30,7 @@ def _create(name, pretrained=True, channels=3, classes=80, autoshape=True, verbo
|
||||
|
||||
from models.common import AutoShape, DetectMultiBackend
|
||||
from models.experimental import attempt_load
|
||||
from models.yolo import DetectionModel
|
||||
from models.yolo import ClassificationModel, DetectionModel
|
||||
from utils.downloads import attempt_download
|
||||
from utils.general import LOGGER, check_requirements, intersect_dicts, logging
|
||||
from utils.torch_utils import select_device
|
||||
@@ -45,8 +45,12 @@ def _create(name, pretrained=True, channels=3, classes=80, autoshape=True, verbo
|
||||
if pretrained and channels == 3 and classes == 80:
|
||||
try:
|
||||
model = DetectMultiBackend(path, device=device, fuse=autoshape) # detection model
|
||||
if autoshape and isinstance(model.model, DetectionModel):
|
||||
model = AutoShape(model) # for file/URI/PIL/cv2/np inputs and NMS
|
||||
if autoshape:
|
||||
if model.pt and isinstance(model.model, ClassificationModel):
|
||||
LOGGER.warning('WARNING: YOLOv5 v6.2 ClassificationModel is not yet AutoShape compatible. '
|
||||
'You must pass torch tensors in BCHW to this model, i.e. shape(1,3,224,224).')
|
||||
else:
|
||||
model = AutoShape(model) # for file/URI/PIL/cv2/np inputs and NMS
|
||||
except Exception:
|
||||
model = attempt_load(path, device=device, fuse=False) # arbitrary model
|
||||
else:
|
||||
|
||||
Reference in new issue
Block a user