Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Module' object is not callable #4

Open
guoguoguilai opened this issue May 13, 2019 · 4 comments
Open

'Module' object is not callable #4

guoguoguilai opened this issue May 13, 2019 · 4 comments

Comments

@guoguoguilai
Copy link

I loaded the model from .json and .params,
sym, arg_params, aux_params = mx.model.load_checkpoint(prefix[3], epoch[3])
mod = mx.mod.Module(symbol=L106_Net96_v2("test"), context=mx.gpu(), data_names=['data'], label_names=['landmark_target'])
mod.bind(for_training=False, data_shapes=[('data', (batch_size[3], 3, 96, 96))])
mod.set_params(arg_params, aux_params)
When I call pytorch_model = gluon2pytorch(mod, [(batch_size[3], 3, 96, 96)], dst_dir=None, pytorch_module_name='Test')
Return: TypeError: 'Module' object is not callable

How can I solve this problem?How to convert module to be hybrid ?

@gmalivenko
Copy link
Owner

Hello @guoguoguilai.
Can you provide me full source code so I can reproduce your error?

@guoguoguilai
Copy link
Author

Hello @guoguoguilai.
Can you provide me full source code so I can reproduce your error?

import mxnet as mx
from gluon2pytorch import gluon2pytorch

def L106_Net96_v2(mode="train"):
# def L106_Net96(mode="train"):
"""
Refine Network
input shape 3 x 96 x 96
"""
lnet106_basenum = 32
data = mx.symbol.Variable(name="data")
landmark_target = mx.symbol.Variable(name="landmark_target")

conv1 = mx.symbol.Convolution(data=data, kernel=(3, 3), num_filter=lnet106_basenum, name="conv1")  # 96/94
bn1 = mx.sym.BatchNorm(data=conv1, name='bn1', fix_gamma=False, momentum=0.9)
prelu1 = mx.symbol.LeakyReLU(data=bn1, act_type="prelu", name="prelu1")

conv2_dw = mx.symbol.Convolution(data=prelu1, kernel=(2, 2), num_filter=lnet106_basenum, num_group=lnet106_basenum,
                                 name="conv2_dw")  # 94/93
bn2_dw = mx.sym.BatchNorm(data=conv2_dw, name='bn2_dw', fix_gamma=False, momentum=0.9)
prelu2_dw = mx.symbol.LeakyReLU(data=bn2_dw, act_type="prelu", name="prelu2_dw")
conv2_sep = mx.symbol.Convolution(data=prelu2_dw, kernel=(1, 1), num_filter=lnet106_basenum, name="conv2_sep")
bn2_sep = mx.sym.BatchNorm(data=conv2_sep, name='bn2_sep', fix_gamma=False, momentum=0.9)
prelu2_sep = mx.symbol.LeakyReLU(data=bn2_sep, act_type="prelu", name="prelu2_sep")

conv3_dw = mx.symbol.Convolution(data=prelu2_sep, kernel=(3, 3), stride=(2, 2), num_filter=lnet106_basenum,
                                 num_group=lnet106_basenum, name="conv3_dw")  # 93/46
bn3_dw = mx.sym.BatchNorm(data=conv3_dw, name='bn3_dw', fix_gamma=False, momentum=0.9)
prelu3_dw = mx.symbol.LeakyReLU(data=bn3_dw, act_type="prelu", name="prelu3_dw")
conv3_sep = mx.symbol.Convolution(data=prelu3_dw, kernel=(1, 1), num_filter=lnet106_basenum * 2, name="conv3_sep")
bn3_sep = mx.sym.BatchNorm(data=conv3_sep, name='bn3_sep', fix_gamma=False, momentum=0.9)
prelu3_sep = mx.symbol.LeakyReLU(data=bn3_sep, act_type="prelu", name="prelu3_sep")

conv4_dw = mx.symbol.Convolution(data=prelu3_sep, kernel=(2, 2), num_filter=lnet106_basenum * 2,
                                 num_group=lnet106_basenum * 2, name="conv4_dw")  # 46/45
bn4_dw = mx.sym.BatchNorm(data=conv4_dw, name='bn4_dw', fix_gamma=False, momentum=0.9)
prelu4_dw = mx.symbol.LeakyReLU(data=bn4_dw, act_type="prelu", name="prelu4_dw")
conv4_sep = mx.symbol.Convolution(data=prelu4_dw, kernel=(1, 1), num_filter=lnet106_basenum * 2, name="conv4_sep")
bn4_sep = mx.sym.BatchNorm(data=conv4_sep, name='bn4_sep', fix_gamma=False, momentum=0.9)
prelu4_sep = mx.symbol.LeakyReLU(data=bn4_sep, act_type="prelu", name="prelu4_sep")

