Train the BeatNet CRNN model
mainThe training pipeline consists of three steps: data preparation, training, and evaluation.
1. Prepare Data
Organize your dataset with .beats annotations (format: <time_in_seconds> <beat_number>, where beat_number == 1 is a downbeat). Use the prepare_data module to extract features.
2. Train
Run the training script using a configuration file. You can override parameters like learning_rate, batch_size, and device via CLI.
3. Use Trained Weights
Exported weights (best_model_weights.pt) can be loaded directly into the BeatNet inference class using model.load_state_dict().
# Step 1: Prepare Data
python -m BeatNet.prepare_data --config src/BeatNet/configs/default.yaml \
--raw_dir /path/to/raw_datasets \
--dataset BALLROOM GTZAN BEATLES CMR ROCK_CORPUS
# Step 2: Train
python -m BeatNet.train --config src/BeatNet/configs/default.yaml \
learning_rate=0.001 batch_size=128 device=cuda
# Step 3: Load weights in Python
import torch
from BeatNet.BeatNet import BeatNet
estimator = BeatNet(1, mode='online', inference_model='PF', plot=[])
estimator.model.load_state_dict(
torch.load('output/best_model_weights.pt', map_location='cpu'), strict=False
)
output = estimator.process("audio_file.wav")