KerasClassifier "can't pickle _thread.RLock objects" message when predicting
See original GitHub issueI’m able to fit a model that includes KerasClassifier as a model in the ensemble. However, at prediction time I get the following error. I’ve tried changing the backend as well as the number of jobs but to no avail. Any ideas?
`--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-9-74578adea9e4> in <module>() ----> 1 preds = ensemble.predict_proba(X[294:])
D:\Continuum\anaconda3\lib\site-packages\mlens\ensemble\base.py in predict_proba(self, X, **kwargs) 633 “”" 634 kwargs.pop(‘proba’, None) –> 635 return self.predict(X, proba=True, **kwargs) 636 637 def _build_layer(self, estimators, indexer, preprocessing, **kwargs):
D:\Continuum\anaconda3\lib\site-packages\mlens\ensemble\base.py in predict(self, X, **kwargs) 613 return 614 X, _ = check_inputs(X, check_level=self.array_check) –> 615 return self._backend.predict(X, **kwargs) 616 617 def predict_proba(self, X, **kwargs):
D:\Continuum\anaconda3\lib\site-packages\mlens\ensemble\base.py in predict(self, X, **kwargs) 199 predictions from final layer. 200 “”" –> 201 if not self.fitted: 202 NotFittedError(“Instance not fitted.”) 203
D:\Continuum\anaconda3\lib\site-packages\mlens\parallel\base.py in fitted(self) 359 if not self.stack or not self._check_static_params(): 360 return False –> 361 return all([g.fitted for g in self.stack]) 362 363 @property
D:\Continuum\anaconda3\lib\site-packages\mlens\parallel\base.py in <listcomp>(.0) 359 if not self.stack or not self._check_static_params(): 360 return False –> 361 return all([g.fitted for g in self.stack]) 362 363 @property
D:\Continuum\anaconda3\lib\site-packages\mlens\parallel\base.py in fitted(self) 359 if not self.stack or not self._check_static_params(): 360 return False –> 361 return all([g.fitted for g in self.stack]) 362 363 @property
D:\Continuum\anaconda3\lib\site-packages\mlens\parallel\base.py in <listcomp>(.0) 359 if not self.stack or not self._check_static_params(): 360 return False –> 361 return all([g.fitted for g in self.stack]) 362 363 @property
D:\Continuum\anaconda3\lib\site-packages\mlens\parallel\handles.py in fitted(self) 256 if not self._check_static_params(): 257 return False –> 258 return all([o.fitted for o in self.learners + self.transformers]) 259 260 def get_params(self, deep=True):
D:\Continuum\anaconda3\lib\site-packages\mlens\parallel\handles.py in <listcomp>(.0) 256 if not self._check_static_params(): 257 return False –> 258 return all([o.fitted for o in self.learners + self.transformers]) 259 260 def get_params(self, deep=True):
D:\Continuum\anaconda3\lib\site-packages\mlens\parallel\learner.py in fitted(self) 743 # Check estimator param overlap 744 fitted = self.learner + self.sublearners –> 745 fitted_params = fitted[0].estimator.get_params(deep=True) 746 model_estimator_params = self.estimator.get_params(deep=True) 747
D:\Continuum\anaconda3\lib\site-packages\mlens\parallel\learner.py in estimator(self) 64 def estimator(self): 65 “”“Deep copy of estimator”“” —> 66 return deepcopy(self._estimator) 67 68 @estimator.setter
D:\Continuum\anaconda3\lib\copy.py in deepcopy(x, memo, _nil) 178 y = x 179 else: –> 180 y = _reconstruct(x, memo, *rv) 181 182 # If is its own copy, don’t memoize.
D:\Continuum\anaconda3\lib\copy.py in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy) 278 if state is not None: 279 if deep: –> 280 state = deepcopy(state, memo) 281 if hasattr(y, ‘setstate’): 282 y.setstate(state)
D:\Continuum\anaconda3\lib\copy.py in deepcopy(x, memo, _nil) 148 copier = _deepcopy_dispatch.get(cls) 149 if copier: –> 150 y = copier(x, memo) 151 else: 152 try:
D:\Continuum\anaconda3\lib\copy.py in _deepcopy_dict(x, memo, deepcopy) 238 memo[id(x)] = y 239 for key, value in x.items(): –> 240 y[deepcopy(key, memo)] = deepcopy(value, memo) 241 return y 242 d[dict] = _deepcopy_dict
D:\Continuum\anaconda3\lib\copy.py in deepcopy(x, memo, _nil) 178 y = x 179 else: –> 180 y = _reconstruct(x, memo, *rv) 181 182 # If is its own copy, don’t memoize.
D:\Continuum\anaconda3\lib\copy.py in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy) 278 if state is not None: 279 if deep: –> 280 state = deepcopy(state, memo) 281 if hasattr(y, ‘setstate’): 282 y.setstate(state)
D:\Continuum\anaconda3\lib\copy.py in deepcopy(x, memo, _nil) 148 copier = _deepcopy_dispatch.get(cls) 149 if copier: –> 150 y = copier(x, memo) 151 else: 152 try:
D:\Continuum\anaconda3\lib\copy.py in _deepcopy_dict(x, memo, deepcopy) 238 memo[id(x)] = y 239 for key, value in x.items(): –> 240 y[deepcopy(key, memo)] = deepcopy(value, memo) 241 return y 242 d[dict] = _deepcopy_dict
D:\Continuum\anaconda3\lib\copy.py in deepcopy(x, memo, _nil) 178 y = x 179 else: –> 180 y = _reconstruct(x, memo, *rv) 181 182 # If is its own copy, don’t memoize.
D:\Continuum\anaconda3\lib\copy.py in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy) 278 if state is not None: 279 if deep: –> 280 state = deepcopy(state, memo) 281 if hasattr(y, ‘setstate’): 282 y.setstate(state)
D:\Continuum\anaconda3\lib\copy.py in deepcopy(x, memo, _nil) 148 copier = _deepcopy_dispatch.get(cls) 149 if copier: –> 150 y = copier(x, memo) 151 else: 152 try:
D:\Continuum\anaconda3\lib\copy.py in _deepcopy_dict(x, memo, deepcopy) 238 memo[id(x)] = y 239 for key, value in x.items(): –> 240 y[deepcopy(key, memo)] = deepcopy(value, memo) 241 return y 242 d[dict] = _deepcopy_dict
D:\Continuum\anaconda3\lib\copy.py in deepcopy(x, memo, _nil) 148 copier = _deepcopy_dispatch.get(cls) 149 if copier: –> 150 y = copier(x, memo) 151 else: 152 try:
D:\Continuum\anaconda3\lib\copy.py in _deepcopy_list(x, memo, deepcopy) 213 append = y.append 214 for a in x: –> 215 append(deepcopy(a, memo)) 216 return y 217 d[list] = _deepcopy_list
D:\Continuum\anaconda3\lib\copy.py in deepcopy(x, memo, _nil) 178 y = x 179 else: –> 180 y = _reconstruct(x, memo, *rv) 181 182 # If is its own copy, don’t memoize.
D:\Continuum\anaconda3\lib\copy.py in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy) 278 if state is not None: 279 if deep: –> 280 state = deepcopy(state, memo) 281 if hasattr(y, ‘setstate’): 282 y.setstate(state)
D:\Continuum\anaconda3\lib\copy.py in deepcopy(x, memo, _nil) 148 copier = _deepcopy_dispatch.get(cls) 149 if copier: –> 150 y = copier(x, memo) 151 else: 152 try:
D:\Continuum\anaconda3\lib\copy.py in _deepcopy_dict(x, memo, deepcopy) 238 memo[id(x)] = y 239 for key, value in x.items(): –> 240 y[deepcopy(key, memo)] = deepcopy(value, memo) 241 return y 242 d[dict] = _deepcopy_dict
D:\Continuum\anaconda3\lib\copy.py in deepcopy(x, memo, _nil) 178 y = x 179 else: –> 180 y = _reconstruct(x, memo, *rv) 181 182 # If is its own copy, don’t memoize.
D:\Continuum\anaconda3\lib\copy.py in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy) 278 if state is not None: 279 if deep: –> 280 state = deepcopy(state, memo) 281 if hasattr(y, ‘setstate’): 282 y.setstate(state)
D:\Continuum\anaconda3\lib\copy.py in deepcopy(x, memo, _nil) 148 copier = _deepcopy_dispatch.get(cls) 149 if copier: –> 150 y = copier(x, memo) 151 else: 152 try:
D:\Continuum\anaconda3\lib\copy.py in _deepcopy_dict(x, memo, deepcopy) 238 memo[id(x)] = y 239 for key, value in x.items(): –> 240 y[deepcopy(key, memo)] = deepcopy(value, memo) 241 return y 242 d[dict] = _deepcopy_dict
D:\Continuum\anaconda3\lib\copy.py in deepcopy(x, memo, _nil) 178 y = x 179 else: –> 180 y = _reconstruct(x, memo, *rv) 181 182 # If is its own copy, don’t memoize.
D:\Continuum\anaconda3\lib\copy.py in _reconstruct(x, memo, func, args, state, listiter, dictiter, deepcopy) 278 if state is not None: 279 if deep: –> 280 state = deepcopy(state, memo) 281 if hasattr(y, ‘setstate’): 282 y.setstate(state)
D:\Continuum\anaconda3\lib\copy.py in deepcopy(x, memo, _nil) 148 copier = _deepcopy_dispatch.get(cls) 149 if copier: –> 150 y = copier(x, memo) 151 else: 152 try:
D:\Continuum\anaconda3\lib\copy.py in _deepcopy_dict(x, memo, deepcopy) 238 memo[id(x)] = y 239 for key, value in x.items(): –> 240 y[deepcopy(key, memo)] = deepcopy(value, memo) 241 return y 242 d[dict] = _deepcopy_dict
D:\Continuum\anaconda3\lib\copy.py in deepcopy(x, memo, _nil) 167 reductor = getattr(x, “reduce_ex”, None) 168 if reductor: –> 169 rv = reductor(4) 170 else: 171 reductor = getattr(x, “reduce”, None)
TypeError: can’t pickle _thread.RLock objects`
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (6 by maintainers)
Top GitHub Comments
Just one thing to note. It’s doesn’t really impact me as I’m using a small dataset but when I use the KerasClassifier in the ensemble I can only get it to work with setting n_jobs=1. If I set to -1 it won’t work.
Gotcha, thanks!