-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathmain_NN_Vehicle_dynamics.py
89 lines (65 loc) · 4.11 KB
/
main_NN_Vehicle_dynamics.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import numpy as np
import sys
import random
# custom modules
import helper_funcs_NN
import src
import visualization
"""
Created by: Leonhard Hermansdorfer, Rainer Trauth
Created on: 01.04.2020
Documentation
main script to run neural network training
"""
random.seed(7)
np.random.seed(7)
# ----------------------------------------------------------------------------------------------------------------------
# Manage Paths ---------------------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------------------------
# create a dictionary which contains paths to all relevant folders and files
path_dict = helper_funcs_NN.src.manage_paths.manage_paths()
# ----------------------------------------------------------------------------------------------------------------------
# Read Parameters ------------------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------------------------
# create a dictionary which contains all parameters
params_dict = helper_funcs_NN.src.handle_params.handle_params(path_dict=path_dict)
# ----------------------------------------------------------------------------------------------------------------------
# Training of the Neural Network ---------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------------------------
# THIS IS THE START (CONFIGURATION) OF THE PROGRAM
if params_dict['NeuralNetwork_Settings']['model_mode'] == 1:
src.train_neuralnetwork.train_neuralnetwork(path_dict=path_dict,
params_dict=params_dict,
nn_mode='feedforward')
if params_dict['NeuralNetwork_Settings']['model_mode'] == 2:
src.train_neuralnetwork.train_neuralnetwork(path_dict=path_dict,
params_dict=params_dict,
nn_mode="recurrent")
# ----------------------------------------------------------------------------------------------------------------------
# Evaluation of the Neural Network -------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------------------------
# exit python if evaluation is disabled (NeuralNetwork_Settings.run_file_mode == 0)
if params_dict['NeuralNetwork_Settings']['run_file_mode'] == 0:
sys.exit('SYSTEM EXIT: exit due to run_file_mode is set to zero to avoid testing the neural network against '
+ 'vehicle sensor data')
for i_count in range(0, params_dict['Test']['n_test']):
idx_start = params_dict['Test']['run_timestart'] + i_count * params_dict['Test']['iteration_step']
if params_dict['NeuralNetwork_Settings']['run_file_mode'] == 1:
print('STARTING RUN FEEDFORWARD NETWORK')
src.run_neuralnetwork.run_nn(path_dict=path_dict,
params_dict=params_dict,
startpoint=idx_start,
counter=i_count,
nn_mode="feedforward")
if params_dict['NeuralNetwork_Settings']['run_file_mode'] == 2:
print('STARTING RUN RECURRENT NETWORK')
src.run_neuralnetwork.run_nn(path_dict=path_dict,
params_dict=params_dict,
startpoint=idx_start,
counter=i_count,
nn_mode="recurrent")
# save and plot results (if activated in parameter file)
visualization.plot_results.plot_run(path_dict=path_dict,
params_dict=params_dict,
counter=i_count,
start=idx_start)