Skip to content

Commit

Permalink
model.fuse() fix for export.py (#827)
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-jocher committed Aug 25, 2020
1 parent 5f07782 commit a8751e5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion models/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
attempt_download(opt.weights)
model = torch.load(opt.weights, map_location=torch.device('cpu'))['model'].float()
model.eval()
model.fuse()

# Update model
model.model[-1].export = True # set Detect() layer export=True
y = model(img) # dry run

Expand All @@ -47,7 +50,6 @@

print('\nStarting ONNX export with onnx %s...' % onnx.__version__)
f = opt.weights.replace('.pt', '.onnx') # filename
model.fuse() # only for ONNX
torch.onnx.export(model, img, f, verbose=False, opset_version=12, input_names=['images'],
output_names=['classes', 'boxes'] if y is None else ['output'])

Expand Down
2 changes: 1 addition & 1 deletion models/yolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def fuse(self): # fuse model Conv2d() + BatchNorm2d() layers
if type(m) is Conv:
m._non_persistent_buffers_set = set() # pytorch 1.6.0 compatability
m.conv = fuse_conv_and_bn(m.conv, m.bn) # update conv
m.bn = None # remove batchnorm
delattr(m, 'bn') # remove batchnorm
m.forward = m.fuseforward # update forward
self.info()
return self
Expand Down

0 comments on commit a8751e5

Please sign in to comment.