MCPcopy Index your code
hub / github.com/ActiveVisionLab/DFNet / freeze_bn_layer

Function freeze_bn_layer

script/utils/utils.py:18–28  ·  view source on GitHub ↗

freeze bn layer by not require grad but still behave differently when model.train() vs. model.eval()

(model)

Source from the content-addressed store, hash-verified

16# from pykalman import KalmanFilter
17
18def freeze_bn_layer(model):
19 ''' freeze bn layer by not require grad but still behave differently when model.train() vs. model.eval() '''
20 print("Freezing BatchNorm Layers...")
21 for module in model.modules():
22 if isinstance(module, nn.BatchNorm2d):
23 # print("this is a BN layer:", module)
24 if hasattr(module, 'weight'):
25 module.weight.requires_grad_(False)
26 if hasattr(module, 'bias'):
27 module.bias.requires_grad_(False)
28 return model
29
30def freeze_bn_layer_train(model):
31 ''' set batchnorm to eval()

Callers 3

trainFunction · 0.90
evalFunction · 0.90
train_featureFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected