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

model.predict dropping 1 label #1

Open
ryanbales opened this issue Jan 3, 2019 · 12 comments
Open

model.predict dropping 1 label #1

ryanbales opened this issue Jan 3, 2019 · 12 comments

Comments

@ryanbales
Copy link

I'm training a model using the freesound data from Kaggle: https://www.kaggle.com/c/freesound-audio-tagging/data

I'm training with 41 classes, but am only getting 40 results. I'm following the basic code from Readme.

@ryanbales
Copy link
Author

Note: I'm now passing in 41 classes and am getting 41 results.

model = train(features, labels, num_classes = len(np.unique(labels)), epochs = 500)

@ryanbales
Copy link
Author

ryanbales commented Jan 3, 2019

Ah, I think it's here.
https://github.com/98mprice/pyAudioClassification/blob/master/pyaudioclassification/__init__.py#L30

Doing np.max takes ignores zero and gives you off by one errors.

This would fix it len(np.unique(labels). I can submit a PR if you agree? @98mprice

@ryanbales ryanbales reopened this Jan 3, 2019
@ryanbales
Copy link
Author

Also,

Why are you subtracting by 1 here? https://github.com/98mprice/pyAudioClassification/blob/master/pyaudioclassification/__init__.py#L42

@micah5
Copy link
Owner

micah5 commented Jan 4, 2019

Hi @ryanbales

Good find! I think you're probably right about this being the cause of the off-by-one error.

To be honest, I can't remember exactly why I subtracted 1 there but it may have been because I copied the code from some of my other projects and didn't pay attention when I did so. Unfortunately I'm currently unable to test whether removing that -1 will fix the issue, but please feel free to submit a PR regardless and I'll marge it and deploy the new release to PyPi when I get home.

Thanks!

@ghost
Copy link

ghost commented Jan 18, 2019

@ryanbales Did the fix work?
I have been trying to make it work using your suggestion, but I am getting this error:

ValueError: Error when checking target: expected activation_5 to have shape (2,) but got array with shape (1,)

The error is raised here:

File "test.py", line 36, in
model = train(features, labels, epochs=100, print_summary=True)
File "........\pyaudioclassification_init_.py", line 49, in train
model.fit(x, y, batch_size=64, epochs=epochs, verbose=verbose)

Please let me know if I am doing something wrong over here.

@lpnaunau
Copy link

lpnaunau commented Feb 27, 2019

@raifofcl Did you find any solution for your error ? I got exactly the same.

@ghost
Copy link

ghost commented Feb 27, 2019

@lpnaunau I cant say it to be a solution, but I found a workaround. I put an empty folder in the data folder.
The condition for this to work is the empty folder must be at the first index after the sort.
In order to achieve this, I put the folders in this format:

  1. 100 - Nothing
  2. 101 - Dog
  3. 102 - Cat

@lpnaunau
Copy link

lpnaunau commented Mar 1, 2019

@raifofcl Thanks !

@ignvinay
Copy link

ignvinay commented Apr 15, 2019

I am also getting same errors.
Please guide me , how did you solve this .

model = train(features, labels, epochs=100, print_summary=True)
File "........\pyaudioclassification_init_.py", line 49, in train
model.fit(x, y, batch_size=64, epochs=epochs, verbose=verbose)

Even though i changed in format of
100-nothing
101-cat
102-dog

still i am getting errors.

@lpnaunau
Copy link

@raifofcl I tried your solution but still getting the same issue.
Thanks anyway for your help !

@krish983
Copy link

@ignvinay Is all that folder contains .ogg or .wav files. It supports for those file formats only.

@krish983
Copy link

@ryanbales I am doing like what you suggested and got the error as

File "test.py", line 25, in
print_leaderboard(pred, './data/')
File "C:\Users\karikatla\AppData\Local\Continuum\anaconda3\lib\site-packages\pyaudioclassification_init_.py", line 74, in print_leaderboard
print('%d.' % (count + 1), r[index + 1], str(round(pred[0][index]*100)) + '%', '(index %s)' % index)
IndexError: list index out of range

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

5 participants