Reset cnn weights in json using keras

I want to use dumping weights and model architecture in another framework for testing.

I know it:

  • model.get_config() can give a model configuration
  • model.to_json returns the model view as a JSON string, but this view does not include weights, only architecture
  • model.save_weights(filepath) saves model weight as an HDF5 file

I want to keep the architecture and weights in a JSON file.

+4
source share
2 answers

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

Solution 1:

Now you can easily do this, iterate over the weights and save it in a JSON file.

weights_list = model.get_weights()

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

, , :

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

2:

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

? 1, "NameError: 'writeJSON'

0

Source: https://habr.com/ru/post/1677135/


All Articles