Save model with config.json

I am working on histological applications of ML using a software called QuPath. An extension called Stardist is used to load custom tf models into QuPath, and the Stardist loader requires a pb file with a config.json. According to the keras docs

" The Keras API saves all of these pieces together in a unified format, marked by the .keras extension. This is a zip archive consisting of the following:

A JSON-based configuration file (config.json): Records of model, layer, and other trackables’ configuration. A H5-based state file, such as model.weights.h5 (for the whole model), with directory keys for layers and their weights. A metadata file in JSON, storing things such as the current Keras version."

I’m in colab and I ran model.save. I get an empty assets folder, a variables folder, fingerprint.pb, keras_metadata.pb, and saved_model.pb. I’m a little confused as to why there is no config.json. Do I have to convert the keras_metadata.pb to keras_metadata.json?

Hi @Ahmed_Malik, Generally .pd file contains all the information about the graph, model architecture, and information about the model’s inputs and outputs. If you want to save the model configuration in the .json file you can get the model config by using model.get_config( ) and you save that in .json using

model_config=model.get_config()
model_config_json = json.dumps(model_config, indent=2)
with open('model_config.json', 'w') as json_file:
    json_file.write(model_config_json)

Thank You.

1 Like