-
Notifications
You must be signed in to change notification settings - Fork 1
/
bin2text.py
53 lines (46 loc) · 1.51 KB
/
bin2text.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import xgboost as xgb
import getopt as opt
MODEL_PATH = ''
FEATURE_PATH = ''
TYPE = None
OUTPUT_PATH = ''
def usage():
help_text= '''
Usage: dumpBin [OPTION] args
dumpBin help
options:
-m, --model MODEL_PATH model's dump file, specified.
-f, --feature FEATURE_PATH feature's file, specified.
-o, --output OUTPUT_PATH output path.
-t, --type type the format of output file.
'''
print help_text
def getOpts(argv):
global FEATURE_PATH, MODEL_PATH, BOOSTER_NUM, DEPTH, OUTPUT_PATH
try:
options, args = opt.getopt(argv[1:], '-m:-f:-t:-o:-h', ['feature=','model=', 'type=','output=','help'])
for op, value in options:
if op in ('-h','--help'):
usage()
sys.exit()
if op in ('-f', '--feature'):
FEATURE_PATH = value
if op in ('-m', '--model'):
MODEL_PATH = value
if op in ('-t', '--type'):
TYPE = value
if op in ('-o', '--output'):
OUTPUT_PATH = value
if FEATURE_PATH == '' or MODEL_PATH == '':
usage()
sys.exit()
except opt.GetoptError:
usage()
sys.exit()
def dumpBin(model_path, feature_map='', out_put='' ,ftype=''):
bst = xgb.load_model(mode_path)
bst.dump_model(out_put, fmap=freature_map, with_stats=True, dump_format=ftype)
if __name__ == '__main__':
# get options
getOpts(sys.argv)
dumpBin(MODEL_PATH, FEATURE_PATH, OUTPUT_PATH, TYPE)