1

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)
shawk
  • 81
  • 8
  • 1
    The `input_shape` doesn't include the batch size: https://stackoverflow.com/a/48141688/712995 – Maxim Jan 08 '18 at 08:31
  • if you have an input shape of `(4800000, 10)` you will build a network which classifies/regresses 10 audio samples at a time -- is this what you want ? – Andre Holzner Jan 08 '18 at 08:34
  • Yes, I need to do convolution and pooling along the sample-series (4800000) for each track (10). – shawk Jan 08 '18 at 15:15
  • No sorry, I need to do convolution and pooling along the sample-series (4800000) for each track (10). I'm getting confused sorry – shawk Jan 08 '18 at 15:37

1 Answers1

0

Just as the error message puts, the shapes of your input data do not match the expected, because you have expanded the wrong dimension.

In this case, the shape of your original training data is (23, 4800000), and becomes (23, 4800000, 1) after expanding dimensions with

X = np.expand_dims(train, axis=2)

but the expected shape of input data is (None, 4800000, 10), None here means vairable-length.

What you should do is just reshaping data with

X = np.expand_dims(train, axis=0)
Dectinc
  • 69
  • 5
  • Sorry I missed one operation, I've done the transpose of train and then I expanded the dimension of the train-set. train.shape = 10,4800000) train = train.T train.shape(4800000,10) X = np.expand_dims(train, axis=2) X.shape = (4800000, 10, 1) So you mean extending the dimension to have (1, 4800000, 10)? – shawk Jan 08 '18 at 15:28