xxradon/PytorchToCaffe

Some error occur with Eltwise

DCSong opened this issue · 2 comments

I try to convert vggface2 model to caffe from this page.

from facenet_pytorch import InceptionResnetV1
model = InceptionResnetV1(pretrained='vggface2').eval()

The code like this:
`import torch
from torch.autograd import Variable
from torchvision.models import resnet
import pytorch_to_caffe
from facenet_pytorch import InceptionResnetV1

if name=='main':
name='VGGFace2'
# For a model pretrained on VGGFace2
model = InceptionResnetV1(pretrained='vggface2').eval()
input=torch.ones([1, 3, 512, 512])
pytorch_to_caffe.trans_net(model, input, name)
pytorch_to_caffe.save_prototxt('{}.prototxt'.format(name))
pytorch_to_caffe.save_caffemodel('{}.caffemodel'.format(name))`

And the error occurs:

bn_scale12 was added to layers
repeat_1.0.branch2.2.relu
relu12 was added to layers
140330631542496:relu_blob12 was added to blobs
repeat_1.0
cat1 was added to layers
140330631542816:cat_blob1 was added to blobs
repeat_1.0.conv2d
conv: cat_blob1
conv13 was added to layers
140330631542736:conv_blob13 was added to blobs
mul1 was added to layers
140330631543136:mul_blob1 was added to blobs
WARNING: CANNOT FOUND blob 140330856145392
Traceback (most recent call last):
File "/home/songdc/miniconda3/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/home/songdc/miniconda3/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/songdc/.vscode/extensions/ms-python.python-2020.8.101144/pythonFiles/lib/python/debugpy/main.py", line 45, in
cli.main()
File "/home/songdc/.vscode/extensions/ms-python.python-2020.8.101144/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 430, in main
run()
File "/home/songdc/.vscode/extensions/ms-python.python-2020.8.101144/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 267, in run_file
runpy.run_path(options.target, run_name=compat.force_str("main"))
File "/home/songdc/miniconda3/lib/python3.7/runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "/home/songdc/miniconda3/lib/python3.7/runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "/home/songdc/miniconda3/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/songdc/Downloads/PytorchToCaffe/VGGFace2_pytorch_2_caffe.py", line 14, in
pytorch_to_caffe.trans_net(model, input, name)
File "/home/songdc/Downloads/PytorchToCaffe/pytorch_to_caffe.py", line 786, in trans_net
out = net.forward(input_var)
File "/home/songdc/miniconda3/lib/python3.7/site-packages/facenet_pytorch/models/inception_resnet_v1.py", line 288, in forward
x = self.repeat_1(x)
File "/home/songdc/miniconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 547, in call
result = self.forward(*input, **kwargs)
File "/home/songdc/miniconda3/lib/python3.7/site-packages/torch/nn/modules/container.py", line 92, in forward
input = module(input)
File "/home/songdc/miniconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 547, in call
result = self.forward(*input, **kwargs)
File "/home/songdc/miniconda3/lib/python3.7/site-packages/facenet_pytorch/models/inception_resnet_v1.py", line 65, in forward
out = out * self.scale + x
File "/home/songdc/Downloads/PytorchToCaffe/pytorch_to_caffe.py", line 583, in _mul
bottom=[log.blobs(input), log.blobs(args[0])], top=top_blobs)
File "/home/songdc/Downloads/PytorchToCaffe/Caffe/layer_param.py", line 33, in init
self.bottom.extend(bottom)
TypeError: None has type NoneType, but expected one of: bytes, unicode

When I check the paras, in self.name=self.param.name=name, the name = mul1, in self.type=self.param.type=type, the type = Eltwise, why does the error occur?

Thank you!

The error occur with code out = out * self.scale + x , it can not correctly treat '+' or '*'.

def forward(self, x):
    x0 = self.branch0(x)
    x1 = self.branch1(x)
    x2 = self.branch2(x)
    out = torch.cat((x0, x1, x2), 1)
    out = self.conv2d(out)
    out = out * self.scale + x
    out = self.relu(out)
    return out

I have solve the error by modify out = out * self.scale + x to out = x + torch.mul(self.scale, out).