Hi I must implement a cnn, I'm new with Keras and Tensorflow so I'm apologizing if I'm making a mistake.
This is what I do:
the dataset is an numpy array (23, 4800000), #number of audio tracks x #number of samples.
So I splitted the dataset in train (10, 4800000), validation (7, 4800000) and test (6, 4800000)
The convolution process along the columns, so I must reshape the input in:
X = np.expand_dims(train, axis=2)
Y = np.expand_dims(valid, axis=2)
The code for first part cnn is:
cnn = Sequential()
cnn.add(Conv1D(40, 80, input_shape=(4800000, 10)))
cnn.add(MaxPooling1D(pool_size=2))
cnn.add(Conv1D(40, 8000))
cnn.add(MaxPooling1D(pool_size=20))
cnn.add(Flatten())
cnn.summary()
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv1d_1 (Conv1D) (None, 4799921, 40) 32040
_________________________________________________________________
max_pooling1d_1 (MaxPooling1 (None, 2399960, 40) 0
_________________________________________________________________
conv1d_2 (Conv1D) (None, 2391961, 40) 12800040
_________________________________________________________________
max_pooling1d_2 (MaxPooling1 (None, 119598, 40) 0
_________________________________________________________________
flatten_1 (Flatten) (None, 4783920) 0
=================================================================
Total params: 12,832,080
Trainable params: 12,832,080
Non-trainable params: 0
_______________________________
cnn.compile(loss='mean_squared_error', optimizer='adam')
cnn.fit(X,Y)
And the error is:
ValueError: Error when checking input: expected conv1d_3_input to have shape (None, 4800000, 10) but got array with shape (4800000, 10, 1)
I don't really understand what it means, please someone could help me?
So during these days I tried to simplify my work.
X_train, X_valid = (7,7500,1), 7 number of tracks, 7500 samples and 1 channel
y_train, y_valid = (7,7500), for each one of 7 tracks correspond a value of probability in any sample.
model = Sequential()
model.add(Conv1D(40, 80, activation='relu', input_shape=(7500,1)))
model.add(MaxPooling1D(pool_size=2))
model.add(Dropout(0.5))
model.add(Conv1D(40, 800 ,activation='relu'))
model.add(MaxPooling1D(pool_size=20))
model.add(Dropout(0.5))
model.compile(loss='mean_squared_error',
optimizer='sgd',
metrics=['accuracy'])
model.summary()
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv1d_112 (Conv1D) (None, 7421, 40) 3240
_________________________________________________________________
max_pooling1d_93 (MaxPooling (None, 3710, 40) 0
_________________________________________________________________
dense_6 (Dense) (None, 3710, 40) 1640
_________________________________________________________________
dropout_81 (Dropout) (None, 3710, 40) 0
_________________________________________________________________
conv1d_113 (Conv1D) (None, 2911, 40) 1280040
_________________________________________________________________
max_pooling1d_94 (MaxPooling (None, 145, 40) 0
_________________________________________________________________
dropout_82 (Dropout) (None, 145, 40) 0
=================================================================
Total params: 1,284,920
Trainable params: 1,284,920
Non-trainable params: 0
model.fit(X_train, y_train, batch_size=50, epochs=1, validation_data=(X_valid, y_valid))
ValueError: Error when checking target: expected dropout_82 to have 3 dimensions, but got array with shape (7, 7500)
I think It concern at y_train and y_valid, but if I expand the dimension the error change with this
ValueError: Error when checking target: expected dropout_86 to have shape (None, 145, 40) but got array with shape (7, 7500, 1)