-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
41 lines (33 loc) · 1.24 KB
/
main.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
from json import load
from sys import argv
from Individual import Individual
from Genetic import Genetic
if __name__ == '__main__':
print(len(argv))
if len(argv) != 4:
raise ValueError('\nUsage:\n\tpython main.py PATH_TO_PARAMS PATH_TO_INPUT PATH_TO_OUTPUT')
with open(argv[1]) as params_json:
params = load(params_json)
target_img = Individual(argv[2])
model = Genetic(
target_img,
population_size=params['population_size'],
tournament_size=params['tournament_size'],
parents_size=params['parents_size'],
mutation_rate=params['mutation_rate'],
blend_use=params['blend_use'],
block_size=tuple(params['block_size']),
num_blocks_initialize=tuple(params['num_blocks_initialize']),
max_blocks_mutation=params['max_blocks_mutation']
)
print('Initializing...')
model.initialize_population()
print('Population Initialized.')
print('Running...')
model.run(
generations=params['generations'],
print_every=params['print_every'])
print('Calculating Top Individual...')
top, fitness = model.top_individuals()
top.show(f'Fitness: {fitness}')
top.save(argv[3])