Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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