Load model stored as json file Keras

I'm loading the model stored as json file using Keras library model_from_json. Following are the steps I'm executing

json_file = open('file.json', 'r')
loaded_model_json = json_file.read()
loaded_model = model_from_json(loaded_model_json)

Its throwing me an error when I execute : loaded_model = model_from_json(loaded_model_json)

Following is the error : TypeError: init() takes at least 4 arguments (3 given)

As per the documentation, I'm on the right track. Not sure where I'm going wrong. Appreciate any recommendations

1 answer

  • answered 2018-11-08 09:14 power.puffed


    Your code is correct and it should work, you can alternatively try:

    with open('model_architecture.json', 'r') as f:
          model = model_from_json(f.read())

    If this does not work, check your json file, it might me corrupt?