执行如下语句的时候报错
model = joblib.load(filename=file_path)
文件目录树如下:
som
-- train(保存模型)
-- lib
-- minisom.py
-- predict(加载模型)
报错信息:
Traceback (most recent call last):
File "D:/SOM/self_organizing_maps/predict/test_som_predict.py", line 55, in <module>
model = joblib.load(filename=file_path)
File "D:\softwear_install_position\anaconda3\envs\py3.7\lib\site-packages\joblib\numpy_pickle.py", line 585, in load
obj = _unpickle(fobj, filename, mmap_mode)
File "D:\softwear_install_position\anaconda3\envs\py3.7\lib\site-packages\joblib\numpy_pickle.py", line 504, in _unpickle
obj = unpickler.load()
File "D:\softwear_install_position\anaconda3\envs\py3.7\lib\pickle.py", line 1088, in load
dispatch[key[0]](self)
File "D:\softwear_install_position\anaconda3\envs\py3.7\lib\pickle.py", line 1376, in load_global
klass = self.find_class(module, name)
File "D:\softwear_install_position\anaconda3\envs\py3.7\lib\pickle.py", line 1427, in find_class
__import__(module, level=0)
ModuleNotFoundError: No module named 'lib'
试着把最后一行错误的地方打印出来看看,即在 __import__(module, level=0)
的前一行 print("model:", model)
,得到如下:
module: lib.minisom
很明显,就是因为使用第三方包 minison
的时候,只在 train
文件夹下有 lib/minisom.py
所以在 predict 文件夹下加载模型的话,就找不到对应的 lib/minisom.py
最终修改的文件目录树为:
som
-- train(保存模型)
-- lib
-- minisom.py
-- predict(加载模型)
-- lib
-- minisom.py