This repository is the implementation of "BERT-stranger".
- Python 3.8.8
- Ubuntu 20.04.2 LTS
- Read requirements.txt for other Python libraries
You can extract multiple loops from MIDI, which are represented as REMI+ (1 <bar>, 32 <tempo>, 129 <instrument>, 128 <pitch>, 128 <pitch drum>, 48 <position>, 58 <duration>, and 32 <velocity>).
import torch
from time import time
from src.loop import BERTStranger
# initialize model with GPU
use_cuda = torch.cuda.is_available()
device = torch.device("cuda" if use_cuda else "cpu")
# define model
model = BERTStranger(device)
file_path = "./05459b96a64358886fe91ce47a9ac91d.mid"
start_time = time()
results = model.extract_loop(file_path)
print(f"Loop extraction for {time() - start_time:.2f} sec")
TBD. You should put the downloaded model on "./model/".
Sangjun Han, Hyeongrae Ihm, Woohyung Lim (LG AI Research)