← all posts site ↗

music genre classification via mel spectrograms

converted audio files into mel spectrograms — visual representations of sound that look like heatmaps — then trained a cnn to classify genres. the fun part was seeing how different genres actually look different in spectrogram space. metal is chaos across the full frequency range. jazz has structured patterns in the mid-range. classical is smooth gradients with clear harmonic stacks.

the model hit 87% accuracy which sounds impressive until you realize it can't tell the difference between indie rock and alternative half the time. which is fair — neither can i. the real insight was that audio classification is fundamentally a vision problem. once you convert sound to image, all the cnn tricks apply. convolutions love patterns, and music is nothing but patterns.

the mel spectrogram conversion is the key step. raw audio is a 1d waveform — not great for cnn input. mel spectrograms map frequency over time with human-perceptual scaling (mel scale compresses high frequencies where humans are less discriminating). the result looks like a heatmap where x-axis is time, y-axis is frequency, and color intensity is amplitude. feed that into a standard resnet architecture and you get genre classification without any audio-specific engineering.

the failure cases were interesting. acoustic covers of metal songs got classified as folk. electronic remixes of jazz got classified as edm. the model was learning production style more than musical structure. which makes sense — a cnn looking at spectrograms sees timbre and texture, not chord progressions and melody. to get true musical understanding you'd need something that processes the harmonic series directly, not its visual representation.