-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
92 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,54 @@ | ||
"""Make sure the data is available""" | ||
import os | ||
import shutil | ||
import sys | ||
import time | ||
from multiprocessing import Pool | ||
from pathlib import Path | ||
|
||
from torchvision.datasets import INaturalist | ||
|
||
|
||
start_time = time.time() | ||
INaturalist(root=sys.argv[1], version="2021_train", download=True) | ||
INaturalist(root=sys.argv[1], version="2021_valid", download=True) | ||
seconds_spent = time.time() - start_time | ||
print(f"Prepared data in {seconds_spent/60:.2f}m") | ||
def link_file(src:str, dest:str): | ||
Path(src).symlink_to(dest) | ||
|
||
|
||
def link_files(src:str, dest:str, workers=4): | ||
src = Path(src) | ||
dest = Path(dest) | ||
os.makedirs(dest, exist_ok=True) | ||
with Pool(processes=workers) as pool: | ||
for path, dnames, fnames in os.walk(str(src)): | ||
rel_path = Path(path).relative_to(src) | ||
fnames = map(lambda _f: rel_path / _f, fnames) | ||
dnames = map(lambda _d: rel_path / _d, dnames) | ||
for d in dnames: | ||
os.makedirs(str(dest / d), exist_ok=True) | ||
pool.starmap( | ||
link_file, | ||
[(src / _f, dest / _f) for _f in fnames] | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
src = Path(sys.argv[1]) | ||
workers = int(sys.argv[2]) | ||
# Referencing $SLURM_TMPDIR here instead of job.sh makes sure that the | ||
# environment variable will only be resolved on the worker node (i.e. not | ||
# referencing the $SLURM_TMPDIR of the master node) | ||
dest = Path(os.environ["SLURM_TMPDIR"]) / "dest" | ||
|
||
start_time = time.time() | ||
|
||
link_files(src, dest, workers) | ||
|
||
# Torchvision expects these names | ||
shutil.move(dest / "train.tar.gz", dest / "2021_train.tgz") | ||
shutil.move(dest / "val.tar.gz", dest / "2021_valid.tgz") | ||
|
||
INaturalist(root=dest, version="2021_train", download=True) | ||
INaturalist(root=dest, version="2021_valid", download=True) | ||
|
||
seconds_spent = time.time() - start_time | ||
|
||
print(f"Prepared data in {seconds_spent/60:.2f}m") |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters