GenreClassifier<T>

Models & Types · AiDotNet.Audio.Classification

Music genre classification after Tzanetakis and Cook 2002: a 30-dimensional “musical surface” feature vector per recording, classified by one diagonal-covariance Gaussian mixture per genre.

Inheritance: NeuralNetworkBase<T> → AudioNeuralNetworkBase<T> → AudioClassifierBase<T> → GenreClassifier<T>

Implements: IGenreClassifier<T>

For Beginners

Genre classification analyzes audio characteristics:

  • Tempo and rhythm patterns (fast/slow, complex/simple beats)
  • Timbre and instrumentation (acoustic vs electronic sounds)
  • Harmonic content (simple vs complex chords)
  • Spectral features (brightness, warmth, texture)

Usage:

How It Works

The features (section III) are 19 timbral texture features (means and variances over 1 s texture windows of the spectral centroid, rolloff, flux and zero crossings of 23 ms analysis windows, the low-energy fraction, and the first five MFCCs), 6 rhythmic content features from a wavelet beat histogram, and 5 pitch content features from multipitch histograms. Each genre is a Gaussian mixture (three components by default, the paper’s GMM(3)) fitted with EM from a K-means start (section IV). The genres are the paper’s ten.

This class supports both:

  • ONNX mode: Load pre-trained models for fast inference
  • Native training mode: Train from scratch using the layer architecture

Constructors

Constructor Summary
GenreClassifier(GenreClassifierOptions options) Creates a new genre classifier with legacy options only.
GenreClassifier(NeuralNetworkArchitecture<T> architecture, GenreClassifierOptions options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer) Creates a new genre classifier in native training mode.
GenreClassifier(NeuralNetworkArchitecture<T> architecture, string modelPath, GenreClassifierOptions options) Creates a new genre classifier in native training mode.

Properties

Property Summary
IReadOnlyList<string> SupportedGenres { get; } Gets the supported genre labels.
bool IsOnnxMode { get; } Gets whether the model is operating in ONNX inference mode.
bool SupportsMultiLabel { get; } Gets whether this model supports multi-label classification.
int SampleRate { get; } Gets the sample rate.
string[] Genres { get; } Gets the supported genre labels (legacy).

Methods

Method Summary
GenreClassificationResult ClassifyLegacy(Tensor<T> audio) Classifies the genre of an audio clip (legacy API).
GenreClassificationResult<T> Classify(Tensor<T> audio) Classifies the genre of an audio clip.
GenreTrackingResult<T> TrackGenreOverTime(Tensor<T> audio, double segmentDuration) Tracks genre over time within a piece.
IReadOnlyDictionary<string, T> GetGenreProbabilities(Tensor<T> audio) Gets genre probabilities for all supported genres.
IReadOnlyList<GenrePrediction<T>> GetTopGenres(Tensor<T> audio, int k) Gets top-K genre predictions.
List<GenreClassificationResult> ClassifyBatch(IEnumerable<Tensor<T>> audioSegments) Classifies multiple audio segments in batch (legacy API).
ModelMetadata<T> GetModelMetadata() Gets metadata about the model.
Task<GenreClassificationResult<T>> ClassifyAsync(Tensor<T> audio, CancellationToken cancellationToken) Classifies audio asynchronously.
Vector<T> GetParameterGradients()

Fields

Field Summary
string[] StandardGenres Standard music genres.