I can not find a specific answer to the question of how to submit data to Keras. Most examples seem to work with images / text data and have clearly defined data points.
I am trying to stream music to the LSTM neural network. I want the network to take ~ 3 seconds of music and assign the next 2 seconds. I have music prepared in .wav files and divided into 5 second intervals, which I laid out on my X (first 3 seconds) and Y (last two seconds). I tried my music at 44,100 Hz, so my X is 132,300 observations "long" and my Y is "88,200" observations.
But I can't figure out exactly how to reduce Keras to my data structure. I use the Tensorflow backing.
In the interest of summarizing the problem and the answer, I will use A, B, C to refer to measurements. The only difference between this example data and my real data is that these are random values distributed from 0 to 1, and my data is an array of integers.
import numpy as np
a = 411
b_train = 132300
b_test = 88200
c = 2
X = np.random.rand(a,b_train,c)
y = np.random.rand(a,b_test ,c)
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.20, random_state=42)
However, I don’t know how to adjust the model to understand that the “first” (A) dimension contains observations and that I want to more or less break the music (B) into channel (C).
I know that it would be easier to convert this to mono (and the 2d problem), but I am very curious to find out if this has a “simple” solution - it mainly depends on what I have below or if I should think about the model differently.
The main question is: how would I build a model that would allow me to convert my X data to my Y data?
, , .
import keras
import math, time
from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation
from keras.layers.recurrent import LSTM
from keras.models import load_model
def build_model(layers):
d = 0.3
model = Sequential()
model.add(LSTM(256, input_shape=(layers), return_sequences=True))
model.add(Dropout(d))
model.add(LSTM(256, input_shape=(layers), return_sequences=False))
model.add(Dropout(d))
model.add(Dense(32,kernel_initializer="uniform",activation='relu'))
model.add(Dense(1,kernel_initializer="uniform",activation='linear'))
start = time.time()
model.compile(loss='mse',optimizer='adam', metrics=['accuracy'])
print("Compilation Time : ", time.time() - start)
return model
model = build_model([328,132300,2])
model.fit(X_train,y_train,batch_size=512,epochs=30,validation_split=0.1,verbose=1)
( model =...):
ValueError: Input 0 is incompatible with layer lstm_2: expected ndim=3, found ndim=4
, Keras ndim = 4 . , , , , "" A, B- C-.
- , . 17 , , /.
!