-
Notifications
You must be signed in to change notification settings - Fork 26
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
pierre.delaunay
committed
Jun 6, 2024
1 parent
17d2db5
commit 6774538
Showing
8 changed files
with
103 additions
and
521 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,59 +1,6 @@ | ||
#!/usr/bin/env python | ||
|
||
import multiprocessing | ||
import os | ||
from pathlib import Path | ||
|
||
from tqdm import tqdm | ||
|
||
|
||
def write(args): | ||
from torchvision.datasets import FakeData | ||
|
||
image_size, offset, count, outdir = args | ||
dataset = FakeData( | ||
size=count, image_size=image_size, num_classes=1000, random_offset=offset | ||
) | ||
|
||
image, y = next(iter(dataset)) | ||
class_val = int(y) | ||
image_name = f"{offset}.jpeg" | ||
|
||
path = os.path.join(outdir, str(class_val)) | ||
os.makedirs(path, exist_ok=True) | ||
|
||
image_path = os.path.join(path, image_name) | ||
image.save(image_path) | ||
|
||
|
||
def generate(image_size, n, outdir): | ||
p_count = min(multiprocessing.cpu_count(), 8) | ||
pool = multiprocessing.Pool(p_count) | ||
for _ in tqdm( | ||
pool.imap_unordered(write, ((image_size, i, n, outdir) for i in range(n))), | ||
total=n, | ||
): | ||
pass | ||
|
||
|
||
def generate_sets(root, sets, shape): | ||
root = Path(root) | ||
sentinel = root / "done" | ||
if sentinel.exists(): | ||
print(f"{root} was already generated") | ||
return | ||
if root.exists(): | ||
print(f"{root} exists but is not marked complete; deleting") | ||
root.rm() | ||
for name, n in sets.items(): | ||
print(f"Generating {name}") | ||
generate(shape, n, os.path.join(root, name)) | ||
sentinel.touch() | ||
|
||
from benchmate.datagen import generate_fakeimagenet | ||
|
||
if __name__ == "__main__": | ||
data_directory = os.environ["MILABENCH_DIR_DATA"] | ||
dest = os.path.join(data_directory, "FakeImageNet") | ||
print(f"Generating fake data into {dest}...") | ||
generate_sets(dest, {"train": 4096, "val": 16, "test": 16}, (3, 384, 384)) | ||
print("Done!") | ||
generate_fakeimagenet() |
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
Oops, something went wrong.