gvecchio commited on
Commit
62c7ae3
1 Parent(s): 2d0f543

Add dataset download script

Browse files
Files changed (1) hide show
  1. scripts/download_dataset.py +32 -0
scripts/download_dataset.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ import requests
3
+ 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
+ r = requests.get(f"{dset_url}/{split}/{class_name}.zip")
15
+ with open(base_dir/split/(class_name + ".zip"), "wb") as f:
16
+ f.write(r.content)
17
+ if class_name in ["Ground", "Wood"]:
18
+ r = requests.get(dset_url + class_name + ".z01")
19
+ with open(base_dir/split/(class_name + ".z01"), "wb") as f:
20
+ f.write(r.content)
21
+
22
+ if __name__ == "__main__":
23
+ # Create argument parser
24
+ parser = argparse.ArgumentParser(description="Download dataset categories.")
25
+ parser.add_argument("--base_dir", required=True, help="Base directory to save the downloaded files.")
26
+ parser.add_argument("--class_names", help="Specify the class name to download a specific category.")
27
+ args = parser.parse_args()
28
+
29
+ # Call the download_dataset function with command-line arguments
30
+ download_dataset(Path(args.base_dir), args.class_names)
31
+
32
+ # python script.py --base_dir /path/to/save --class_name Leather