glenn-jocher
commited on
Commit
•
46daa7b
1
Parent(s):
36d12a5
Remove `.autoshape()` method (#5694)
Browse files- hubconf.py +2 -1
- models/common.py +3 -5
- models/yolo.py +1 -8
hubconf.py
CHANGED
@@ -27,6 +27,7 @@ def _create(name, pretrained=True, channels=3, classes=80, autoshape=True, verbo
|
|
27 |
"""
|
28 |
from pathlib import Path
|
29 |
|
|
|
30 |
from models.experimental import attempt_load
|
31 |
from models.yolo import Model
|
32 |
from utils.downloads import attempt_download
|
@@ -55,7 +56,7 @@ def _create(name, pretrained=True, channels=3, classes=80, autoshape=True, verbo
|
|
55 |
if len(ckpt['model'].names) == classes:
|
56 |
model.names = ckpt['model'].names # set class names attribute
|
57 |
if autoshape:
|
58 |
-
model = model
|
59 |
return model.to(device)
|
60 |
|
61 |
except Exception as e:
|
|
|
27 |
"""
|
28 |
from pathlib import Path
|
29 |
|
30 |
+
from models.common import AutoShape
|
31 |
from models.experimental import attempt_load
|
32 |
from models.yolo import Model
|
33 |
from utils.downloads import attempt_download
|
|
|
56 |
if len(ckpt['model'].names) == classes:
|
57 |
model.names = ckpt['model'].names # set class names attribute
|
58 |
if autoshape:
|
59 |
+
model = AutoShape(model) # for file/URI/PIL/cv2/np inputs and NMS
|
60 |
return model.to(device)
|
61 |
|
62 |
except Exception as e:
|
models/common.py
CHANGED
@@ -23,7 +23,7 @@ from utils.datasets import exif_transpose, letterbox
|
|
23 |
from utils.general import (LOGGER, check_requirements, check_suffix, colorstr, increment_path, make_divisible,
|
24 |
non_max_suppression, scale_coords, xywh2xyxy, xyxy2xywh)
|
25 |
from utils.plots import Annotator, colors, save_one_box
|
26 |
-
from utils.torch_utils import time_sync
|
27 |
|
28 |
|
29 |
def autopad(k, p=None): # kernel, padding
|
@@ -405,12 +405,10 @@ class AutoShape(nn.Module):
|
|
405 |
|
406 |
def __init__(self, model):
|
407 |
super().__init__()
|
|
|
|
|
408 |
self.model = model.eval()
|
409 |
|
410 |
-
def autoshape(self):
|
411 |
-
LOGGER.info('AutoShape already enabled, skipping... ') # model already converted to model.autoshape()
|
412 |
-
return self
|
413 |
-
|
414 |
def _apply(self, fn):
|
415 |
# Apply to(), cpu(), cuda(), half() to model tensors that are not parameters or registered buffers
|
416 |
self = super()._apply(fn)
|
|
|
23 |
from utils.general import (LOGGER, check_requirements, check_suffix, colorstr, increment_path, make_divisible,
|
24 |
non_max_suppression, scale_coords, xywh2xyxy, xyxy2xywh)
|
25 |
from utils.plots import Annotator, colors, save_one_box
|
26 |
+
from utils.torch_utils import copy_attr, time_sync
|
27 |
|
28 |
|
29 |
def autopad(k, p=None): # kernel, padding
|
|
|
405 |
|
406 |
def __init__(self, model):
|
407 |
super().__init__()
|
408 |
+
LOGGER.info('Adding AutoShape... ')
|
409 |
+
copy_attr(self, model, include=('yaml', 'nc', 'hyp', 'names', 'stride', 'abc'), exclude=()) # copy attributes
|
410 |
self.model = model.eval()
|
411 |
|
|
|
|
|
|
|
|
|
412 |
def _apply(self, fn):
|
413 |
# Apply to(), cpu(), cuda(), half() to model tensors that are not parameters or registered buffers
|
414 |
self = super()._apply(fn)
|
models/yolo.py
CHANGED
@@ -22,8 +22,7 @@ from models.experimental import *
|
|
22 |
from utils.autoanchor import check_anchor_order
|
23 |
from utils.general import LOGGER, check_version, check_yaml, make_divisible, print_args
|
24 |
from utils.plots import feature_visualization
|
25 |
-
from utils.torch_utils import
|
26 |
-
time_sync)
|
27 |
|
28 |
try:
|
29 |
import thop # for FLOPs computation
|
@@ -226,12 +225,6 @@ class Model(nn.Module):
|
|
226 |
self.info()
|
227 |
return self
|
228 |
|
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 |
-
|
235 |
def info(self, verbose=False, img_size=640): # print model information
|
236 |
model_info(self, verbose, img_size)
|
237 |
|
|
|
22 |
from utils.autoanchor import check_anchor_order
|
23 |
from utils.general import LOGGER, check_version, check_yaml, make_divisible, print_args
|
24 |
from utils.plots import feature_visualization
|
25 |
+
from utils.torch_utils import fuse_conv_and_bn, initialize_weights, model_info, scale_img, select_device, time_sync
|
|
|
26 |
|
27 |
try:
|
28 |
import thop # for FLOPs computation
|
|
|
225 |
self.info()
|
226 |
return self
|
227 |
|
|
|
|
|
|
|
|
|
|
|
|
|
228 |
def info(self, verbose=False, img_size=640): # print model information
|
229 |
model_info(self, verbose, img_size)
|
230 |
|