Skip to content

Commit

Permalink
Export single output only (ultralytics#7259)
Browse files Browse the repository at this point in the history
* Update

* Update

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
glenn-jocher and pre-commit-ci[bot] committed Apr 3, 2022
1 parent 73ace7a commit d153b2d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions export.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ def run(
if isinstance(m, Detect):
m.inplace = inplace
m.onnx_dynamic = dynamic
m.export = True
if hasattr(m, 'forward_export'):
m.forward = m.forward_export # assign custom forward (optional)

Expand Down
3 changes: 2 additions & 1 deletion models/yolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
class Detect(nn.Module):
stride = None # strides computed during build
onnx_dynamic = False # ONNX export parameter
export = False # export mode

def __init__(self, nc=80, anchors=(), ch=(), inplace=True): # detection layer
super().__init__()
Expand Down Expand Up @@ -72,7 +73,7 @@ def forward(self, x):
y = torch.cat((xy, wh, conf), 4)
z.append(y.view(bs, -1, self.no))

return x if self.training else (torch.cat(z, 1), x)
return x if self.training else (torch.cat(z, 1),) if self.export else (torch.cat(z, 1), x)

def _make_grid(self, nx=20, ny=20, i=0):
d = self.anchors[i].device
Expand Down

0 comments on commit d153b2d

Please sign in to comment.