Bläddra i källkod

model.fuse() fix for export.py (#827)

5.0
Glenn Jocher 4 år sedan
förälder
incheckning
a8751e50de
2 ändrade filer med 4 tillägg och 2 borttagningar
  1. +3
    -1
      models/export.py
  2. +1
    -1
      models/yolo.py

+ 3
- 1
models/export.py Visa fil

@@ -28,6 +28,9 @@ if __name__ == '__main__':
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

@@ -47,7 +50,6 @@ if __name__ == '__main__':

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'])


+ 1
- 1
models/yolo.py Visa fil

@@ -163,7 +163,7 @@ class Model(nn.Module):
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

Laddar…
Avbryt
Spara