File size: 472 Bytes
1b46ba9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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)