Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare the similarity of two keras models

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())
like image 400
Stergios Avatar asked Nov 08 '22 00:11

Stergios


1 Answers

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())
like image 152
Abdulrahman Bres Avatar answered Nov 14 '22 21:11

Abdulrahman Bres