RGF-team / rgf

Home repository for the Regularized Greedy Forest (RGF) library. It includes original implementation from the paper and multithreaded one written in C++, along with various language-specific wrappers.
378 stars 58 forks source link

excuse me,but could someone tell me that after I use "joblib.dump(clf,'fastrgf_model.pkl')",how could I load model back?? #289

Closed wangbingnan136 closed 5 years ago

wangbingnan136 commented 5 years ago

from sklearn.externals import joblib joblib.dump(clf,'fastrgf_model.pkl')

clf=joblib.load('fastrgf_model.pkl')

KeyError Traceback (most recent call last)

in 5 try: ----> 6 clfs.append(joblib.load(path+model)) 7 except: D:\anaconda\envs\tensorflow\lib\site-packages\sklearn\externals\joblib\numpy_pickle.py in load(filename, mmap_mode) 597 --> 598 obj = _unpickle(fobj, filename, mmap_mode) 599 D:\anaconda\envs\tensorflow\lib\site-packages\sklearn\externals\joblib\numpy_pickle.py in _unpickle(fobj, filename, mmap_mode) 525 try: --> 526 obj = unpickler.load() 527 if unpickler.compat_mode: D:\anaconda\envs\tensorflow\lib\pickle.py in load(self) 1049 assert isinstance(key, bytes_types) -> 1050 dispatch[key[0]](self) 1051 except _Stop as stopinst: D:\anaconda\envs\tensorflow\lib\site-packages\sklearn\externals\joblib\numpy_pickle.py in load_build(self) 338 """ --> 339 Unpickler.load_build(self) 340 D:\anaconda\envs\tensorflow\lib\pickle.py in load_build(self) 1506 if setstate is not None: -> 1507 setstate(state) 1508 return D:\anaconda\envs\tensorflow\lib\site-packages\rgf\utils.py in __setstate__(self, state) 477 global CONFIG --> 478 CONFIG = state.pop("config") 479 self.__dict__.update(state) KeyError: 'config' During handling of the above exception, another exception occurred: OSError Traceback (most recent call last) in 6 clfs.append(joblib.load(path+model)) 7 except: ----> 8 clfs.append(load_model(path+model)) D:\anaconda\envs\tensorflow\lib\site-packages\keras\engine\saving.py in load_model(filepath, custom_objects, compile) 415 model = None 416 opened_new_file = not isinstance(filepath, h5py.Group) --> 417 f = h5dict(filepath, 'r') 418 try: 419 model = _deserialize_model(f, custom_objects, compile) D:\anaconda\envs\tensorflow\lib\site-packages\keras\utils\io_utils.py in __init__(self, path, mode) 184 self._is_file = False 185 elif isinstance(path, str): --> 186 self.data = h5py.File(path, mode=mode) 187 self._is_file = True 188 elif isinstance(path, dict): D:\anaconda\envs\tensorflow\lib\site-packages\h5py\_hl\files.py in __init__(self, name, mode, driver, libver, userblock_size, swmr, rdcc_nslots, rdcc_nbytes, rdcc_w0, track_order, **kwds) 392 fid = make_fid(name, mode, userblock_size, 393 fapl, fcpl=make_fcpl(track_order=track_order), --> 394 swmr=swmr) 395 396 if swmr_support: D:\anaconda\envs\tensorflow\lib\site-packages\h5py\_hl\files.py in make_fid(name, mode, userblock_size, fapl, fcpl, swmr) 168 if swmr and swmr_support: 169 flags |= h5f.ACC_SWMR_READ --> 170 fid = h5f.open(name, flags, fapl=fapl) 171 elif mode == 'r+': 172 fid = h5f.open(name, h5f.ACC_RDWR, fapl=fapl) h5py\_objects.pyx in h5py._objects.with_phil.wrapper() h5py\_objects.pyx in h5py._objects.with_phil.wrapper() h5py\h5f.pyx in h5py.h5f.open() OSError: Unable to open file (file signature not found)
StrikerRUS commented 5 years ago

@wangbingnan136 You can dump and load your model like the following:

https://github.com/RGF-team/rgf/blob/f95178ee8225106af06f6ce93d277d9559d6fcfa/python-package/tests/test_rgf_python.py#L53-L65

where estimator_class can be RGFRegressor, RGFClassifier, FastRGFRegressor or FastRGFClassifier.

I can't understand why keras is in your traceback. You can post the whole code, if you wish to find the mistake, because

from sklearn.externals import joblib
joblib.dump(clf,'fastrgf_model.pkl')
clf=joblib.load('fastrgf_model.pkl')

works fine.

wangbingnan136 commented 5 years ago

Thank u very much,It's my mistake hh!

StrikerRUS commented 5 years ago

No problem! Glad that you've solved the issue!