forked from TomasBrezina/NeuralNetworkRacing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__main__.py
44 lines (33 loc) · 1.07 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
42
43
44
# -*- coding: utf-8 -*-
"""
DEEP LEARNING CARS
Simple simulation in Python in which a Neural Network learns to drive a racing car on a track.
Neural network has several inputs (distance sensors and car speed)
and it outputs acceleration and steering.
I used a simple Evolutionary algorithm to train the NN.
- Tomáš Březina 2020
Run command:
pip install -r requirements.txt
"""
from app import App, load_json
from game.messages import ask_load_nn, ask_yes_no
from models.evolution import Entity
# simulation settings
settings = load_json("configs/config.json")
entity = Entity()
SAVE_FILE = None
if ask_yes_no(title="Start", message="Load saved NN?"):
SAVE_FILE = ask_load_nn("saves")
# if save file is defined
if SAVE_FILE:
entity.load_file(SAVE_FILE)
else:
# create new neural network
nn_stg = load_json("configs/default_nn_config.json")
entity.set_parameters_from_dict(nn_stg)
entity.nn = entity.get_random_nn()
# window
app = App(settings)
app.start_simulation(
entity=entity, track=app.tile_manager.generate_track(shape=(5, 3), spawn_index=0)
)