Download dataset_code/get_length_num.py from SuperCS/useful_code: direct link, hf CLI and curl.
- Browser
- Download file 933 Bytes
-
https://huggingface.co/datasets/SuperCS/useful_code/resolve/e31e7b4c95a577cc71d9084c97befecffb3ebf56/dataset_code/get_length_num.py
- Command line
-
hf download hf://datasets/SuperCS/useful_code@e31e7b4c95a577cc71d9084c97befecffb3ebf56/dataset_code/get_length_num.py
-
curl -L -o get_length_num.py https://huggingface.co/datasets/SuperCS/useful_code/resolve/e31e7b4c95a577cc71d9084c97befecffb3ebf56/dataset_code/get_length_num.py
933 Bytes
| import os | |
| from collections import Counter | |
| from tqdm import tqdm | |
| def count_lengths(folder_path): | |
| lengths = [] | |
| for filename in os.listdir(folder_path): | |
| if filename.endswith('.pt'): | |
| parts = filename.split('_') | |
| if len(parts) >= 4: | |
| try: | |
| length = int(parts[-3]) | |
| resolution = f"{length}" | |
| lengths.append(resolution) | |
| except ValueError: | |
| print(f"无法解析文件: {filename}") | |
| counter = Counter(lengths) | |
| print("各长度统计:") | |
| for length, count in sorted(counter.items(), key=lambda x: x[1], reverse=True): | |
| print(f"{length}: {count}个文件") | |
| total_files = sum(counter.values()) | |
| print(f"\n总计: {total_files}个文件") | |
| return counter | |
| # 使用方法: | |
| count_lengths("/mnt/bn/yufan-dev-my/ysh/Datasets/fp_offload_latents") | |