如何从 Google Cloud Storage 存储桶加载保存在 joblib 文件中的模型 [英] How to load a model saved in joblib file from Google Cloud Storage bucket

查看:18
本文介绍了如何从 Google Cloud Storage 存储桶加载保存在 joblib 文件中的模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 Google Cloud Storage 存储桶加载一个保存为 joblib 文件的模型.当它在本地路径时,我们可以如下加载它(考虑到model_file是系统中的完整路径):

I want to load a model which is saved as a joblib file from Google Cloud Storage bucket. When it is in local path, we can load it as follows (considering model_file is the full path in system):

loaded_model = joblib.load(model_file)

我们如何使用 Google Cloud Storage 完成相同的任务?

How can we do the same task with Google Cloud Storage?

推荐答案

我认为这不可能,至少是直接的.我想过一种解决方法,但可能没有你想要的那么高效.

I don't think that's possible, at least in a direct way. I though about a workaround, but the might not be as efficient as you want.

通过使用 Google Cloud Storage 客户端库[1] 可以先下载模型文件,加载,等你的程序结束,删除.当然,这意味着每次运行代码时都需要下载文件.这是一个片段:

By using the Google Cloud Storage client libraries [1] you can download the model file first, load it, and when your program ends, delete it. Of course, this means that you need to download the file every time you run the code. Here is a snippet:

from google.cloud import storage
from sklearn.externals import joblib

storage_client = storage.Client()
bucket_name=<bucket name>
model_bucket='model.joblib'
model_local='local.joblib'

bucket = storage_client.get_bucket(bucket_name)
#select bucket file
blob = bucket.blob(model_bucket)
#download that file and name it 'local.joblib'
blob.download_to_filename(model_local)
#load that file from local file
job=joblib.load(model_local)

这篇关于如何从 Google Cloud Storage 存储桶加载保存在 joblib 文件中的模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