Skip to content

Error while loading model #5826

@nathanhack

Description

@nathanhack

After train a model for a long time I saved it using

bst.save_model("xgboostModel.trail04.json")

I latter tried to load it with the same params to continue training

filemodel = 'xgboostModel.trail04.json'
bst = xgb.train(param, xgTrain, num_boost_round=numOfRounds, evals=watchList, early_stopping_rounds=2000, xgb_model=filemodel)

but I get this error:

  File "/home/user/programs/pycharm/plugins/python-ce/helpers/pydev/pydevd.py", line 1438, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/home/user/programs/pycharm/plugins/python-ce/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/user/projects/temp/pythontmp/lastPointClassifiers.py", line 270, in <module>
    trial04()
  File "/home/user/projects/temp/pythontmp/lastPointClassifiers.py", line 256, in trial04
    xgb_model=filemodel)
  File "/home/user/.local/lib/python3.7/site-packages/xgboost/training.py", line 212, in train
    xgb_model=xgb_model, callbacks=callbacks)
  File "/home/user/.local/lib/python3.7/site-packages/xgboost/training.py", line 37, in _train_internal
    model_file=xgb_model)
  File "/home/user/.local/lib/python3.7/site-packages/xgboost/core.py", line 1175, in __init__
    self.load_model(model_file)
  File "/home/user/.local/lib/python3.7/site-packages/xgboost/core.py", line 1804, in load_model
    self.handle, c_str(os_fspath(fname))))
  File "/home/user/.local/lib/python3.7/site-packages/xgboost/core.py", line 190, in _check_call
    raise XGBoostError(py_str(_LIB.XGBGetLastError()))
xgboost.core.XGBoostError: [19:57:42] /workspace/src/common/json.cc:413: Expecting: ",", got: "

When I try the same exact thing but run it over a smaller number of rounds it loads fine and trains like a champ.

def Example():
    X, Y = getData(randomize=True)
    X = np.array(X)
    Y = np.array(Y)
    l = int(len(X) * .5)
    xgTrain = xgb.DMatrix(X[:l], label=Y[:l])
    xgTest = xgb.DMatrix(X[l:], label=Y[l:])
    param = {
        'objective': 'multi:softmax',
        'eta': 0.0001,
        'max_depth': 6,
        'nthread': 16,
        'num_class': 2,
        'tree_method': 'gpu_hist',
    }
    watchList = [(xgTrain, 'train'), (xgTest, 'test')]
    numOfRounds = 1000000
    filemodel = 'xgboostModel.trail04.json'

    print("fit()")
    if path.exists(filemodel):
        bst = xgb.train(param, xgTrain, num_boost_round=numOfRounds, evals=watchList, early_stopping_rounds=2000,
                        xgb_model=filemodel)
    else:
        bst = xgb.train(param, xgTrain, num_boost_round=numOfRounds, evals=watchList, early_stopping_rounds=2000)

    bst.save_model(filemodel)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions