| import os | |
| from collections import Counter | |
| from tqdm import tqdm | |
| def count_resolutions(folder_path): | |
| resolutions = [] | |
| for filename in os.listdir(folder_path): | |
| if filename.endswith('.pt'): | |
| parts = filename.split('_') | |
| if len(parts) >= 4: | |
| try: | |
| height = int(parts[-2]) | |
| width = int(parts[-1].split('.')[0]) # 去掉.pt后缀 | |
| resolution = f"{width}×{height}" | |
| resolutions.append(resolution) | |
| except ValueError: | |
| print(f"无法解析文件: {filename}") | |
| counter = Counter(resolutions) | |
| print("各分辨率统计:") | |
| for resolution, count in sorted(counter.items()): | |
| print(f"{resolution}: {count}个文件") | |
| return counter | |
| # 使用方法: | |
| count_resolutions("/mnt/bn/yufan-dev-my/ysh/Datasets/fp_offload_latents") | |