-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_cache.py
61 lines (45 loc) · 1.82 KB
/
run_cache.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import argparse
import os
from src import logging
from src.data.dataloader import Feature
from src.data.train import default_config, load_data
logger = logging.create_logger(__name__)
BATCH_SIZE = 128
def cache(size, cache_dir):
config = default_config()
config.features = [Feature.image]
config.crop_size = size
# Create image cache dir
config.image_cache_dir = cache_dir + f"/image_cache_{size}"
config.image_cache_dir = config.image_cache_dir.replace("(", "")
config.image_cache_dir = config.image_cache_dir.replace(",", "")
config.image_cache_dir = config.image_cache_dir.replace(")", "")
config.image_cache_dir = config.image_cache_dir.replace(" ", "-")
logger.info(f"Caching images with size {size} in dir {config.image_cache_dir}")
dataset_train, dataset_valid, dataset_test = load_data(
enable_tf_caching=False, config=config
)
_create_cache("train", dataset_train)
_create_cache("valid", dataset_valid)
_create_cache("test", dataset_test)
os.system(f"tar -cf {config.image_cache_dir}.tar {config.image_cache_dir}")
def _create_cache(name, dataset):
for i, _ in enumerate(dataset.batch(BATCH_SIZE)):
logger.info(f"Cached {i * BATCH_SIZE} {name} images")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--size-x", help="Image size in x direction", type=int, required=True,
)
parser.add_argument(
"--size-y", help="Image size in y direction", type=int, required=True,
)
parser.add_argument(
"--cache-dir",
help="Directory where image are going to be cache and compressed",
type=str,
default="/project/cq-training-1/project1/teams/team10",
)
args = parser.parse_args()
size = (args.size_x, args.size_y)
cache(size, args.cache_dir)