Tflearn RNN输出始终是恒定的 - tflearn的新产品



目标:

我正在尝试开发一个能够学习一些未知的非线性四轮驱动无人机动力学的NN模型。最终目的是要在我写的遗传算法工具中使用该模型,该工具将调整我的无人机控制系统以实现所需的响应。GA需要一个可以使用的"黑匣子"模型来生成一组输入的无人机行为的预测。

nn设计:

我创建这种模型的想法是利用一个RNN,该RNN需要ESC电机控制器命令值的时间历史记录为输入(4个输入,每个电动机1个(,并吐出相应的欧拉角(3个输出,滚动,滚动,俯仰,偏航(。我有一个自定义飞行控制器设计/写的,使我能够将任何必要的数据记录到SD卡,即电动机输出和欧拉角。

我当前使用的代码尝试和训练此模型失败,如下所示。这也是我第一次使用Tflearn或任何主要的NN编程,因此也将不胜感激。

另外,如果您想自己运行,您需要的一切(假设您已经拥有Tflearn和Tensorflow(,请在我的GitHub储备库中找到

# An attempt to use a Recurrent Neural Network to learn and predict drone dynamics. In this version, the
# network inputs are the four motor commands and the outputs are the roll, pitch, and yaw angles.
from __future__ import division, print_function, absolute_import
import tflearn
from tflearn.layers.normalization import batch_normalization
import numpy as np
import pandas as pd
import math
import matplotlib
matplotlib.use('Agg')   # use('Agg') for saving to file and use('TkAgg') for interactive plot
import matplotlib.pyplot as plt
# Configuration Variables
input_dim = 4
output_dim = 3
steps_of_history = 10
batch_len = 128
epoch_len = 3
rawDataPath = 'DroneData/timeSeriesData.csv'
# Generate the data used in training
timeSeries = pd.read_csv(rawDataPath)
x = [timeSeries['m1CMD'], timeSeries['m2CMD'], timeSeries['m3CMD'], timeSeries['m4CMD']]
y = [timeSeries['pitch'], timeSeries['roll'], timeSeries['yaw']]
# Convert row vectors into column vectors
x = np.array(x);     y = np.array(y)
x = np.transpose(x); y = np.transpose(y)
# Generate the input and target training data
input_seq = []
output_seq = []
for i in range(0, len(timeSeries['rtosTick']) - steps_of_history):
    input_seq.append(x[i:i+steps_of_history, :])    # Time history input
    output_seq.append(y[i+steps_of_history, :])     # Single output resulting from ^^^

trainX = np.reshape(input_seq, [-1, input_dim, steps_of_history])
trainY = np.reshape(output_seq, [-1, output_dim])

# Build the network model
input_layer = tflearn.input_data(shape=[None, input_dim, steps_of_history])
layer1 = tflearn.simple_rnn(input_layer, n_units=10, activation='softmax', return_seq=True, name='Layer1')
layer2 = tflearn.simple_rnn(layer1, n_units=10, activation='sigmoid', name='Layer2')
layer3 = tflearn.fully_connected(layer2, output_dim, activation='linear', name='Layer3')
output_layer = tflearn.regression(layer3, optimizer='adam', loss='mean_square', learning_rate=0.1)

# Training
model = tflearn.DNN(output_layer, clip_gradients=0.3, tensorboard_verbose=0)
model.fit(trainX, trainY, n_epoch=epoch_len, validation_set=0.1, batch_size=batch_len)

# Generate a model prediction as a very simple sanity check...
predictY = model.predict(trainX)

# Plot the results
plt.figure(figsize=(20, 4))
plt.suptitle('Pitch Predictions')
plt.plot(trainY[:, 0], 'r-', label='Actual')
plt.plot(predictY[:, 0], 'g-', label='Predicted')
plt.legend()
plt.savefig('pitch.png')
plt.figure(figsize=(20, 4))
plt.suptitle('Roll Predictions')
plt.plot(trainY[:, 1], 'r-', label='Actual')
plt.plot(predictY[:, 1], 'g-', label='Predicted')
plt.legend()
plt.savefig('roll.png')
plt.figure(figsize=(20, 4))
plt.suptitle('Yaw Predictions')
plt.plot(trainY[:, 2], 'r-', label='Actual')
plt.plot(predictY[:, 2], 'g-', label='Predicted')
plt.legend()
plt.savefig('yaw.png')

问题:

如果您查看我链接repo的根文件夹中的" pitch.png"," roll.png"," yaw.png"图,您会发现我的网络的预测值是一个常数值。我针对7410个样本的简单飞行日志数据集进行了训练,其中包括俯仰滚动和偏航的不错变化(/- 20 gE(。在此处查看原始数据。我知道这对于最终模型来说可能还不够好,但这是从。

开始的东西。

我觉得我至少应该在输出方面有所变化,即使它不合适。有人可以帮我指出这个问题吗?我自己没有取得任何进步。

我最终解决了问题。事实证明,nn 不喜欢被馈送在1000 范围内的输入数据。ESC数据被记录为PWM命令在我们身上花费的时间,因此NN从1060-1860中获得的值。

通过预处理MATLAB中的数据将其扩展到0.0-5.0范围内,系统表现良好,并且能够学习动力学,而没有太多麻烦。

如果遇到此帖子的任何人都喜欢使用它,我将不断更新GitHub链接上的代码。

最新更新