dump weights of cnn in json using keras dump weights of cnn in json using keras json json

dump weights of cnn in json using keras


Keras does not have any built-in way to export the weights to JSON.

Solution 1:

For now you can easily do it by iterating over the weights and saving it to the JSON file.

weights_list = model.get_weights()

will return a list of all weight tensors in the model, as Numpy arrays.

Then, all you have to do next is to iterate over this list and write to the file:

for i, weights in enumerate(weights_list):    writeJSON(weights)

Solution 2:

import jsonweights_list = model.get_weights()print json.dumps(weights_list.tolist())