从谷歌云存储加载保存的 XGBBoost 模型 (.bst)

问题描述 投票:0回答:0

我在 Google 云存储上训练了一个 XGBoost 模型并将其保存为来自 Vertex AI (Kubeflow) 管道组件的“model.bst”文件,然后我尝试从 Vertex AI 中的笔记本加载它。

import xgboost as xgb
model = xgb.train(param, dtrain, num_boost_round=boost_rounds)
model.save_model(model_path)

我尝试了不同的解决方案,但都以不同的错误告终。例如:

fs = gcsfs.GCSFileSystem()
with fs.open(model_path, "rb") as f:
    model = model.load_model(f)
f.close()

这个解决方案的错误是:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_542318/3872730142.py in <module>
     14 
     15 with fs.open(model_path, "rb") as f:
---> 16     model = model.load_model(f)
     17 f.close()
     18 

/opt/conda/lib/python3.7/site-packages/xgboost/core.py in load_model(self, fname)
   2301                                                           length))
   2302         else:
-> 2303             raise TypeError('Unknown file type: ', fname)
   2304 
   2305         if self.attr("best_iteration") is not None:

TypeError: ('Unknown file type: ', <File-like object GCSFileSystem, bucket/model.bst>)
google-cloud-storage xgboost google-cloud-vertex-ai
© www.soinside.com 2019 - 2024. All rights reserved.