私はいくつかのプロジェクトに取り組んでおり、Python でニューラル ネットワークを使用する必要があります。ニューラル ネットワークをトレーニングしようとしていますが、常に FIT() 関数でエラーが発生します。これは私のコードです:
def matrix_to_vector(m):
return m.flatten()
def prepare_for_rnn(tones):
ready_for_rnn = []
for tone in tones:
ready_for_rnn.append(matrix_to_vector(tone))
return ready_for_rnn
def convert_output2(outputs):
return np.eye(len(outputs))
tone = LoadDataSet('samples/ddur.wav')
X_train = []
X_train.append(tone.DataSet)
x_train = prepare_for_rnn(X_train)
tones = ['D']
y_train = convert_output2(tones)
model = Sequential()
model.add(Dense(128, input_dim=1, activation='sigmoid'))
model.add(Dense(1, activation='sigmoid'))
sgd = SGD(lr=0.01, momentum=0.9)
model.compile(loss='mean_squared_error', optimizer=sgd)
y_train = np.array(y_train)
print x_train
print y_train
print y_train.shape
print len(y_train)
model.fit(x_train, y_train, nb_epoch=2000, batch_size=1, verbose=0, shuffle=False, show_accuracy=False)
score = model.evaluate(x_train, y_train, batch_size=16)
入力配列と出力配列のサンプル数が同じではないというエラーが表示されます。
私のコンソール出力:
/usr/bin/python2.7 /home/misel/PycharmProjects/SoftProjekat/main.py
Using Theano backend.
[array([ 0.70347332, 0.72311571, 2.64259667, ..., 0.52694423,
0.21127148, 0.43055696])]
[[ 1.]]
(1, 1)
1
Traceback (most recent call last):
File "/home/misel/PycharmProjects/SoftProjekat/main.py", line 103, in <module>
model.fit(x_train, y_train, nb_epoch=2000, batch_size=1, verbose=0, shuffle=False, show_accuracy=False)
File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 503, in fit
raise Exception('All input arrays and the target array must '
Exception: All input arrays and the target array must have the same number of samples.