-1

I've trained my model using google colab and saved it as model.pkl. When I try to load the model in my laptop it is throwing the below error:

Traceback (most recent call last):
File "app.py", line 8, in <module>
model = pickle.load(open('model.pkl', 'rb'))
File "sklearn\tree\_tree.pyx", line 606, in sklearn.tree._tree.Tree.__cinit__
ValueError: Buffer dtype mismatch, expected 'SIZE_t' but got 'long long'

I've done some research on the above error and got to know that the random forest code uses different types for indices on 32-bit and 64-bit machines. I've seen similar question on this platform but NOT satisfied with the accepted answer because the answer suggesting to train the model again which is not suitable in case since there are lot of thing to re-do and i don't want to put load on the server again.

Any suggestions or solutions ?

Ravi
  • 1,614
  • 4
  • 14
  • 27

2 Answers2

0

Not sure about '.pkl' format,but can you try saving it as
model.save('modelweight.h5') and then load as model.load ('modelweight.h5'). This shall work. Thanks.

Prachi
  • 402
  • 1
  • 5
  • 10
0

try to use cpickle instead of pickle

try:
   import cPickle as pickle
except:
   import pickle
f = open('model.pkl','w+')
pickle.dump(model, f)#to save the model into file

f = open('model.pkl','r')
model = pickle.load(f)