audio_classification icon indicating copy to clipboard operation
audio_classification copied to clipboard

Value Error with input

Open yuriautsumi opened this issue 6 years ago • 7 comments

I am trying to get keras_cnn_mel.py to run but am getting the following error:

ValueError: Error when checking input: expected input_1 to have shape (63, 320, 1) but got array with shape (157, 320, 1)

I’m guessing the time dimension is not matching up for some of the audio files. Did you end up truncating those files or is there some sort of data compression technique I should look into?

yuriautsumi avatar Mar 22 '19 20:03 yuriautsumi

Hello All your audio files should have the same length, so you need to truncate them or pad them. Best

CVxTz avatar Mar 22 '19 20:03 CVxTz

what padding technique do you recommend? or would you be able to share the code you used to produce the results in the medium post?

yuriautsumi avatar Mar 22 '19 20:03 yuriautsumi

Its in the repo : https://github.com/CVxTz/audio_classification/blob/master/code/keras_cnn_mel.py

def load_audio_file(file_path, input_length=input_length): data = librosa.core.load(file_path, sr=16000)[0] #, sr=16000 if len(data)>input_length:

    max_offset = len(data)-input_length
    
    offset = np.random.randint(max_offset)
    
    data = data[offset:(input_length+offset)] # HERE: Truncating
    
    
else:
    if input_length > len(data):
        max_offset = input_length - len(data)

        offset = np.random.randint(max_offset)
    else:
        offset = 0
    
    
    data = np.pad(data, (offset, input_length - len(data) - offset), "constant") ##HERE : Padding
    
    
data = preprocess_audio_mel_T(data)

return data

CVxTz avatar Mar 22 '19 20:03 CVxTz

Hmm, I haven't changed that part though, so the data is being loaded by the load_audio_file code. It seems like the error actually doesn't have to do with the data being input into the model, but potentially the data being output by the first layer (input layer) of the model. Any idea what could be happening? I haven't changed the code except to download the data and put that file in my directory.

yuriautsumi avatar Mar 22 '19 20:03 yuriautsumi

Maybe its a difference in librosa version since I uploaded the code Maybe you can change the input shape from " inp = Input(shape=(63, 320, 1))" to " inp = Input(shape=(157, 320, 1))" in the model definition ?

CVxTz avatar Mar 22 '19 20:03 CVxTz

Did this solve your issue ?

CVxTz avatar Mar 22 '19 21:03 CVxTz

That also did not work, and I am getting the same error message. Could you let me know what versions of each package you used in your working version of the code?

yuriautsumi avatar Mar 23 '19 15:03 yuriautsumi