xxradon / PytorchToCaffe

Pytorch model to caffe model, supported pytorch 0.3, 0.3.1, 0.4, 0.4.1 ,1.0 , 1.0.1 , 1.2 ,1.3 .notice that only pytorch 1.1 have some bugs
MIT License
783 stars 224 forks source link

AttributeError: 'module' object has no attribute 'walk_stack' #21

Closed Ariel-JUAN closed 5 years ago

Ariel-JUAN commented 5 years ago

Hi,I got this error in pytorch_to_caffe.py", line 530, in call. def __call__(self,*args,**kwargs): 527 if not NET_INITTED: 528 return self.raw(*args,**kwargs) 529 print(dir(traceback)) 530 for stack in traceback.walk_stack(None): 531 if 'self' in stack[0].f_locals: 532 layer=stack[0].f_locals['self'] 533 if layer in layer_names: 534 log.pytorch_layer_name=layer_names[layer] 535 print(layer_names[layer]) 536 break And I print the traceback's attribute: ['all', 'builtins', 'doc', 'file', 'name', 'package', '_format_final_exc_line', '_print', '_some_str', 'extract_stack', 'extract_tb', 'format_exc', 'format_exception', 'format_exception_only', 'format_list', 'format_stack', 'format_tb', 'linecache', 'print_exc', 'print_exception', 'print_last', 'print_list', 'print_stack', 'print_tb', 'sys', 'tb_lineno', 'types'] There is no walk_stack. How should I overcome this error?

Ariel-JUAN commented 5 years ago

您好 我使用的是python2.7 traceback没有walk_stack的属性。如果我只想使用python2.7,我应该如何修改代码呢?

ljeff97 commented 5 years ago

Any ideas how to solve this problem please?

BaofengZan commented 5 years ago

您好,请问你遇到的这个问题是如何解决的呢 ?@Ariel-JUAN

Ariel-JUAN commented 5 years ago

Hi, I solved this problem by compiling caffe under python3 environment.

gailysun commented 5 years ago

Hi, I solved this problem by compiling caffe under python3 environment.

Thanks for your solution. When I use python3, this problem is solved. But I meet a new problem: KeyError: 140477310121448 when I convert run /example/resnet_pytorch_2_caffe.py

  1. 140477310121520:view_blob1 was added to blobs
  2. Add blob view_blob1 : torch.Size([1, 512])
  3. Traceback (most recent call last):
  4. File "./example/resnet_pytorch_2_caffe.py", line 17, in
  5. pytorch_to_caffe.trans_net(resnet18,input,name)
  6. File "./pytorch_to_caffe.py", line 613, in trans_net
  7. out = net.forward(input_var)
  8. File "/home/scr/anaconda2/envs/pt2caffeenv/lib/python3.6/site-packages/torchvision/models/resnet.py", line 161, in forward
  9. x = x.view(x.size(0), -1)
  10. File "./pytorch_to_caffe.py", line 411, in _view
  11. bottom=[log.blobs(input)],top=top_blobs)
  12. File "./pytorch_to_caffe.py", line 89, in blobs
  13. print("{}:{} getting".format(var, self._blobs[var]))
  14. File "./pytorch_to_caffe.py", line 32, in getitem
  15. return self.data[key]
  16. KeyError: 140477310121448 Did you meet the problem?