dmlc / xgboost

Scalable, Portable and Distributed Gradient Boosting (GBDT, GBRT or GBM) Library, for Python, R, Java, Scala, C++ and more. Runs on single machine, Hadoop, Spark, Dask, Flink and DataFlow
https://xgboost.readthedocs.io/en/stable/
Apache License 2.0
26.36k stars 8.74k forks source link

Model deployment in C++ #1844

Closed adendek closed 6 years ago

adendek commented 7 years ago

Let's assume I created and trained some DNN model (via python api) and then I want to deploy it into some standalone c++ project. How can I do it? Can you give me any advices?

xydrolase commented 7 years ago

Gradient boost trees are basically decision trees, which can be converted into many if-else statements.

Once you train your model, you can dump the tree model, and convert it into customized C++ code with if-else statements checking the feature and split values. And finally, return the leaf value when you reaches the leaf.

ghost commented 7 years ago

@adendek - just create script that parses trees dump and generates one giant function with if-else statements. That's what I did and it works.

adendek commented 7 years ago

@drag0 Can you share the script with me? PS. Did you checked the time performance of your solution? In my project the timing is a crucial issue.

adendek commented 7 years ago

@drag0 what is the status of this script?

byronliwei commented 7 years ago

can you send this scipt to me? thank you. my email is byronliwei@gmail.com @drag0

enissay14 commented 7 years ago

@drag0 I can use that script too! Thanks ( yassine dot landa at gmail dot com)

yon100 commented 7 years ago

@drag0 I would highly appreciate receiving your script to gan.sagur@gmail.com. Thanks!!

carsonyan commented 7 years ago

Can you please share the script to me also :+1: carsonwolf@gmail.com

kaishengyao commented 7 years ago

please share the script to me also kaishengy@gmail.com thanks a lot!

ghost commented 7 years ago

I'll push script code to GitHub today/tomorrow evening so you'll be able to use it. Sorry everyone for waiting so long.

ghost commented 7 years ago

Here it is guys: https://github.com/drag0/xgb2cpp

enissay14 commented 7 years ago

@drag0 you rock! Thanks.

xiaocongcsu commented 7 years ago

Is there any other method to use xgboost classifier in C++ project? For the cpp model is too long to compile in tx2. Thanks