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

Add support for some missing modules #58

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions convert_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ def lua_recursive_model(module,seq):
n = LambdaReduce(lambda x,y,dim=dim: torch.cat((x,y),dim))
lua_recursive_model(m,n)
add_submodule(seq,n)
elif name == 'Tanh':
n = nn.Tanh()
add_submodule(seq, n)
elif name == 'MulConstant':
n = Lambda(lambda x: x * m.constant_scalar)
add_submodule(seq, n)
elif name == 'SpatialZeroPadding':
n = nn.ConstantPad2d((m.pad_l, m.pad_r, m.pad_t, m.pad_b), 0)
add_submodule(seq, n)
elif name == 'InstanceNormalization':
n = m._instance_norm
copy_param(m, n) # check this
add_submodule(seq, n)
elif name == 'TorchObject':
print('Not Implement',name,real._typename)
else:
Expand Down Expand Up @@ -229,6 +242,14 @@ def lua_recursive_source(module):
s += ['LambdaReduce(lambda x,y,dim={}: torch.cat((x,y),dim), # Concat'.format(m.dimension)]
s += lua_recursive_source(m)
s += [')']
elif name == 'Tanh':
s += ['nn.Tanh()']
elif name == 'MulConstant':
s += ['Lambda(lambda x: x*{}), # MulConstant'.format(m.constant_scalar)]
elif name == 'SpatialZeroPadding':
s += ['nn.ConstantPad2d({}, 0)'.format((m.pad_l, m.pad_r, m.pad_t, m.pad_b))]
elif name == 'InstanceNormalization':
s += ['nn.InstanceNorm2d({},{},{},{}), # InstanceNorm2d'.format(m._instance_norm.num_features, m.eps, m._instance_norm.momentum, m._instance_norm.affine)]
else:
s += '# ' + name + ' Not Implement,\n'
s = map(lambda x: '\t{}'.format(x),s)
Expand Down