XLSR-Conformer-TCM-DF / convert.py
korallll's picture
Wrapper code (speech-spoof-bench)
6332a34 verified
Raw History Blame Contribute Delete
1.15 kB
# convert.py — DF checkpoint -> model.safetensors (2026-11-01).
# Source: NTU SharePoint (guest link from github ductuantruong/tcm_add README),
# model_checkpoints/interspeech24_tcm/DF/fixed_length/avg_5_best.pth (1,285,107,735 B)
# = the authors' own main.py 5-checkpoint average (fixed-length DF model). Re-saved unchanged.
# Loaded with weights_only=True (plain tensor state_dict, no code objects).
import os
import sys
import torch
from safetensors.torch import save_file
HERE = os.path.dirname(os.path.abspath(__file__))
SRC = sys.argv[1] if len(sys.argv) > 1 else os.path.join(
HERE, "..", "_ckpt_dl", "ntu__tcm_add", "DF", "fixed_length", "avg_5_best.pth")
sd = torch.load(SRC, map_location="cpu", weights_only=True)
assert isinstance(sd, dict) and all(isinstance(v, torch.Tensor) for v in sd.values())
sd = {k: v.contiguous() for k, v in sd.items()}
print(len(sd), "tensors;", sorted({str(v.dtype) for v in sd.values()}))
save_file(sd, os.path.join(HERE, "model.safetensors"), metadata={"source": "tcm_add DF/fixed_length/avg_5_best.pth"})
print("wrote model.safetensors", os.path.getsize(os.path.join(HERE, "model.safetensors")))