Datasets:
Upload parquet_to_raw.py with huggingface_hub
Browse files- parquet_to_raw.py +4 -27
parquet_to_raw.py
CHANGED
|
@@ -9,7 +9,6 @@ import json
|
|
| 9 |
from pathlib import Path
|
| 10 |
|
| 11 |
from datasets import load_dataset, load_from_disk
|
| 12 |
-
from huggingface_hub import HfApi
|
| 13 |
|
| 14 |
# split -> (has_reflections, has_edge)
|
| 15 |
SPLITS = {
|
|
@@ -32,7 +31,7 @@ def save_split(ds, split: str, has_reflections: bool, has_edge: bool, out_dir: P
|
|
| 32 |
for i, sample in enumerate(ds):
|
| 33 |
stem = sample.get("image_id") or f"{i:06d}"
|
| 34 |
|
| 35 |
-
img_path = img_dir / f"{stem}.
|
| 36 |
mask_path = mask_dir / f"{stem}.png"
|
| 37 |
sample["image"].save(img_path)
|
| 38 |
sample["mask"].save(mask_path)
|
|
@@ -57,9 +56,9 @@ def save_split(ds, split: str, has_reflections: bool, has_edge: bool, out_dir: P
|
|
| 57 |
if (i + 1) % 100 == 0:
|
| 58 |
print(f" {i + 1}/{len(ds)}")
|
| 59 |
|
| 60 |
-
(split_dir / "metadata.jsonl").write_text(
|
| 61 |
-
|
| 62 |
-
)
|
| 63 |
print(f" saved {len(rows)} samples -> {split_dir}")
|
| 64 |
|
| 65 |
|
|
@@ -71,8 +70,6 @@ def main():
|
|
| 71 |
parser.add_argument("--out", default="GSD", help="Output root directory (default: ./GSD)")
|
| 72 |
parser.add_argument("--splits", nargs="+", choices=list(SPLITS), default=list(SPLITS),
|
| 73 |
help="Which splits to convert (default: all)")
|
| 74 |
-
parser.add_argument("--upload-to", metavar="REPO_ID",
|
| 75 |
-
help="Upload raw files to this HF dataset repo after conversion, e.g. garrying/GSD-raw")
|
| 76 |
args = parser.parse_args()
|
| 77 |
|
| 78 |
out_dir = Path(args.out)
|
|
@@ -92,26 +89,6 @@ def main():
|
|
| 92 |
|
| 93 |
print(f"\nDone! Raw files in: {out_dir.resolve()}")
|
| 94 |
|
| 95 |
-
if args.upload_to:
|
| 96 |
-
api = HfApi()
|
| 97 |
-
api.create_repo(args.upload_to, repo_type="dataset", exist_ok=True)
|
| 98 |
-
for split in args.splits:
|
| 99 |
-
print(f"\nUploading {split} -> {args.upload_to}...")
|
| 100 |
-
api.upload_folder(
|
| 101 |
-
folder_path=str(out_dir / split),
|
| 102 |
-
path_in_repo=split,
|
| 103 |
-
repo_id=args.upload_to,
|
| 104 |
-
repo_type="dataset",
|
| 105 |
-
ignore_patterns=["*.jsonl"],
|
| 106 |
-
)
|
| 107 |
-
api.upload_file(
|
| 108 |
-
path_or_fileobj=(out_dir / split / "metadata.jsonl").read_bytes(),
|
| 109 |
-
path_in_repo=f"{split}/metadata.jsonl",
|
| 110 |
-
repo_id=args.upload_to,
|
| 111 |
-
repo_type="dataset",
|
| 112 |
-
)
|
| 113 |
-
print(f"\nUploaded! https://huggingface.co/datasets/{args.upload_to}")
|
| 114 |
-
|
| 115 |
|
| 116 |
if __name__ == "__main__":
|
| 117 |
main()
|
|
|
|
| 9 |
from pathlib import Path
|
| 10 |
|
| 11 |
from datasets import load_dataset, load_from_disk
|
|
|
|
| 12 |
|
| 13 |
# split -> (has_reflections, has_edge)
|
| 14 |
SPLITS = {
|
|
|
|
| 31 |
for i, sample in enumerate(ds):
|
| 32 |
stem = sample.get("image_id") or f"{i:06d}"
|
| 33 |
|
| 34 |
+
img_path = img_dir / f"{stem}.jpg"
|
| 35 |
mask_path = mask_dir / f"{stem}.png"
|
| 36 |
sample["image"].save(img_path)
|
| 37 |
sample["mask"].save(mask_path)
|
|
|
|
| 56 |
if (i + 1) % 100 == 0:
|
| 57 |
print(f" {i + 1}/{len(ds)}")
|
| 58 |
|
| 59 |
+
# (split_dir / "metadata.jsonl").write_text(
|
| 60 |
+
# "\n".join(json.dumps(r) for r in rows)
|
| 61 |
+
# )
|
| 62 |
print(f" saved {len(rows)} samples -> {split_dir}")
|
| 63 |
|
| 64 |
|
|
|
|
| 70 |
parser.add_argument("--out", default="GSD", help="Output root directory (default: ./GSD)")
|
| 71 |
parser.add_argument("--splits", nargs="+", choices=list(SPLITS), default=list(SPLITS),
|
| 72 |
help="Which splits to convert (default: all)")
|
|
|
|
|
|
|
| 73 |
args = parser.parse_args()
|
| 74 |
|
| 75 |
out_dir = Path(args.out)
|
|
|
|
| 89 |
|
| 90 |
print(f"\nDone! Raw files in: {out_dir.resolve()}")
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
if __name__ == "__main__":
|
| 94 |
main()
|