conv5_dw = mx.symbol.Convolution(data=prelu4_sep, kernel=(3, 3), stride=(2, 2), num_filter=lnet106_basenum * 2,
                                 num_group=lnet106_basenum * 2, name="conv5_dw")  # 45/22
bn5_dw = mx.sym.BatchNorm(data=conv5_dw, name='bn5_dw', fix_gamma=False, momentum=0.9)
prelu5_dw = mx.symbol.LeakyReLU(data=bn5_dw, act_type="prelu", name="prelu5_dw")
conv5_sep = mx.symbol.Convolution(data=prelu5_dw, kernel=(1, 1), num_filter=lnet106_basenum * 2, name="conv5_sep")
bn5_sep = mx.sym.BatchNorm(data=conv5_sep, name='bn5_sep', fix_gamma=False, momentum=0.9)
prelu5_sep = mx.symbol.LeakyReLU(data=bn5_sep, act_type="prelu", name="prelu5_sep")

conv6_dw = mx.symbol.Convolution(data=prelu5_sep, kernel=(2, 2), num_filter=lnet106_basenum * 2,
                                 num_group=lnet106_basenum * 2, name="conv6_dw")  # 22/21
bn6_dw = mx.sym.BatchNorm(data=conv6_dw, name='bn6_dw', fix_gamma=False, momentum=0.9)
prelu6_dw = mx.symbol.LeakyReLU(data=bn6_dw, act_type="prelu", name="prelu6_dw")
conv6_sep = mx.symbol.Convolution(data=prelu6_dw, kernel=(1, 1), num_filter=lnet106_basenum * 2, name="conv6_sep")
bn6_sep = mx.sym.BatchNorm(data=conv6_sep, name='bn6_sep', fix_gamma=False, momentum=0.9)
prelu6_sep = mx.symbol.LeakyReLU(data=bn6_sep, act_type="prelu", name="prelu6_sep")

conv7_dw = mx.symbol.Convolution(data=prelu6_sep, kernel=(3, 3), stride=(2, 2), num_filter=lnet106_basenum * 2,
                                 num_group=lnet106_basenum * 2, name="conv7_dw")  # 21/10
bn7_dw = mx.sym.BatchNorm(data=conv7_dw, name='bn7_dw', fix_gamma=False, momentum=0.9)
prelu7_dw = mx.symbol.LeakyReLU(data=bn7_dw, act_type="prelu", name="prelu7_dw")
conv7_sep = mx.symbol.Convolution(data=prelu7_dw, kernel=(1, 1), num_filter=lnet106_basenum * 4, name="conv7_sep")
bn7_sep = mx.sym.BatchNorm(data=conv7_sep, name='bn7_sep', fix_gamma=False, momentum=0.9)
prelu7_sep = mx.symbol.LeakyReLU(data=bn7_sep, act_type="prelu", name="prelu7_sep")

conv8_dw = mx.symbol.Convolution(data=prelu7_sep, kernel=(2, 2), num_filter=lnet106_basenum * 4,
                                 num_group=lnet106_basenum * 4, name="conv8_dw")  # 10/9
bn8_dw = mx.sym.BatchNorm(data=conv8_dw, name='bn8_dw', fix_gamma=False, momentum=0.9)
prelu8_dw = mx.symbol.LeakyReLU(data=bn8_dw, act_type="prelu", name="prelu8_dw")
conv8_sep = mx.symbol.Convolution(data=prelu8_dw, kernel=(1, 1), num_filter=lnet106_basenum * 4, name="conv8_sep")
bn8_sep = mx.sym.BatchNorm(data=conv8_sep, name='bn8_sep', fix_gamma=False, momentum=0.9)
prelu8_sep = mx.symbol.LeakyReLU(data=bn8_sep, act_type="prelu", name="prelu8_sep")

conv9_dw = mx.symbol.Convolution(data=prelu8_sep, kernel=(3, 3), stride=(2, 2), num_filter=lnet106_basenum * 4,
                                 num_group=lnet106_basenum * 4, name="conv9_dw")  # 9/4
bn9_dw = mx.sym.BatchNorm(data=conv9_dw, name='bn9_dw', fix_gamma=False, momentum=0.9)
prelu9_dw = mx.symbol.LeakyReLU(data=bn9_dw, act_type="prelu", name="prelu9_dw")
conv9_sep = mx.symbol.Convolution(data=prelu9_dw, kernel=(1, 1), num_filter=lnet106_basenum * 8, name="conv9_sep")
bn9_sep = mx.sym.BatchNorm(data=conv9_sep, name='bn9_sep', fix_gamma=False, momentum=0.9)
prelu9_sep = mx.symbol.LeakyReLU(data=bn9_sep, act_type="prelu", name="prelu9_sep")

