From 89b63777231b51d5ca60db6b4361bcf159218cb4 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 19 Mar 2020 18:11:08 -0700 Subject: [PATCH] Fuse by default when test.py called directly (faster) --- models.py | 2 +- test.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/models.py b/models.py index 4a815e7d..ee9b98c3 100755 --- a/models.py +++ b/models.py @@ -311,7 +311,7 @@ class Darknet(nn.Module): def fuse(self): # Fuse Conv2d + BatchNorm2d layers throughout model - print('Fusing Conv2d() and BatchNorm2d() layers...') + print('Fusing layers...') fused_list = nn.ModuleList() for a in list(self.children())[0]: if isinstance(a, nn.Sequential): diff --git a/test.py b/test.py index d9439f6b..991448c3 100644 --- a/test.py +++ b/test.py @@ -29,7 +29,7 @@ def test(cfg, os.remove(f) # Initialize model - model = Darknet(cfg, img_size).to(device) + model = Darknet(cfg, img_size) # Load weights attempt_download(weights) @@ -38,6 +38,10 @@ def test(cfg, else: # darknet format load_darknet_weights(model, weights) + # Fuse + model.fuse() + model.to(device) + if device.type != 'cpu' and torch.cuda.device_count() > 1: model = nn.DataParallel(model) else: # called by train.py