How to compare the similarity of two keras models

Viewed 3980

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())
2 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())

you can use ROC curves to compare classifiers.

With binary classifiers, one calculates the true-positive-rate and the false-positive-rate for all possible thresholds and plots the first on the y-axis and the second on the x-axis. The resulting curve per classifier can be integrated and the resulting integral, the so called "area under the curve", is equal to the probability that the classifier rankes a randomly chosen positive sample higher than a randomly chosen negative one. This value can be used to compare classifiers because a higher value shows a overall better performance than a lower one. Fawcett also gives a method to apply this to multi-class classification

Related