MCPcopy Create free account
hub / github.com/OpenGVLab/HumanBench / hook

Function hook

PATH/helper/param_count.py:83–88  ·  view source on GitHub ↗
(module, x)

Source from the content-addressed store, hash-verified

81 for m in model.modules():
82 if isinstance(m, nn.Conv2d):
83 def hook(module, x):
84 out_h = int((x[0].size()[2] + 2 * module.padding[0] - module.kernel_size[0]) / module.stride[0] + 1)
85 out_w = int((x[0].size()[3] + 2 * module.padding[1] - module.kernel_size[1]) / module.stride[1] + 1)
86 ops = module.in_channels * module.out_channels * module.kernel_size[0] * module.kernel_size[1] * out_h * out_w / module.groups * multi_add
87 flop_counts.append(ops)
88 param_counts.append(get_layer_param(module))
89 m.register_forward_pre_hook(hook)
90
91 elif isinstance(m, nn.ReLU) or isinstance(m, nn.PReLU):

Callers

nothing calls this directly

Calls 2

get_layer_paramFunction · 0.85
sizeMethod · 0.80

Tested by

no test coverage detected