I am training a TabNetClassifier. My code is largely borrowed from:
‘tabnet/census_example.ipynb at develop · dreamquark-ai/tabnet · GitHub’
Everything is working fine until I try to save the model. When trying to save the model, I get the error: ‘TypeError: Object of type int32 is not JSON serializable’
More details below:
from pytorch_tabnet.tab_model import TabNetClassifier
tabnet_params = {"cat_idxs": cat_idxs,
"cat_dims": cat_dims,
"cat_emb_dim": 2,
"optimizer_fn": torch.optim.Adam,
"optimizer_params": dict(lr=2e-2),
"scheduler_params": {"step_size": 50, "gamma": 0.9},
"scheduler_fn": torch.optim.lr_scheduler.StepLR,
"mask_type": 'entmax'}
clf = TabNetClassifier(**tabnet_params)
clf.fit(
X_train=X_train, y_train=y_train,
eval_set=[(X_train, y_train), (X_valid, y_valid)],
eval_name=['train', 'valid'],
eval_metric=['auc'],
max_epochs=50,
patience=20,
batch_size=1024,
virtual_batch_size=128,
num_workers=0,
weights=1,
drop_last=False)
My model trains fine and I can perform inference with it. However, when I try to save it:
saving_path_name = "./tabnet_model_test_1"
saved_filepath = clf.save_model(saving_path_name)
>>> TypeError: Object of type int32 is not JSON serializable