https://kedro.org/ logo
#questions
Title
# questions
f

Francis Duval

01/22/2024, 6:46 PM
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

datajoely

01/22/2024, 6:46 PM
so this is just an error passed up from
json.dumps
what do you have in your dictionary?
f

Francis Duval

01/22/2024, 6:49 PM
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

datajoely

01/22/2024, 6:49 PM
<class 'torch.optim.adam.Adam'>
and the other classes aren’t serializable
f

Francis Duval

01/22/2024, 6:49 PM
Oh, need to transform back to string.
d

datajoely

01/22/2024, 6:49 PM
yes exactly
f

Francis Duval

01/22/2024, 6:50 PM
Thanks, I'm pretty new to Python, that's why XD
d

datajoely

01/22/2024, 6:51 PM
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

Francis Duval

01/22/2024, 6:52 PM
Oh yes, makes sense, only Python can understand these kinds of objects.
🚀 1