每当我运行以下代码时:
file_name = "soil_model_fineTuned.pkl"
with open(file_name, 'rb') as f:
model = pickle.load(f)
我收到这样的错误:
model = pickle.load(f)
ModuleNotFoundError: No module named 'keras.src.saving.pickle_utils'
即使我已经安装了 Keras 3.3.3 并安装了 Tensorflow 2.16.1 和 Python 3.10,即使我使用
joblib
我仍然遇到同样的错误:
model = joblib.load(file_name)
File "/opt/miniconda3/envs/tensorflow/lib/python3.10/site-packages/joblib/numpy_pickle.py", line 658, in load
obj = _unpickle(fobj, filename, mmap_mode)
File "/opt/miniconda3/envs/tensorflow/lib/python3.10/site-packages/joblib/numpy_pickle.py", line 577, in _unpickle
obj = unpickler.load()
File "/opt/miniconda3/envs/tensorflow/lib/python3.10/pickle.py", line 1213, in load
dispatch[key[0]](self)
File "/opt/miniconda3/envs/tensorflow/lib/python3.10/pickle.py", line 1538, in load_stack_global
self.append(self.find_class(module, name))
File "/opt/miniconda3/envs/tensorflow/lib/python3.10/pickle.py", line 1580, in find_class
__import__(module, level=0)
ModuleNotFoundError: No module named 'keras.src.saving.pickle_utils'
如果有其他方法可以加载我的pickle模型和Keras 3.3.3,请告诉!!
我期待一个关于如何加载我保存的pickle模型的解决方案,但在keras库中显示不同的错误,希望我得到一个好的答案。
尝试升级 pip: python -m pip install --升级pip
尝试重新安装tensorflow:
pip 卸载 keras tensorflow -y pip 安装张量流
尝试创建新的虚拟环境: python -m venv myenv myenv\脚本激活