Hello! I have this weird error when trying to cata...
# questions
f
Hello! I have this weird error when trying to catalog a dictionary as a json file:
Object of type type is not JSON serializable
I wonder what I did wrong, because I followed this tutorial closely: https://demo.kedro.org/ My catalog entry:
Copy code
tune.base_batchnorm_l2reg.params:
  type: tracking.JSONDataset
  filepath: data/07_tuning_results/base_batchnorm_l2reg/params.json
  versioned: True
Do you have an idea of why this is happening?
d
so this is just an error passed up from
json.dumps
what do you have in your dictionary?
f
It is a simple dictionary (non-nested): { 'model_class': 'NNFreq_no_batchnorm', 'optimizer': class 'torch.optim.adam.Adam', 'early_stopping_patience': 10, 'lr_scheduler_factor': 0.2, 'lr_scheduler_patience': 5, 'batch_size': [64], 'optimizer__lr': [0.0001], 'module__act': [class 'torch.nn.modules.activation.ReLU', class 'torch.nn.modules.activation.Tanh']}
d
<class 'torch.optim.adam.Adam'>
and the other classes aren’t serializable
f
Oh, need to transform back to string.
d
yes exactly
f
Thanks, I'm pretty new to Python, that's why XD
d
no worries! the general rule of json is that you need to work with primitives like string, int, list etc. But when you get to complex objects, particularly those that wont work outside of Python you’ll need to either default to string or be creative in other ways.
K 1
f
Oh yes, makes sense, only Python can understand these kinds of objects.
🚀 1