I have built a Keras model using the functional API and I created a second model using model_from_json()
function. I want to see if the model layers (not the weights) of the two models are exactly the same.
How can I compare the two Keras models?
EDIT
Based on the comments below, I could possibly compare each layer. Would something like the one below make sense:
for l1, l2 in zip(mdl.layers, mdl2.layers):
print (l1.get_config() == l2.get_config())
Update: your approach is correct.
You can iterate over the two models layers and compare one by one (since you don't care about the weights or how the model is compiled and optimized).
You can do this:
for l1, l2 in zip(mdl.layers, mdl2.layers):
print(l1.get_config() == l2.get_config())
Or just:
print(mdl.get_config() == mdl2.get_config())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With