import os from glob import glob import torch from tqdm import tqdm for ckpt_path in tqdm(sorted(glob("./**/*.pth", recursive=True)), dynamic_ncols=True): if (not os.path.isfile(ckpt_path)) or os.path.islink(ckpt_path): continue ckpt = torch.load(ckpt_path, map_location="cpu") if "model" not in ckpt or len(ckpt) == 1: continue for k in tuple(ckpt.keys()): if k != "model": del ckpt[k] torch.save(ckpt, ckpt_path)