Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Looking for an example for loading from a Stream source #144

Open
Yandychang1 opened this issue Dec 8, 2023 · 4 comments
Open

Looking for an example for loading from a Stream source #144

Yandychang1 opened this issue Dec 8, 2023 · 4 comments

Comments

@Yandychang1
Copy link

Yandychang1 commented Dec 8, 2023

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.

@madelson
Copy link

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);

@Yandychang1
Copy link
Author

It seems to me that for xgboost classifiers and regressors, this may not apply, at least for now.

@mdabros
Copy link
Owner

mdabros commented Jan 20, 2024

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.

@Yandychang1
Copy link
Author

I noticed the same thing, so far I have not found a way to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants