-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_test.py
50 lines (37 loc) · 1 KB
/
make_test.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
import pickle
import yaml
import sys
from utils.set_seed import set_seed
"""
Pre-generate a set of testing games
"""
def make_games(dataset, number_of_images, number_of_games, game_type, seed=None):
# LOAD DATASET
from utils.dataprep import load_emb_pickled
metadata, embeddings = load_emb_pickled(dataset)
filenames = metadata.get("fnames")
categories = metadata.get("categories")
# CREATE GAME
game_settings = {
"images": embeddings,
"categories": categories,
"images_filenames": filenames
}
from game import Game
game = Game(**game_settings)
if seed is not None:
set_seed(seed)
return game.generate_games(number_of_games, number_of_images, game_type)
def main(out_path, **kwargs):
games = make_games(**kwargs)
with open(out_path, "wb") as f:
pickle.dump(games, f)
print(f"Saved to {out_path}")
if __name__ == "__main__":
if len(sys.argv) == 2:
config = sys.argv[1]
else:
config = "settings-make-test.yml"
with open(config, "r") as f:
settings = yaml.load(f)
main(**settings)