Skip to content

Commit b97e8cf

Browse files
committed
initial commit
0 parents  commit b97e8cf

15 files changed

+2318
-0
lines changed

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
DeepNav_data/*
2+
DeepNav_results/*
3+
recycle/*
4+
*pycache*
5+
*.csv
6+
*.ulg
7+
*.pdf
8+
*.hdf5
9+
*.mp4
10+
*.json
11+
*.mat

DeepNav.py

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Created on Mon 09 Nov 2020 | 5:25 PM
4+
5+
@author: Ahmed Majuid
6+
7+
Usage: Define the network architecture and training hyperparameters
8+
"""
9+
10+
# non standard library
11+
import os
12+
import tensorflow as tf
13+
import training
14+
import utils
15+
import postprocessing
16+
from preprocessing.create_dataset import create_dataset
17+
18+
# Session Parameters
19+
trial_number = 10
20+
21+
session_mode = ["Fresh", "Resume", "Evaluate", "Override"]
22+
mode_id = 0
23+
gpu_name = ["/GPU:0", "/GPU:1", None]
24+
gpu_id = 0
25+
26+
create_new_dataset = 1 # 0:No, 1:Yes
27+
28+
# Network Hyperparameters
29+
batch_size = int(3 * 1024)
30+
learning_rate = 0.005
31+
dropout = 0.0
32+
epochs = 150
33+
initial_epoch = 0
34+
window_size = 50
35+
36+
# Network Architecture
37+
model_architecture = [
38+
tf.keras.layers.LSTM(100, return_sequences=True),
39+
tf.keras.layers.LSTM(100, return_sequences=True),
40+
tf.keras.layers.LSTM(100, return_sequences=True),
41+
tf.keras.layers.LSTM(100, return_sequences=False),
42+
tf.keras.layers.Dense(6)
43+
]
44+
45+
n_features = 10
46+
n_labels = 6
47+
48+
# Save the hyperparameters in a dictionary
49+
session_data = {"trial_number" : trial_number,
50+
"session_mode" : session_mode[mode_id],
51+
"gpu_name" : gpu_name[gpu_id],
52+
"learning_rate" : learning_rate,
53+
"window_size" : window_size,
54+
"dropout" : dropout,
55+
"batch_size" : batch_size,
56+
"epochs" : epochs,
57+
"initial_epoch" : initial_epoch,
58+
59+
"n_features" : n_features,
60+
"n_labels" : n_labels,
61+
}
62+
63+
# create folders for the training outputs (weights, plots, loss history)
64+
trial_tree = utils.create_trial_tree(session_data["trial_number"], session_data["session_mode"])
65+
66+
if create_new_dataset:
67+
session_data["dataset_name"] = None
68+
else:
69+
session_data["dataset_name"] = "T022_7logs_F11L10_W100_11Nov2020_1652"
70+
71+
# create windowed datasets from the flight csv files (or retrieve an old one from binary files)
72+
train_ds, val_dataset, train_flights_dict, val_flights_dict, signals_weights = create_dataset(session_data)
73+
74+
# batch and shuffle
75+
train_dataset = train_ds.batch(batch_size).shuffle(buffer_size=1000)
76+
val_dataset = val_dataset.batch(batch_size).shuffle(buffer_size=1000)
77+
78+
# convert signals weights to a tensor to be used by the loss function
79+
signals_weights_tensor = tf.constant(signals_weights, dtype=tf.float32)
80+
81+
# start training
82+
model = training.start_training(session_data, model_architecture, train_dataset, val_dataset, \
83+
signals_weights_tensor, trial_tree)
84+
85+
# for every flight, plot all states (truth vs predictions)
86+
postprocessing.evaluate_all_flights(model, train_flights_dict, val_flights_dict, \
87+
trial_tree["trial_root_folder"], n_extreme_flights=10)
88+
89+
# add the network configuration and performance to the summary csv
90+
postprocessing.summarize_session(trial_tree, model, session_data)

Readme.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Readme
2+
3+
## DeepNav Directory Structure
4+
5+
DeepNav
6+
|_ DeepNav_data : contains all data used for training
7+
|_ ulg_files: log files as downloaded from the database (.ulg)
8+
|_ flight_csvs: for every ulg file, there is a folder containing
9+
multiple csv files, one csv for each message
10+
at least there sould be
11+
-estimator_status
12+
-sensor_combined
13+
-vehicle_air_data
14+
-vehicle_magnetometer
15+
|_ combined_csvs: multiple csvs combined into one csv per flight
16+
|_ untrimmed
17+
|_ original
18+
|_ differenced: deltas using np.diff
19+
|_ flight_names.csv: contains names of all flights
20+
in front of a name you can right the start and
21+
end minutes you wish to keep the data in between
22+
(trim outward) .. you can write "delete" to delete
23+
the flight
24+
|_ trimmed_csvs
25+
|_ original
26+
|_ differenced
27+
|_training
28+
|_validation
29+
|_ deleted_csvs
30+
|_ original
31+
|_ differenced
32+

loss_plotter.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Fri Jun 12 21:48:47 2020
5+
6+
@author: Ahmed Majuid
7+
"""
8+
9+
import pandas as pd
10+
import matplotlib.pyplot as plt
11+
import numpy as np
12+
import os
13+
14+
os.chdir(os.path.dirname(os.path.abspath(__file__)))
15+
16+
# trials you want to plot
17+
trials = [11]
18+
legends = []
19+
20+
for trial in trials:
21+
22+
trial_log_file = os.path.join("DeepNav_results", "trial_" + str(trial).zfill(3), "model_history_log.csv")
23+
# check if there is a log csv file for this trial and read it as a pandas frame
24+
try:
25+
df = pd.read_csv(trial_log_file)
26+
except:
27+
print("didn't find ", trial_log_file)
28+
continue
29+
30+
# extract the training and validation losses vectors from the data frame
31+
df.head()
32+
df = df[["loss", "val_loss"]]
33+
34+
loss = df.loss
35+
val_loss = df.val_loss
36+
37+
# if you want to plot starting from a certain epoch (for zooming purposes)
38+
zoom = 3
39+
40+
epoch = np.linspace(1, len(loss)-1, len(loss)) - zoom
41+
42+
# print total epochs, minimum loss and val_loss along with their epochs
43+
print("trial:", trial, ", epochs:", val_loss.size, end=", ")
44+
print("min_loss:", f'{np.min(loss):.4f}', "at epoch", np.argmin(loss), end=", ")
45+
print("min val_loss:", f'{np.min(val_loss):.4f}', "at epoch", np.argmin(val_loss),)
46+
47+
48+
plt.plot(epoch[zoom:], loss[zoom:])
49+
plt.plot(epoch[zoom:], val_loss[zoom:])
50+
plt.grid(True)
51+
52+
# add this trial labels to the legend
53+
legends.append("trial " + str(trial).zfill(3) + " training loss")
54+
legends.append("trial " + str(trial).zfill(3) + " validation loss")
55+
56+
57+
58+
plt.legend(legends)
59+
plt.xlabel("epochs")
60+
plt.ylabel("Loss (MAE)")
61+
62+
plt.savefig("losses.pdf")
63+
64+
plt.show()

0 commit comments

Comments
 (0)