Filter training-only keys (teacher.*, caltime.*) from checkpoints

rife426.pth and possibly other new checkpoints contain extra modules
used during training (teacher network, caltime scheduler) that are not
part of the IFNet inference architecture. These cause
load_state_dict to fail with "Unexpected key(s)" errors.

Now export_onnx.py filters the state_dict to keep only keys that match
the model architecture before loading, with strict=True to catch any
real missing keys.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
huchukato
2026-08-05 11:01:43 +02:00
co-authored by Devin
parent 2e1c533e34
commit 9eefdbddfa
+13 -1
View File
@@ -120,7 +120,19 @@ def export_onnx(ckpt_name, ensemble, scale_factor):
model_path = load_file_from_github_release(MODEL_TYPE, ckpt_name)
arch_ver = CKPT_NAME_VER_DICT[ckpt_name]
interpolation_model = IFNet(arch_ver=arch_ver)
interpolation_model.load_state_dict(torch.load(model_path))
# Some checkpoints (e.g. rife426.pth) contain extra training-only modules
# (teacher.*, caltime.*) that are not part of the inference architecture.
# Filter them out to avoid load_state_dict errors.
raw_state_dict = torch.load(model_path, weights_only=False)
model_keys = set(interpolation_model.state_dict().keys())
filtered_state_dict = {
k: v for k, v in raw_state_dict.items()
if k in model_keys
}
skipped = set(raw_state_dict.keys()) - model_keys
if skipped:
print(f"Filtered out {len(skipped)} training-only keys: {sorted(skipped)[:5]}...")
interpolation_model.load_state_dict(filtered_state_dict, strict=True)
interpolation_model.eval().to(TORCH_DEVICE)
# # dummy data