I got it in the following way. But do we have a better way to do it ? here net impies the model.
for n, m in net.named_children():
num_children = sum(1 for i in m.children())
if num_children != 0:
# in a layer of resnet
layer = getattr(net, n)
# decomp every bottleneck
for i in range(num_children):
BasicBlock = layer[i]
conv2 = getattr(BasicBlock, ‘conv2’)
#print(conv2)
decompose = function_call
# s += count_params(conv2)
setattr(BasicBlock, ‘conv2’,decompose)
#print(decompose)
conv1 = getattr(BasicBlock, ‘conv1’)
#print(conv1)
decompose = function_call
# s += count_params(conv2)
setattr(BasicBlock, ‘conv1’,decompose)
conv = getattr(BasicBlock, ‘downsample’)
if(conv) :
c = getattr(conv, ‘0’)
decompose = function_call
setattr(conv, ‘0’,decompose)