Looking for an example for loading from a Stream source
Opened this issue · 4 comments
I am looking for an example to load a trained XGBoostClassifier model from a Stream rather than from a file. I am planning to save it as an embedded resource, so I want the ability to load my model from a DLL.
I’m early in exploring this repo but looking for the same capability. I think maybe it can be done with the methods that load from a TextReader:
using TextReader reader = new StreamReader(GetEmbeddedResourceStream()); ….Load(() => reader);
It seems to me that for xgboost classifiers and regressors, this may not apply, at least for now.
Hi @Yandychang1
Not sure if you already found an alternative for this.
It is possible to load using a StreamReader
for all models except for the XGBoost models sadly. The reason is that SharpLearning simply wraps XGBoost.net and uses the Booster
class from that library to load the model from file. You can see the call here for the RegressionXGBoostModel
:
https://github.com/mdabros/SharpLearning/blob/master/src/SharpLearning.XGBoost/Models/RegressionXGBoostModel.cs#L96
From a quick look there does not seem to be an obvious way to instantiate the Booster
class from a stream sadly. If you can find a way, I would be happy to add an overload for it in SharpLearning
.
I noticed the same thing, so far I have not found a way to fix this.