Model Comparison
Change checkpoint_path1 in the ckpt_compare.py file (as shown in the following code block) to the path of the abnormal model file and checkpoint_path2 to the path of the normal model file. Then, run the ckpt_compare.py script in the TensorFlow 1.15 environment. The variable names and cosine similarity are output in ascending order of cosine similarity.
from tensorflow.python import pywrap_tensorflow
import numpy as np
checkpoint_path1 = "path1/model-200"
checkpoint_path2 = "path2/model-200"
reader1 = pywrap_tensorflow.NewCheckpointReader(checkpoint_path1)
reader2 = pywrap_tensorflow.NewCheckpointReader(checkpoint_path2)
var_to_shape_map = reader1.get_variable_to_shape_map()
key_cos = {}
for key in var_to_shape_map:
tensor1 = reader1.get_tensor(key).reshape(-1)
tensor2 = reader2.get_tensor(key).reshape(-1)
key_cos[key] = np.dot(tensor1,tensor2)/(np.linalg.norm(tensor1)*np.linalg.norm(tensor2))
key_cos = list(key_cos.items())
key_cos.sort(key = lambda x : x[1])
for key, cos in key_cos:
print(key, cos)

Parent topic: Random Error Location