PicklingError in logs
I'm seeing the following error in the status log. I assume this has something to do with saving intermediate network parameters via pickle.
Caught PicklingError while saving job: Can't pickle <class 'caffe_pb2.NetParameter'>: it's not found as caffe_pb2.NetParameter
Hmm, I haven't seen that problem before. Is this on a mac?
Yes. Mac running OS X.
I've noticed that when the server gets killed and restarted, the completed model training jobs don't show up anymore. I wonder if this bug is related to that.
Yes, it probably is. If the jobs can't be saved to disk (via pickling), then they won't be reloaded on server restart. I'm almost certain this is because you're running on a mac, and either caffe has some issues with their python support on OS X, or it's something that needs to be fixed on my side. Can you try running this and see if it leads you anywhere?
% python
from caffe.proto import caffe_pb2
net = caffe_pb2.NetParameter()
The module import and object creation seems to work fine, but when I try to pickle that object I get the error. See below:
Python 2.7.9 (default, Feb 10 2015, 03:28:08)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> from caffe.proto import caffe_pb2
>>> net = caffe_pb2.NetParameter()
>>> pickle.dump( net , open('save.p','wb'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 1370, in dump
Pickler(file, protocol).dump(obj)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 224, in dump
self.save(obj)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 400, in save_reduce
save(func)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 300, in save
self.save_global(obj)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 748, in save_global
(obj, module, name))
pickle.PicklingError: Can't pickle <class 'caffe_pb2.NetParameter'>: it's not found as caffe_pb2.NetParameter
I also tried pickling the object with cPickle and got a related error message:
>>> cPickle.dump( net , open('save.p','wb'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
cPickle.PicklingError: Can't pickle <class 'caffe_pb2.NetParameter'>: import of module caffe_pb2 failed
Ok, this is interesting. If I explicitly add the ./caffe/proto directory to the PYTHONPATH environment variable and import the class directly, it seems to work.
[caffe/python]$ export PYTHONPATH=./caffe/proto:$PYTHONPATH
[caffe/python]$ python
Python 2.7.9 (default, Feb 10 2015, 03:28:08)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> import caffe_pb2
>>> net = caffe_pb2.NetParameter()
>>> pickle.dump( net , open('save.p','wb'))
>>> net2 = pickle.load( open('save.p','rb'))
>>> net == net2
True
>>> net
<caffe_pb2.NetParameter object at 0x106e87488>
>>> net2
<caffe_pb2.NetParameter object at 0x106fceb90>
>>>
Hi,
I have the exact same problem as mentioned here: no any model are loaded when restarting digits and the same exception: pickle.PicklingError: Can't pickle <class 'caffe_pb2.NetParameter'>: it's not found as caffe_pb2.NetParameter
However, I don't get any errors when trying pickle with caffe on python shell. And setting the PYTHONPATH didn't change anything.
I am on Linux, Centos distrib
Any Idea?
Ok. This workaround seems to work, in that the PicklingError in the logs go away and the trained networks actually show up after a web server restart. This is very likely not the CORRECT way to fix the bug, but it might be informative towards the correct solution:
- Add the following line to the top of
digits/webapp.pyafterimport sys
sys.path.append('/usr/local/caffe/python/caffe/proto/')
where /usr/local/caffe/ should be replaced with the actual install location of Caffe.
- Replace all occurrences of
from caffe.proto import caffe_pb2in the code based withimport caffe_pb2 - Restart server.
Hmmm.... The workaround above seems to break database creation. :( Not good.
What if you just replace:
from caffe.proto import caffe_pb2withimport caffe.proto_pb2- and
caffe_pb2.NetParameter()withcaffe.proto.caffe_pb2.NetParameter()
And then don't mess with the path. Does that work?
You're exactly right, this isn't the correct way to fix the bug, but it's helping us move towards fixing it.
Nope. That doesn't work.
Python 2.7.9 (default, Feb 10 2015, 03:28:08)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> import caffe.proto.caffe_pb2
>>> net = caffe.proto.caffe_pb2.NetParameter()
>>> pickle.dump( net , open('save.p', 'wb'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 1370, in dump
Pickler(file, protocol).dump(obj)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 224, in dump
self.save(obj)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 400, in save_reduce
save(func)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 300, in save
self.save_global(obj)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 748, in save_global
(obj, module, name))
pickle.PicklingError: Can't pickle <class 'caffe_pb2.NetParameter'>: it's not found as caffe_pb2.NetParameter
>>>
That doesn’t change anything to me: it works on the shell, but still have the issue with digits.
Python 2.7.8 (default, Mar 26 2015, 11:41:56) [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2 Type "help", "copyright", "credits" or "license" for more information.
import pickle import caffe.proto.caffe_pb2 net = caffe.proto.caffe_pb2.NetParameter() pickle.dump( net , open('save.p', 'wb'))
Le 27 mars 2015 à 22:03, RudolphV [email protected] a écrit :
Nope. That doesn't work.
Python 2.7.9 (default, Feb 10 2015, 03:28:08) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin Type "help", "copyright", "credits" or "license" for more information.
import pickle import caffe.proto.caffe_pb2 net = caffe.proto.caffe_pb2.NetParameter() pickle.dump( net , open('save.p', 'wb')) Traceback (most recent call last): File "
", line 1, in File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 1370, in dump Pickler(file, protocol).dump(obj) File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 224, in dump self.save(obj) File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 331, in save self.save_reduce(obj=obj, *rv) File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 400, in save_reduce save(func) File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 300, in save self.save_global(obj) File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 748, in save_global (obj, module, name)) pickle.PicklingError: Can't pickle <class 'caffe_pb2.NetParameter'>: it's not found as caffe_pb2.NetParameter — Reply to this email directly or view it on GitHub https://github.com/NVIDIA/DIGITS/issues/32#issuecomment-87091076.
Ok, I think this tweak to the workaround solves most problems (at least for me). Again, not the _correct_ way to do this, but it gets me up and running.
- Programmatically add
$CAFFE_HOME + /python/caffe/proto/to the Python search path indigits/config.py. I did this in thevalidate()method of theCaffeRootOptionclass, but again, not sure if this is the best place. - Replace all occurrences of
from caffe.proto import caffe_pb2in the code based withimport caffe_pb2 - Restart the server
Nope :(
Oops, yes it’s working now! Thanks :)
Le 27 mars 2015 à 22:32, RudolphV [email protected] a écrit :
Ok, I think this tweak to the workaround solves most problems (at least for me). Again, not the correct way to do this, but it gets me up and running.
Programmatically add $CAFFE_HOME + /python/caffe/proto/ to the Python search path in digits/config.py. I did this in the validate() method of the CaffeRootOption class, but again, not sure if this is the best place. Replace all occurrences of from caffe.proto import caffe_pb2 in the code based with import caffe_pb2 Restart the server — Reply to this email directly or view it on GitHub https://github.com/NVIDIA/DIGITS/issues/32#issuecomment-87097617.
I haven't forgotten about this, I just can't reproduce the error on my side.
I was trying this the other day (not thinking it was related to your problem):
import pickle
from collections import namedtuple
class Foo():
Bar = namedtuple('Bar', ['baz']) # inside class
def __init__(self):
self.bar = self.Bar(1)
f = Foo()
pickle.dump(f, open('save.pickle', 'wb'))
That gives me the same error:
pickle.PicklingError: Can't pickle <class '__main__.Bar'>: it's not found as __main__.Bar
This works, though:
import pickle
from collections import namedtuple
Bar = namedtuple('Bar', ['baz']) # outside class
class Foo():
def __init__(self):
self.bar = Bar(1)
f = Foo()
pickle.dump(f, open('save.pickle', 'wb'))
I was able to reproduce this issue as well. I guess http://stackoverflow.com/a/6607586/1491900 answer here provides a list of possible options...
That's weird though, because I'm already editing the path to include caffe:
https://github.com/NVIDIA/DIGITS/blob/v1.1.0/digits/config.py#L119
Can you provide a patch that fixes the issue, so that @RudolphV can try it out on his machine, too?
Luke: If I follow @RudolphV's workaround in https://github.com/NVIDIA/DIGITS/issues/32#issuecomment-87097617, I am able to use pickling to dump the object.