我在Chaquopy中利用joblib来load一个在pycharm中写好的AdaBoost模型:
from joblib import dump, loadfilename = join(dirname(__file__), 'gao1_to_gao2_1.pkl')clf = load(filename)
报错如下:
E/AndroIDRuntime: FATAL EXCEPTION: main Process: com.example.NCEPU, PID: 18024 com.chaquo.python.PyException: ValueError: Buffer dtype mismatch, expected 'SIZE_t' but got 'long long' at <python>.sklearn.tree._tree.Tree.__cinit__(_tree.pyx:607) at <python>.pickle.load_reduce(pickle.py:1587) at <python>.pickle.load(pickle.py:1210) at <python>.joblib.numpy_pickle._unpickle(numpy_pickle.py:504) at <python>.joblib.numpy_pickle.load(numpy_pickle.py:585) at <python>.AdaBoost.test(AdaBoost.py:76) at <python>.chaquopy_java.call(chaquopy_java.pyx:380) at <python>.chaquopy_java.Java_com_chaquo_python_PyObject_callAttrThrowsNative(chaquopy_java.pyx:352) at com.chaquo.python.PyObject.callAttrThrowsNative(Native Method) at com.chaquo.python.PyObject.callAttrThrows(PyObject.java:232) at com.chaquo.python.PyObject.callAttr(PyObject.java:221) at com.example.NCEPU.Student.Predict.AdaBoostActivity.callPythonCode(AdaBoostActivity.java:45) at com.example.NCEPU.Student.Predict.AdaBoostActivity.createList(AdaBoostActivity.java:61) at com.example.NCEPU.Student.Predict.AdaBoostActivity.lambda$initVIEws$AdaBoostActivity(AdaBoostActivity.java:56) at com.example.NCEPU.Student.Predict.-$$Lambda$AdaBoostActivity$dJAvP4dDDrPleKcJgBCESW0ea0M.onClick(UnkNown Source:2) at androID.vIEw.VIEw.performClick(VIEw.java:7192) at androID.vIEw.VIEw.performClickInternal(VIEw.java:7166) at androID.vIEw.VIEw.access00(VIEw.java:824) at androID.vIEw.VIEw$PerformClick.run(VIEw.java:27592) at androID.os.Handler.handleCallback(Handler.java:888) at androID.os.Handler.dispatchMessage(Handler.java:100) at androID.os.Looper.loop(Looper.java:213) at androID.app.ActivityThread.main(ActivityThread.java:8169) at java.lang.reflect.Method.invoke(Native Method) at com.androID.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
翻遍stackoverflow发现是因为32位Python不能导入64位训练的模型,于是在Chaquopy中输出一下:
import platformprint(platform.architecture())
输出为:
('32bit', 'windowsPE')
果然,Chaquopy中Python默认是32位。那没办法,只能用32位Python训练模型然后再导入了。
1.安装32位python 在官网下载32位的python38,然后安装,这个不再叙述。
安装后在Pycharm上配置:
import platformprint(platform.architecture())
输出为:
('32bit', 'windowsPE')
可以看到当前版本已经是32位了
2.安装skleanr和pandas直接在pycharm的Terminal中安装:
pip install sklearn -i https://pypi.douban.com/simplepip install pandas -i https://pypi.douban.com/simple
安装过程有极大概率会报错,这中间省略了很多细节。。。。因为问题实在太多了,忘记记录了。不过最后是升级了一下pip就OK了。
3.训练模型并保存这一步是在pycharm中进行的:
clf = AdaBoostClassifIEr(base_estimator=DecisionTreeClassifIEr(max_depth=7, min_samples_leaf=5), n_estimators=200, algorithm='SAMME', learning_rate=0.5)clf = clf.fit(train_x, train_y) # 训练模型dump(clf, 'gao1_to_gao2_1.pkl')
4.Chaquopy中加载模型 gao1_to_gao2_1.pkl放在python文件夹下:
from joblib import dump, loadfilename = join(dirname(__file__), 'gao1_to_gao2_1.pkl')clf = load(filename)
总结 以上是内存溢出为你收集整理的Chaquopy中不能导入64位Python训练的机器学习模型(32bit与64bit不兼容)全部内容,希望文章能够帮你解决Chaquopy中不能导入64位Python训练的机器学习模型(32bit与64bit不兼容)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)