我正在使用来自this网站的神经网络进行Myo Armband手势的动态分类(神经网络是在我自己的数据集上训练的)。现在我已经删除了因问题而使用Myo的所有东西:这个程序为我用于测试的数据集中的每一行返回相同的类标签。怎么能修好?另外,有没有办法实际进行动态分类(Myo发送8个数字的向量)(我怀疑因为minmax需要数据集是二维的)?
以下是代码:
from math import exp
# Calculate neuron activation for an input
def activate(weights, inputs):
activation = weights[-1]
for i in range(len(weights)-1):
activation += weights[i] * inputs[i]
return activation
# Transfer neuron activation
def transfer(activation):
return 1.0 / (1.0 + exp(-activation))
# Forward propagate input to a network output
def forward_propagate(network, row):
inputs = row
for layer in network:
new_inputs = []
for neuron in layer:
activation = activate(neuron['weights'], inputs)
neuron['output'] = transfer(activation)
new_inputs.append(neuron['output'])
inputs = new_inputs
return inputs
# Make a prediction with a network
def predict(network, row):
outputs = forward_propagate(network, row)
return outputs.index(max(outputs))
def dataset_minmax(dataset):
stats = [[min(column), max(column)] for column in zip(*dataset)]
return stats
# Rescale dataset columns to the range 0-1
def normalize_dataset(dataset, minmax):
for row in dataset:
for i in range(len(row) - 1):
row[i] = (row[i] - minmax[i][0]) / (minmax[i][1] - minmax[i][0])
def make_predictions():
dataset = [[29,46,107,324,56,44,121,35,1],
[29,46,109,327,51,37,123,38,1],
[28,42,107,309,55,32,124,38,1],
[40,112,287,59,35,121,36,1],
[27,43,129,306,75,41,107,38,1],
[28,38,127,289,79,40,109,37,1],
[29,37,126,292,77,35,100,34,1],
[30,40,87,48,77,51,272,80,2],
[26,37,88,47,84,44,250,80,2],
[29,39,91,47,84,46,247,79,2],
[28,38,85,45,80,47,249,78,2],
[28,36,81,43,76,50,337,83,2],
[28,34,75,41,83,52,344,81,2],
[30,38,80,46,71,53,347,92,2],
[28,35,72,45,64,47,360,101,2]]
network = [[{'weights': [0.09640510259345969, 0.37923370996257266, 0.5476265202749506, 0.9144446394025773, 0.837692750149296, 0.5343300438262426, 0.7679511829130964, 0.5325204151469501, 0.06532276962299033]}],
[{'weights': [0.040400453542770665, 0.13301701225112483]}, {'weights': [0.1665525504275246, 0.5382087395561351]}, {'weights': [0.26800994395551214, 0.3322334781304659]}]]
minmax = dataset_minmax(dataset)
normalize_dataset(dataset, minmax)
for row in dataset:
prediction = predict(network, row)
print('Expected=%d, Got=%d' % (row[-1], prediction))
if __name__ == '__main__':
make_predictions()
答案 0 :(得分:0)
解决了问题,实际上是使用了不正确的训练模型。