Download dataset_layout.py from EntropyDrop/SKING_DDJ_Dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/datasets/EntropyDrop/SKING_DDJ_Dataset/resolve/main/dataset_layout.py
- Command line
-
hf download hf://datasets/EntropyDrop/SKING_DDJ_Dataset/dataset_layout.py
-
curl -L -o dataset_layout.py https://huggingface.co/datasets/EntropyDrop/SKING_DDJ_Dataset/resolve/main/dataset_layout.py
1.3 kB
| """Shared file naming and directory layout for dataset readers and writers.""" | |
| from pathlib import Path | |
| import re | |
| SHARD_PREFIX_LENGTH = 3 | |
| DATASET_FILE_PATTERN = re.compile( | |
| r"(?P<id>.+?)_(?:(?:source|intermediate|edited|result|perfect)" | |
| r"(?:_[A-Za-z0-9][A-Za-z0-9_-]*)?\.(?:png|jpe?g|webp)" | |
| r"|(?:prompt|best|perfect|all_rejected)\.txt" | |
| r"|(?:author|decode)\.json" | |
| r"|(?:meat|semantic)\.(?:png|json)" | |
| r"|result(?:_[A-Za-z0-9][A-Za-z0-9_-]*)?\.uv_review\.json)" | |
| ) | |
| def generation_directory(root: Path, model_version: str, generation_id: str) -> Path: | |
| """Use the first three ID characters for every model; short IDs stay intact.""" | |
| for value in (model_version, generation_id): | |
| if not value or value in {".", ".."} or any(c in value for c in "/\\\0"): | |
| raise ValueError("Model version and generation ID must be single path components") | |
| return Path(root) / model_version / generation_id[:SHARD_PREFIX_LENGTH] | |
| def model_directory(sample_directory: Path, generation_id: str) -> Path: | |
| """Recognize current shards and the previous one-character layout for readers.""" | |
| directory = Path(sample_directory) | |
| if directory.name in {generation_id[:SHARD_PREFIX_LENGTH], generation_id[:1]}: | |
| return directory.parent | |
| return directory | |