Unverified 提交 ffcbd8ca authored 作者: Glenn Jocher's avatar Glenn Jocher 提交者: GitHub

Export with official `nn.SiLU()` (#7256)

* Update * Update time_limit
上级 dda669a1
...@@ -54,7 +54,6 @@ from pathlib import Path ...@@ -54,7 +54,6 @@ from pathlib import Path
import pandas as pd import pandas as pd
import torch import torch
import torch.nn as nn
from torch.utils.mobile_optimizer import optimize_for_mobile from torch.utils.mobile_optimizer import optimize_for_mobile
FILE = Path(__file__).resolve() FILE = Path(__file__).resolve()
...@@ -64,10 +63,8 @@ if str(ROOT) not in sys.path: ...@@ -64,10 +63,8 @@ if str(ROOT) not in sys.path:
if platform.system() != 'Windows': if platform.system() != 'Windows':
ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative
from models.common import Conv
from models.experimental import attempt_load from models.experimental import attempt_load
from models.yolo import Detect from models.yolo import Detect
from utils.activations import SiLU
from utils.datasets import LoadImages from utils.datasets import LoadImages
from utils.general import (LOGGER, check_dataset, check_img_size, check_requirements, check_version, colorstr, from utils.general import (LOGGER, check_dataset, check_img_size, check_requirements, check_version, colorstr,
file_size, print_args, url2file) file_size, print_args, url2file)
...@@ -474,10 +471,10 @@ def run( ...@@ -474,10 +471,10 @@ def run(
im, model = im.half(), model.half() # to FP16 im, model = im.half(), model.half() # to FP16
model.train() if train else model.eval() # training mode = no Detect() layer grid construction model.train() if train else model.eval() # training mode = no Detect() layer grid construction
for k, m in model.named_modules(): for k, m in model.named_modules():
if isinstance(m, Conv): # assign export-friendly activations # if isinstance(m, Conv): # assign export-friendly activations
if isinstance(m.act, nn.SiLU): # if isinstance(m.act, nn.SiLU):
m.act = SiLU() # m.act = SiLU()
elif isinstance(m, Detect): if isinstance(m, Detect):
m.inplace = inplace m.inplace = inplace
m.onnx_dynamic = dynamic m.onnx_dynamic = dynamic
if hasattr(m, 'forward_export'): if hasattr(m, 'forward_export'):
......
...@@ -738,7 +738,7 @@ def non_max_suppression(prediction, ...@@ -738,7 +738,7 @@ def non_max_suppression(prediction,
# min_wh = 2 # (pixels) minimum box width and height # min_wh = 2 # (pixels) minimum box width and height
max_wh = 7680 # (pixels) maximum box width and height max_wh = 7680 # (pixels) maximum box width and height
max_nms = 30000 # maximum number of boxes into torchvision.ops.nms() max_nms = 30000 # maximum number of boxes into torchvision.ops.nms()
time_limit = 0.030 * bs # seconds to quit after time_limit = 0.1 + 0.03 * bs # seconds to quit after
redundant = True # require redundant detections redundant = True # require redundant detections
multi_label &= nc > 1 # multiple labels per box (adds 0.5ms/img) multi_label &= nc > 1 # multiple labels per box (adds 0.5ms/img)
merge = False # use merge-NMS merge = False # use merge-NMS
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论