Skip to content

Commit c9ac992

Browse files
authored
Remove .autoshape() method (ultralytics#5694)
1 parent 4d615c3 commit c9ac992

File tree

3 files changed

+6
-14
lines changed

3 files changed

+6
-14
lines changed

hubconf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def _create(name, pretrained=True, channels=3, classes=80, autoshape=True, verbo
2727
"""
2828
from pathlib import Path
2929

30+
from models.common import AutoShape
3031
from models.experimental import attempt_load
3132
from models.yolo import Model
3233
from utils.downloads import attempt_download
@@ -55,7 +56,7 @@ def _create(name, pretrained=True, channels=3, classes=80, autoshape=True, verbo
5556
if len(ckpt['model'].names) == classes:
5657
model.names = ckpt['model'].names # set class names attribute
5758
if autoshape:
58-
model = model.autoshape() # for file/URI/PIL/cv2/np inputs and NMS
59+
model = AutoShape(model) # for file/URI/PIL/cv2/np inputs and NMS
5960
return model.to(device)
6061

6162
except Exception as e:

models/common.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from utils.general import (LOGGER, check_requirements, check_suffix, colorstr, increment_path, make_divisible,
2424
non_max_suppression, scale_coords, xywh2xyxy, xyxy2xywh)
2525
from utils.plots import Annotator, colors, save_one_box
26-
from utils.torch_utils import time_sync
26+
from utils.torch_utils import copy_attr, time_sync
2727

2828

2929
def autopad(k, p=None): # kernel, padding
@@ -405,12 +405,10 @@ class AutoShape(nn.Module):
405405

406406
def __init__(self, model):
407407
super().__init__()
408+
LOGGER.info('Adding AutoShape... ')
409+
copy_attr(self, model, include=('yaml', 'nc', 'hyp', 'names', 'stride', 'abc'), exclude=()) # copy attributes
408410
self.model = model.eval()
409411

410-
def autoshape(self):
411-
LOGGER.info('AutoShape already enabled, skipping... ') # model already converted to model.autoshape()
412-
return self
413-
414412
def _apply(self, fn):
415413
# Apply to(), cpu(), cuda(), half() to model tensors that are not parameters or registered buffers
416414
self = super()._apply(fn)

models/yolo.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
from utils.autoanchor import check_anchor_order
2323
from utils.general import LOGGER, check_version, check_yaml, make_divisible, print_args
2424
from utils.plots import feature_visualization
25-
from utils.torch_utils import (copy_attr, fuse_conv_and_bn, initialize_weights, model_info, scale_img, select_device,
26-
time_sync)
25+
from utils.torch_utils import fuse_conv_and_bn, initialize_weights, model_info, scale_img, select_device, time_sync
2726

2827
try:
2928
import thop # for FLOPs computation
@@ -226,12 +225,6 @@ def fuse(self): # fuse model Conv2d() + BatchNorm2d() layers
226225
self.info()
227226
return self
228227

229-
def autoshape(self): # add AutoShape module
230-
LOGGER.info('Adding AutoShape... ')
231-
m = AutoShape(self) # wrap model
232-
copy_attr(m, self, include=('yaml', 'nc', 'hyp', 'names', 'stride'), exclude=()) # copy attributes
233-
return m
234-
235228
def info(self, verbose=False, img_size=640): # print model information
236229
model_info(self, verbose, img_size)
237230

0 commit comments

Comments
 (0)