How to overcome joblib "TypeError: cannot determine object instance objects" in class method?

Given the class and 2 methods in it, A, B.

I get "TypeError: can not pickle objectsmethod objects" when I try to execute the following command while in A:

joblib.Parallel(n_jobs=-1)(joblib.delayed(self.B)(arg1, arg2, arg3) for arg1 in arg1_values_list) 

I found several threads in Stackoverflow regarding the instance method, and some of them are even related to joblib, but I still have not been able to overcome this error.

EDIT:

The following code:

 from sklearn.externals.joblib import Parallel, delayed def a(self, x): print x return x*10 class c(object): def b(self): Parallel(n_jobs=-1)( delayed(a)(self, i) for i in range(10)) test_c = c() test_c.b() 

works fine during normal operation.

but when attempting profiling with "python -m cProfile"

+6
source share
1 answer

It is most likely safer to pass functions without saving in Python to joblib.Parallel . You can try import dill register sorting support for instance methods: https://pypi.python.org/pypi/dill (your mileage may vary).

+3
source

All Articles