Skip to content

Commit

Permalink
Update export.py with --train mode argument (ultralytics#3066)
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-jocher authored and danny-schwartz7 committed May 22, 2021
1 parent b3fa0b3 commit 9cf091c
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions models/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
parser.add_argument('--device', default='cpu', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
parser.add_argument('--half', action='store_true', help='FP16 half-precision export')
parser.add_argument('--inplace', action='store_true', help='set YOLOv5 Detect() inplace=True')
parser.add_argument('--train', action='store_true', help='model.train() mode')
parser.add_argument('--dynamic', action='store_true', help='dynamic ONNX axes') # ONNX-only
parser.add_argument('--simplify', action='store_true', help='simplify ONNX model') # ONNX-only
opt = parser.parse_args()
Expand All @@ -53,6 +54,8 @@
# Update model
if opt.half:
img, model = img.half(), model.half() # to FP16
if opt.train:
model.train() # training mode (no grid construction in Detect layer)
for k, m in model.named_modules():
m._non_persistent_buffers_set = set() # pytorch 1.6.0 compatibility
if isinstance(m, models.common.Conv): # assign export-friendly activations
Expand Down

0 comments on commit 9cf091c

Please sign in to comment.