Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value Error with input #3

Open
sakuralily11 opened this issue Mar 22, 2019 · 7 comments
Open

Value Error with input #3

sakuralily11 opened this issue Mar 22, 2019 · 7 comments

Comments

@sakuralily11
Copy link

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?

@CVxTz
Copy link
Owner

CVxTz commented Mar 22, 2019

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

@sakuralily11
Copy link
Author

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?

@CVxTz
Copy link
Owner

CVxTz commented Mar 22, 2019

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

@sakuralily11
Copy link
Author

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.

@CVxTz
Copy link
Owner

CVxTz commented Mar 22, 2019

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
Copy link
Owner

CVxTz commented Mar 22, 2019

Did this solve your issue ?

@sakuralily11
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants