Limits of Keras load_weights skip_mismatch for rollback after a schema change
0 reputation · 30 Dec 2021, 00:30 UTC
Goal
I want to reuse trained weights from a previous model version after changing the architecture (for example, adding a Dense layer), and I need the process to be rollback-safe: the original layers must keep their trained values, and it must be obvious which parts of the new model were left untouched.
Constraints and uncertainty
Keras documents model.load_weights(filepath, by_name=True, skip_mismatch=True) as a way to load weights into a modified architecture by matching layers by name and skipping shape mismatches. With the default by_name=False, any architecture change raises a ValueError, which is safe but blocks reuse entirely. My concern is that skip_mismatch=True appears to silently ignore mismatched layers, so a partially initialized model could go unnoticed unless I audit the result myself. I am assuming TensorFlow 2.x with tf.keras, since the skip_mismatch argument is not available in older standalone Keras releases.
Questions
- Is there a documented way to enumerate which layers were skipped during a
skip_mismatch=Trueload, or is manual comparison of layer names and shapes the only option? - Does
by_name=Trueguarantee that renamed or reordered layers are matched correctly, or are there documented edge cases where weights land on the wrong layer? - Is combining
model.get_config()with weight saving a supported pattern for reverting to a prior schema, or is full model saving the only reliable rollback path?