Training deep neural networks

@cesans


In [1]:
import matplotlib.pyplot as plt
%matplotlib inline

In [2]:
import sys
sys.path.append('..')
import numpy as np

import deep_control as dc


Couldn't import dot_parser, loading of dot files will not be possible.

Loading data

Previously generated trajectories can be loaded with dc.data.load_trajectories


In [3]:
# The time column is automatically discarded
# For free landing we drop the 'x' column 

col_names = ['t', 'm', #'x',
                             'vx', 'z', 'vz', 'theta', 'vtheta', 'T', 'Tl', 'Tr']

cols = [0,1, #2,
                 3,4,5,6,7,8,9,10]

In [4]:
trajs = dc.data.load_trajectories('data/main_thrusters/', col_names=col_names, cols=cols)


Loading trajectories: 100%|██████████| 100/100 [00:00<00:00, 402.29it/s]

Training

From the trajectories we can generate the training sets:


In [5]:
train_p = 0.9 # proportion of training data
x_train, y_train, x_test, y_test, idx_train = dc.data.create_training_data(trajs, train_p = train_p, n_outputs=3)


Creating training data: 100%|██████████| 90/90 [00:00<00:00, 1774.48it/s]
Creating test data: 100%|██████████| 10/10 [00:00<00:00, 1677.25it/s]

In [6]:
dc.nn.save_training_data([x_train, y_train, x_test, y_test, idx_train], "mass_thrusters")

We specify a model to train


In [7]:
model_description = {"data": "mass_thrusters",
                     "control": dc.nn.THRUST,
                     "nlayers": 3,
                     "units": 128, 
                     "output_mode": dc.nn.OUTPUT_LOG, 
                     "dropout": False,
                     "batch_size": 8, 
                     "epochs": 32, 
                     "lr": 0.001,
                     "input_vars" : 6,
                     "hidden_nonlinearity": "ReLu"}

In [9]:
dc.nn.train(model_description)


=====  MODEL ===========
control:0
input_vars:6
output_mode:0
dropout:False
batch_size:8
epochs:32
data:mass_thrusters
hidden_nonlinearity:ReLu
nlayers:3
lr:0.001
units:1104
========================
Loading data...
=======================
Preprocessing...
=======================
Training, epoch 0: 100%|██████████| 1338/1338 [01:21<00:00, 16.32it/s]
Training...
epoch 0, train loss: 0.139448388079
epoch 0, test loss: 0.117317342076
Training, epoch 1:  12%|█▏        | 161/1338 [00:09<01:06, 17.58it/s]
Training stopped