简体   繁体   English

如何在python 3.5上训练的python 3.6中加载机器学习模型?

[英]How to load machine learning model in python 3.6 that is trained on python 3.5?

I have trained a machine learning model on Python 3.5 , and now I switched to Google Colab, which uses Python 3.6 , and when I try to load the model that I have trained on Python 3.5 , it gives this error:我已经在 Python 3.5上训练了一个机器学习模型,现在我切换到使用 Python 3.6 Google Colab,当我尝试加载我在 Python 3.5上训练过的模型时,它给出了这个错误:

SystemError: unknown opcode.

After googling, I found that this error occurs because of the environment change, then I cross-checked my python version, and both Python version were different. google了之后发现这个错误是因为环境变化导致的,于是我交叉检查了我的python版本,发现两个python版本都不一样。 How can I load my model on Python 3.6 ?如何在 Python 3.6上加载我的模型?

You shouldn't.你不应该。

Even if you get it to run without errors / warnings, there might be slight changes under the hood that change the behavior / performance of the model.即使您让它在没有错误/警告的情况下运行,引擎盖下也可能会有细微的变化,从而改变模型的行为/性能。

You should either retrain the model on Python 3.6 or create a virtual environment that runs Python 3.5 for your model to ensure it performs as expected.您应该在 Python 3.6 上重新训练模型,或者为您的模型创建一个运行 Python 3.5 的虚拟环境,以确保它按预期执行。 Also always ensure that the actual libraries (eg keras...) have the same version.还要始终确保实际库(例如 keras...)具有相同的版本。

I ran into same problem as you did.我遇到了和你一样的问题。 I trained my model on a GCP on python 3.5 and move it to colab to continue with evaluation which is python 3.6.我在 python 3.5 上的 GCP 上训练了我的模型,并将其移动到 colab 以继续进行 python 3.6 的评估。

What I did is to reinstantiate the exact model from code, and then call load_weights:我所做的是从代码中重新实例化确切的模型,然后调用 load_weights:

model = create_my_model()

model.load_weights('my_model_trained_with_py_35.h5')

model.save('my_model_py36.h5')

For my case, I don't have lot of custom code other than a Lambda with:就我而言,除了具有以下功能的 Lambda 之外,我没有很多自定义代码:

def abs_diff(x):
  return tf.abs(x[0] - x[1])

Since your model could be arbitrarily more complex, this may or may not work, but it is worth a try esp.由于您的模型可能更加复杂,这可能有效也可能无效,但值得一试,尤其是。 if re-training is too expensive.如果再培训太贵了。 As usual, evaluate the model with the same data and ensure nothing is strange.像往常一样,使用相同的数据评估模型并确保没有任何异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何加载深度学习 model,在 matlab 中训练,在 python - how to load deep learning model, trained in matlab, in python 在 javascript 中加载经过训练的机器学习 model - Load trained Machine Learning model in javascript 如何在虚拟机中将python3.5升级到python3.6? - how to upgrade python3.5 to python3.6 in Virtual Machine? 如何统一使用 python 制造和训练的机器学习 model 来预测某些事情? - How to use a python made and trained machine learning model in unity to predict something? 在 python 中加载机器学习 model 时出错 - error while load machine learning model in python 如何将 Python 机器学习 model 嵌入到 NodeJs 中 - How to embed Python Machine learning model into NodeJs 是否有一种直接的方法可以在 Python 中的一组全新数据上使用经过训练的机器学习 Model - Is there a straight forward approach to use a Trained Machine Learning Model on a brand new set of data in Python 如何将python 3.5更改为python 3.6 env - How to change python 3.5 to python 3.6 env 如何为我训练有素的机器学习 model 提供输入以预测 output? - How to give input to my trained machine learning model to predict the output? 如何从 Python 3.5 升级到 3.6? - How to upgrade from Python 3.5 to 3.6?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM