MCPcopy
hub / github.com/WongKinYiu/PyTorch_YOLOv4 / fuse

Method fuse

models/models.py:546–561  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

544 return x, p
545
546 def fuse(self):
547 # Fuse Conv2d + BatchNorm2d layers throughout model
548 print('Fusing layers...')
549 fused_list = nn.ModuleList()
550 for a in list(self.children())[0]:
551 if isinstance(a, nn.Sequential):
552 for i, b in enumerate(a):
553 if isinstance(b, nn.modules.batchnorm.BatchNorm2d):
554 # fuse this bn layer with the previous conv2d layer
555 conv = a[i - 1]
556 fused = torch_utils.fuse_conv_and_bn(conv, b)
557 a = nn.Sequential(fused, *list(a.children())[i + 1:])
558 break
559 fused_list.append(a)
560 self.module_list = fused_list
561 self.info() if not ONNX_EXPORT else None # yolov3-spp reduced from 225 to 152 layers
562
563 def info(self, verbose=False):
564 torch_utils.model_info(self, verbose)

Callers 2

attempt_loadFunction · 0.80
export.pyFile · 0.80

Calls 1

infoMethod · 0.95

Tested by

no test coverage detected