pyAudioClassification icon indicating copy to clipboard operation
pyAudioClassification copied to clipboard

model.predict dropping 1 label

Open ryanbales opened this issue 6 years ago • 12 comments
trafficstars

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 avatar Jan 03 '19 21:01 ryanbales

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 avatar Jan 03 '19 21:01 ryanbales

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 avatar Jan 03 '19 22:01 ryanbales

Also,

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

ryanbales avatar Jan 03 '19 22:01 ryanbales

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!

micah5 avatar Jan 04 '19 06:01 micah5

@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.

raifofcl avatar Jan 18 '19 13:01 raifofcl

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

lpnaunau avatar Feb 27 '19 14:02 lpnaunau

@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

raifofcl avatar Feb 27 '19 15:02 raifofcl

@raifofcl Thanks !

lpnaunau avatar Mar 01 '19 13:03 lpnaunau

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.

ignvinay avatar Apr 15 '19 11:04 ignvinay

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

lpnaunau avatar Apr 17 '19 15:04 lpnaunau

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

krish983 avatar Aug 19 '19 15:08 krish983

@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

krish983 avatar Aug 20 '19 12:08 krish983