Open leo038 opened 3 years ago
I have the same issue. can someone help us to fix this issue?
my log is listed as follow:
['cat_blob1'] ['relu_blob8', None]
Traceback (most recent call last):
File "app_py2caffe.py", line 32, in
the same issue
你的torchvision是0.4.0太高了,换成0.2.0 主要是0.2之后的版本将view改成了flatten操作,以alexnet为例 0.2的实现为
def forward(self, x):
x = self.features(x)
x = x.view(x.size(0), 256 * 6 * 6)
x = self.classifier(x)
return x
到了0.5变成了
def forward(self, x):
x = self.features(x)
x = self.avgpool(x)
x = torch.flatten(x, 1)
x = self.classifier(x)
return x
其中的flatten并没有实现,搞清楚原因后解决就简单多了 新建一_flatten函数
def _flatten(raw , input, * args):
x = raw(input, *args)
if not NET_INITTED:
return x
layer_name=log.add_layer(name='flatten')
top_blobs=log.add_blobs([x],name='flatten_blob')
layer=caffe_net.Layer_param(name=layer_name,type='Reshape',
bottom=[log.blobs(input)],top=top_blobs)
start_dim = args[0]
end_dim = len(x.shape)
if len(args) > 1:
end_dim = args[1]
dims = []
for i in range(start_dim):
dims.append(x.shape[i])
cum = 1
for i in range(start_dim, end_dim):
cum = cum * x.shape[i]
dims.append(cum)
if end_dim != len(x.shape):
cum = 1
for i in range(end_dim, len(x.shape)):
cum = cum * x.shape[i]
dims.append(cum)
layer.param.reshape_param.shape.CopyFrom(caffe_net.pb.BlobShape(dim=dims))
log.cnet.add_layer(layer)
return x
然后替换pytorch中的实现,在那一堆torch.max=Rp(torch.max,_max)等骚操作后加上 torch.flatten = Rp(torch.flatten,_flatten)
I just download the code and run python3 example/resnet_pytorch_2_caffe.py
and got the following error
WARNING: CANNOT FOUND blob 140623413128576 Traceback (most recent call last): File "example/resnet_pytorch_2_caffe.py", line 19, in <module> pytorch_to_caffe.trans_net(resnet18,input,name) File "./pytorch_to_caffe.py", line 786, in trans_net out = net.forward(input_var) File "/usr/local/lib/python3.6/dist-packages/torchvision/models/resnet.py", line 206, in forward x = self.fc(x) File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 547, in __call__ result = self.forward(*input, **kwargs) File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/linear.py", line 87, in forward return F.linear(input, self.weight, self.bias) File "./pytorch_to_caffe.py", line 690, in __call__ out=self.obj(self.raw,*args,**kwargs) File "./pytorch_to_caffe.py", line 138, in _linear bottom=[log.blobs(input)],top=top_blobs) File "./Caffe/layer_param.py", line 33, in __init__ self.bottom.extend(bottom) TypeError: None has type NoneType, but expected one of: bytes, unicode
the version of my environment is: Ubuntu 18.04 x86_64 python3: 3.6.9 torch: 1.2.0 torchvision:0.4.0
It works!
I just download the code and run python3 example/resnet_pytorch_2_caffe.py
and got the following error
the version of my environment is: Ubuntu 18.04 x86_64 python3: 3.6.9 torch: 1.2.0 torchvision:0.4.0