conv10_dw = mx.symbol.Convolution(data=prelu9_sep, kernel=(2, 2), num_filter=lnet106_basenum * 8,
                                  num_group=lnet106_basenum * 8, name="conv10_dw")  # 4/3
bn10_dw = mx.sym.BatchNorm(data=conv10_dw, name='bn10_dw', fix_gamma=False, momentum=0.9)
prelu10_dw = mx.symbol.LeakyReLU(data=bn10_dw, act_type="prelu", name="prelu10_dw")
conv10_sep = mx.symbol.Convolution(data=prelu10_dw, kernel=(1, 1), num_filter=lnet106_basenum * 8,
                                   name="conv10_sep")
bn10_sep = mx.sym.BatchNorm(data=conv10_sep, name='bn10_sep', fix_gamma=False, momentum=0.9)
prelu10_sep = mx.symbol.LeakyReLU(data=bn10_sep, act_type="prelu", name="prelu10_sep")

conv11_dw = mx.symbol.Convolution(data=prelu10_sep, kernel=(3, 3), num_filter=lnet106_basenum * 8,
                                  num_group=lnet106_basenum * 8, name="conv11_dw")  # 3/1
bn11_dw = mx.sym.BatchNorm(data=conv11_dw, name='bn11_dw', fix_gamma=False, momentum=0.9)
prelu11_dw = mx.symbol.LeakyReLU(data=bn11_dw, act_type="prelu", name="prelu11_dw")
conv11_sep = mx.symbol.Convolution(data=prelu11_dw, kernel=(1, 1), num_filter=lnet106_basenum * 8,
                                   name="conv11_sep")
bn11_sep = mx.sym.BatchNorm(data=conv11_sep, name='bn11_sep', fix_gamma=False, momentum=0.9)
prelu11_sep = mx.symbol.LeakyReLU(data=bn11_sep, act_type="prelu", name="prelu11_sep")

conv6_3 = mx.symbol.FullyConnected(data=prelu11_sep, num_hidden=212, name="conv6_3")
bn6_3 = mx.sym.BatchNorm(data=conv6_3, name='bn6_3', fix_gamma=False, momentum=0.9)
if mode == "test":
    landmark_pred = bn6_3
    group = mx.symbol.Group([landmark_pred])
else:

    landmark_pred = mx.symbol.LinearRegressionOutput(data=bn6_3, label=landmark_target,
                                                     grad_scale=1, name="landmark_pred")
    #landmark_pred = mx.symbol.
    out = mx.symbol.Custom(landmark_pred=landmark_pred, landmark_target=landmark_target,
                           op_type='negativemining_onlylandmark106', name="negative_mining")
    group = mx.symbol.Group([out])
#mx.viz.plot_network(landmark_pred, title='alexnet', save_format='jpg', hide_weights=True).view()
return group

batch_size = 4
prefix = "L106"
epoch = 8000
sym, arg_params, aux_params = mx.model.load_checkpoint(prefix, epoch)
mod = mx.mod.Module(symbol=L106_Net96_v2("test"), context=mx.gpu(), data_names=['data'], label_names=['landmark_target'])
mod.bind(for_training=False, data_shapes=[('data', (batch_size, 3, 96, 96))])
mod.set_params(arg_params, aux_params)
pytorch_model = gluon2pytorch(mod, [(batch_size, 3, 96, 96)], dst_dir=None, pytorch_module_name='Test')

Thank you Thank you in advance!

@ooguz166
Copy link

ooguz166 commented Jul 16, 2021

Same Error on this code too:

 from gluon2pytorch import gluon2pytorch

  if __name__ == '__main__':
      net = get_model(name="i3d_resnet50_v1_ucf101", nclass=101, pretrained=True)
      net.hybridize()
      net.collect_params().initialize()
      pytorch_model = gluon2pytorch(net, [(1, 3, 224, 224)], dst_dir=None)

TypeError: 'module' object is not callable

@ooguz166
Copy link

Same Error on this code too:

 from gluon2pytorch import gluon2pytorch

  if __name__ == '__main__':
      net = get_model(name="i3d_resnet50_v1_ucf101", nclass=101, pretrained=True)
      net.hybridize()
      net.collect_params().initialize()
      pytorch_model = gluon2pytorch(net, [(1, 3, 224, 224)], dst_dir=None)

TypeError: 'module' object is not callable

İf you build the lib from the setup.py importing like this "from gluon2pytorch.gluon2pytorch import gluon2pytorch" solves the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants