Update scripts/download_dataset.py
Browse files- scripts/download_dataset.py +17 -8
scripts/download_dataset.py
CHANGED
@@ -4,20 +4,29 @@ from pathlib import Path
|
|
4 |
|
5 |
classlist = ["Blends", "Ceramic", "Concrete", "Fabric", "Leather", "Marble", "Metal", "Misc", "Plaster", "Plastic", "Stone", "Terracotta", "Wood"]
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
def download_dataset(base_dir, class_names=None):
|
8 |
-
dset_url = "https://huggingface.co/datasets/gvecchio/MatSynth/resolve/main/maps
|
9 |
|
10 |
classes = class_names.split(",") if class_names else classlist
|
11 |
if classes:
|
12 |
for split in ["train", "test"]:
|
|
|
|
|
|
|
13 |
for class_name in classes:
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
if class_name in ["Ground", "Wood"]:
|
18 |
-
|
19 |
-
|
20 |
-
f.write(r.content)
|
21 |
|
22 |
if __name__ == "__main__":
|
23 |
# Create argument parser
|
|
|
4 |
|
5 |
classlist = ["Blends", "Ceramic", "Concrete", "Fabric", "Leather", "Marble", "Metal", "Misc", "Plaster", "Plastic", "Stone", "Terracotta", "Wood"]
|
6 |
|
7 |
+
def download_stream(url, dest_file):
|
8 |
+
with requests.get(url, stream=True) as r:
|
9 |
+
r.raise_for_status()
|
10 |
+
with open(dest_file, "wb") as f:
|
11 |
+
for chunk in r.iter_content(chunk_size=8192):
|
12 |
+
f.write(chunk)
|
13 |
+
|
14 |
def download_dataset(base_dir, class_names=None):
|
15 |
+
dset_url = "https://huggingface.co/datasets/gvecchio/MatSynth/resolve/main/maps"
|
16 |
|
17 |
classes = class_names.split(",") if class_names else classlist
|
18 |
if classes:
|
19 |
for split in ["train", "test"]:
|
20 |
+
dest_dir = base_dir/split
|
21 |
+
dest_dir.mkdir(parents=True, exist_ok=True)
|
22 |
+
|
23 |
for class_name in classes:
|
24 |
+
req = f"{dset_url}/{split}/{class_name}.zip"
|
25 |
+
download_stream(req, dest_dir/(class_name + ".zip"))
|
26 |
+
|
27 |
+
if class_name in ["Ground", "Wood"] and split == "train":
|
28 |
+
req = f"{dset_url}/{split}/{class_name}.z01"
|
29 |
+
download_stream(req, dest_dir/(class_name + ".z01"))
|
|
|
30 |
|
31 |
if __name__ == "__main__":
|
32 |
# Create argument parser
|