useful_code / dataset_code /move_bad_pt.py
SuperCS's picture
Add files using upload-large-folder tool
e31e7b4 verified
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}")