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

15.1 Song Classification -- IndexError: list index out of range #68

Open
mikechen66 opened this issue May 2, 2020 · 3 comments
Open

Comments

@mikechen66
Copy link

Hi Douwe:

I tried the song classification. It has the list index out of range error. Please indicate how how to solve the issue.

IndexError Traceback (most recent call last)
in
17
18 song_specs, genres, genre_to_idx, idx_to_genre = load_songs('/home/mike/Documents/datasets/genres')
---> 19 song_specs[0].shape

IndexError: list index out of range

Best regards,

Mike

@DOsinga
Copy link
Owner

DOsinga commented May 2, 2020

Hi Mike,

It looks like load_songs didn't return anything, which from the source code seems to happen when it can't find any songs. See if the list_dir above does anything or perhaps it is pointing to the wrong place.

Douwe

@mikechen66
Copy link
Author

mikechen66 commented May 9, 2020

Hi Douwe:

I see that the path is too value to be understood. So it is shows the error

IndexError: list index out of range

I see that song_folder is a path but not be expressed in 15.1. Can you make an explicit example in the original code of lines. If the 15.1 Song Classification is to be solved, 15.2 to 15.4 will be easy to be solved.

def load_songs(song_folder):
    song_specs = []
    idx_to_genre = []
    genre_to_idx = {}
    genres = []
    for genre in os.listdir(song_folder):
        genre_to_idx[genre] = len(genre_to_idx)
        idx_to_genre.append(genre)
        genre_folder = os.path.join(song_folder, genre)
        for song in os.listdir(genre_folder):
            if song.endswith('.au'):
                signal, sr = librosa.load(os.path.join(genre_folder, song))
                melspec = librosa.feature.melspectrogram(signal, sr=sr).T[:1280,]
                song_specs.append(melspec)
                genres.append(genre_to_idx[genre])
    return song_specs, genres, genre_to_idx, idx_to_genre

song_specs, genres, genre_to_idx, idx_to_genre = load_songs('/home/mike/Documents/datasets/genres')
song_specs[0].shape

Thanks in advance,

Mike

@mikechen66
Copy link
Author

The song classification example is interesting. But the question is the IndexError: list index out of range. I tried many methods and could not correct the issue.

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