Caffe to Tensorflow (Kaffe by Ethereon) : TypeError: Descriptors should not be created directly, but only retrieved from their parent

我怕爱的太早我们不能终老 提交于 2020-01-15 05:49:08

问题


I wanted to use the wonderful package caffe-tensorflow by ethereon and I ran into the same problem described in this closed issue:

When I run the example or try to import caffepb I got the error message:

>>> import caffepb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "caffepb.py", line 28, in <module>
        type=None),
  File "/home/me/anaconda/python2.7/site-packages/google/protobuf/descriptor.py", line 652, in __new__
    _message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors should not be created directly, but only retrieved from their parent.

I am using Tensorflow 0.7.0 on a linux 64 bits UBUNTU 14.04 machine with protobuf 3.0.0b2.post (but it also happened with 3.0.0a4 and 3.0.0b2) with Python 2.7 and anaconda.

I tried to reinstall protobuf and tensorflow numerous times as I figured it was quite possibly a conflict between different protobuf installs (or at least that was the conclusion of the github issue) but I couldn't make it work even after doing a combination of pip install protobuf, pip uninstall protobuf or directly installing protobuf .whl.

What would you advise ?

EDIT: Using a virtual environment may be a solution but I would like to avoid it if possible


回答1:


Renaming any file creating descriptors to have suffix "_pb2.py" will solve this problem.

UPDATE(April 4, 2017): In the "caffe-tensorflow" project, I renamed the "kaffe/caffe/caffepb.py" to "caffe_pb2.py", and this solved the problem. This is the only file I found in this project that creates PB descriptors.




回答2:


I met the same problem too. My solution (workaround) was the same as one of the comments in the issue - install/run tf and protobuf3 (and anything) in virtualenv.

I have no more idea about what the problem exactly is. This is just one workaround that you can give a try.




回答3:


Kai Yu's solution also worked for me. However, I also recommend deleting the "caffepb.pyc" file in caffe-tensorflow/kaffe/caffe to ensure that none of the code can still be using the caffe_pb2 module with the old name.

I believe that this module is only used in the file caffe-tensorflow/kaffe/caffe/resolver.py.



来源:https://stackoverflow.com/questions/38616620/caffe-to-tensorflow-kaffe-by-ethereon-typeerror-descriptors-should-not-be-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!