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

Output model from Python to C/C++ in if/else format #769

Closed
sami043 opened this issue Aug 2, 2017 · 11 comments
Closed

Output model from Python to C/C++ in if/else format #769

sami043 opened this issue Aug 2, 2017 · 11 comments

Comments

@sami043
Copy link

sami043 commented Aug 2, 2017

Is there any built in method to export the model to .c/.cpp in if/else format? I could potentially parse the text model but that may be a little more prone to error. I saw on here someone had created a python script to do it for binary but for multiclaas it requires modifications. Specifically, what does a decision type of '2' represent?

@guolinke
Copy link
Collaborator

guolinke commented Aug 2, 2017

We have this feature.
refer to our test here: https://github.com/Microsoft/LightGBM/tree/master/tests/cpp_test

BTW, the decision_type = 2 is out of date now. maybe you need to retrain your model with the latest code.

@wxchan can you add more documents for the if-else conversion ?

@sami043
Copy link
Author

sami043 commented Aug 2, 2017

I just built the latest lightGBM yesterday so that's strange that I am getting that decision type. With save_model?

@guolinke
Copy link
Collaborator

guolinke commented Aug 2, 2017

@sami043 It is updated today (f2bec2b). decision_type is still there, but its value range is changed.
if you model file has num_cat field, it is up to date.

@wxchan
Copy link
Contributor

wxchan commented Aug 2, 2017

@sami043 you can add convert_model=SOME_PATH and convert_model_language=cpp to params , 1st is output address and 2nd is output language(now c++ is only option). And you need to re-compile c++ and python to make it work.

I actually never tried it from python. You can take a try.

@guolinke I will write some docs maybe tomorrow.

@sami043
Copy link
Author

sami043 commented Aug 2, 2017 via email

@wxchan
Copy link
Contributor

wxchan commented Aug 2, 2017

@sami043 sorry, I forgot. It is only implemented in command line version now.

@sami043
Copy link
Author

sami043 commented Aug 2, 2017

@wxchan

Thanks for the quick replies.

Are there plans to expand it to non-command line later on? Or would it be possible to load a .txt model through the command line interface and export the .cpp code?

@wxchan
Copy link
Contributor

wxchan commented Aug 2, 2017

@sami043 for 2nd one, yes, set task : convert_model, you can see #469

for 1st one, maybe in the future, I am a little busy these days.

@sami043
Copy link
Author

sami043 commented Aug 2, 2017

That did the trick! Thanks!

@sami043 sami043 closed this as completed Aug 2, 2017
@beutlgb
Copy link

beutlgb commented Nov 23, 2017

Hey,
I have a model.txt file, i understand thet i can use the CLI to convert it to an if-else code. but i didnt understand exactly how to do it.
can you write the command line i need to use to convert the model.txt file.
can i do this from the pyhton interface?
Thanks very much'
Great package!!

@SoftwareApe
Copy link

Is there also a guide somewhere on how to use the converted C++ model? I can't find anything using Google.

@lock lock bot locked as resolved and limited conversation to collaborators Mar 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants