加载时找不到泡菜文件

发布于 2025-01-31 16:39:26 字数 648 浏览 4 评论 0原文

我使用以下代码保存了与泡菜的分类器模型 -

import pickle
with open('model.pickle', 'wb') as fid:
    pickle.dump(clf, fid) 

这是我加载泡菜模型的corce.py文件,在部署期间调用了相同的文件。另请注意,所有这些文件(代码,腌制文件和相关文件)都位于同一目录中。

# Initialize the deployment environment
def init():
    global obj
    with open('./model.pickle', 'rb') as f:
        obj = pickle.load(f)

这将存储在某些目录var/azureml-app

运行此部署代码后,这是我收到的错误 -

open('/mnt/batch/tasks/shared/LS_root/mounts/clusters/model.pickle', 'rb') as f:
    FileNotFoundError: [Errno 2] No such file or directory: '/mnt/batch/tasks/model.pickle'

I have saved a classifier model with pickle using the following code-

import pickle
with open('model.pickle', 'wb') as fid:
    pickle.dump(clf, fid) 

This is the score.py file where I am loading the pickle model and the same file is called during deployment. Also note that, all these files (code, pickle file and related files) are in the same directory.

# Initialize the deployment environment
def init():
    global obj
    with open('./model.pickle', 'rb') as f:
        obj = pickle.load(f)

This is getting stored in some directory var/azureml-app

After running this deployment code, this is the error I am getting-

open('/mnt/batch/tasks/shared/LS_root/mounts/clusters/model.pickle', 'rb') as f:
    FileNotFoundError: [Errno 2] No such file or directory: '/mnt/batch/tasks/model.pickle'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏の忆 2025-02-07 16:39:27

我想出了解决此错误的方法。

而不是按照

 with open('./skm.pickle', 'rb') as f:
        obj = pickle.load(f)

您需要加载模型来加载模型,因为

 model_path = os.path.join(os.getenv('AZUREML_MODEL_DIR'), 'skm.pickle')
 model = joblib.load(model_path)

azureml_model_dir将将其存储的模型的环境目录录取。

这将解决错误。

I figured out the way to solve this error.

Instead of loading the model as

 with open('./skm.pickle', 'rb') as f:
        obj = pickle.load(f)

You need to load the model as

 model_path = os.path.join(os.getenv('AZUREML_MODEL_DIR'), 'skm.pickle')
 model = joblib.load(model_path)

The AZUREML_MODEL_DIR will take the environment directory of the model where it is stored.

This will solve the error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文