Download dataset_code/move_bad_pt.py from SuperCS/useful_code: direct link, hf CLI and curl.
- Browser
- Download file 1.91 kB
-
https://huggingface.co/datasets/SuperCS/useful_code/resolve/588aece1dbdc7786fe6bcebd2ddd82a60eb5dde3/dataset_code/move_bad_pt.py
- Command line
-
hf download hf://datasets/SuperCS/useful_code@588aece1dbdc7786fe6bcebd2ddd82a60eb5dde3/dataset_code/move_bad_pt.py
-
curl -L -o move_bad_pt.py https://huggingface.co/datasets/SuperCS/useful_code/resolve/588aece1dbdc7786fe6bcebd2ddd82a60eb5dde3/dataset_code/move_bad_pt.py
1.91 kB
| import os | |
| import shutil | |
| import torch | |
| from concurrent.futures import ThreadPoolExecutor, as_completed | |
| from tqdm import tqdm | |
| # 设置路径 | |
| src_dirs = [ | |
| "/mnt/bn/yufan-dev-my/ysh/Ckpts/Lixsp11/0_final_sekai_dataset/sekai-real-drone", | |
| "/mnt/bn/yufan-dev-my/ysh/Ckpts/Lixsp11/0_final_sekai_dataset/sekai-game-drone", | |
| "/mnt/bn/yufan-dev-my/ysh/Ckpts/Lixsp11/0_final_sekai_dataset/sekai-game-walking-193", | |
| "/mnt/bn/yufan-dev-my/ysh/Ckpts/Lixsp11/0_final_sekai_dataset/sekai-game-walking-386", | |
| "/mnt/bn/yufan-dev-my/ysh/Ckpts/Lixsp11/0_final_sekai_dataset/sekai-real-walking-hq-193", | |
| "/mnt/bn/yufan-dev-my/ysh/Ckpts/Lixsp11/0_final_sekai_dataset/sekai-real-walking-hq-386", | |
| ] | |
| # src_dir = '/mnt/bn/yufan-dev-my/ysh/Datasets/fp_offload_latents' | |
| bad_dir = '/mnt/bn/yufan-dev-my/ysh/Datasets/bad_pt' | |
| for src_dir in src_dirs: | |
| # 创建 bad_pt 目录(如果不存在) | |
| os.makedirs(bad_dir, exist_ok=True) | |
| # 检查并移动损坏文件 | |
| def check_and_move(file): | |
| file_path = os.path.join(src_dir, file) | |
| try: | |
| torch.load(file_path, map_location='cpu', weights_only=False) | |
| return (file, True) # 成功加载 | |
| except Exception: | |
| shutil.move(file_path, os.path.join(bad_dir, file)) | |
| return (file, False) | |
| # 获取所有 pt 文件 | |
| pt_files = [f for f in os.listdir(src_dir) if f.endswith('.pt')] | |
| # 进度条包装器 | |
| results = [] | |
| with ThreadPoolExecutor(max_workers=8) as executor: | |
| futures = {executor.submit(check_and_move, file): file for file in pt_files} | |
| for future in tqdm(as_completed(futures), total=len(futures), desc="处理中"): | |
| file, ok = future.result() | |
| if not ok: | |
| print(f"❌ 损坏:{file}") | |
| # 可以注释掉下面这行减少控制台输出 | |
| # else: | |
| # print(f"✅ 正常:{file}") | |