xiezheng-cs / PytorchToCaffe

A tool for PytorchToCaffe,fork form https://github.com/xxradon/PytorchToCaffe
MIT License
11 stars 2 forks source link

Error with add/mul/Eltwise #4

Closed DCSong closed 4 years ago

DCSong commented 4 years ago

import torch 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))

Add blob conv_blob13 : torch.Size([1, 256, 61, 61]) 140602027406272:cat_blob1 getting 140602027407552:conv_blob13 getting mul1 was added to layers 140602027406752:mul_blob1 was added to blobs Add blob mul_blob1 : torch.Size([1, 256, 61, 61]) 140602027407552:conv_blob13 getting Traceback (most recent call last): File "VGGFace2_pytorch_2_caffe.py", line 14, in pytorch_to_caffe.trans_net(model, input, name) File "/home/songdc/Documents/PytorchToCaffe/pytorch_to_caffe.py", line 675, 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 489, 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 489, 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/Documents/PytorchToCaffe/pytorch_to_caffe.py", line 552, in _mul bottom=[log.blobs(input), log.blobs(args[0])], top=top_blobs) File "/home/songdc/Documents/PytorchToCaffe/pytorch_to_caffe.py", line 101, in blobs print("{}:{} getting".format(var, self._blobs[var])) File "/home/songdc/Documents/PytorchToCaffe/pytorch_to_caffe.py", line 39, in getitem return self.data[key] KeyError: 140602226322992

torch:1.0 torchvision:0.2 (haven add code torchvison.ops.boxes to facenet_pytorch source code which occur in torchvision>0.3)

Why does the error occur? Thank you!

DCSong commented 4 years ago

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