Chadrick Blog

saving and loading only architecture of tf.keras model

One can export only the model’s architecture information as JSON file like the following.

modeljson = model.to\_json()

model\_save\_path = "somewhere/model\_arch.json

with open(model\_save\_path,'w') as fd:
    fd.write(modeljson)

To load this back to model, here is a sample code

with open(model\_json\_path,'r') as fd:
    modeljson = fd.read()

model = tf.keras.models.model\_from\_json(modeljson)