### Install melband-roformer-infer Package Source: https://github.com/openmirlab/melband-roformer-infer/blob/main/notebooks/quickstart_colab.ipynb Installs the melband-roformer-infer package from its GitHub repository. This is the initial setup step for using the library. ```python # Install melband-roformer-infer package !pip install -q git+https://github.com/openmirlab/melband-roformer-infer.git # TODO: After publishing to PyPI, use: # !pip install -q melband-roformer-infer ``` -------------------------------- ### Install melband-roformer-infer with UV Source: https://github.com/openmirlab/melband-roformer-infer/blob/main/README.md Install the library using UV, which is recommended for faster and more efficient package management. ```bash uv pip install melband-roformer-infer ``` -------------------------------- ### Install melband-roformer-infer with Pip Source: https://github.com/openmirlab/melband-roformer-infer/blob/main/README.md Install the library using pip. This is a standard method for Python package installation. ```bash pip install melband-roformer-infer ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://github.com/openmirlab/melband-roformer-infer/blob/main/README.md Clone the MelBand-Roformer-Infer repository and install development dependencies using either UV or pip. ```bash # Clone repository git clone https://github.com/openmirlab/melband-roformer-infer.git cd melband-roformer-infer # Install with UV uv sync # Install with pip pip install -e ".[dev]" ``` -------------------------------- ### Verify Installation and Environment Source: https://github.com/openmirlab/melband-roformer-infer/blob/main/notebooks/quickstart_colab.ipynb Checks if the PyTorch installation is successful and if CUDA is available for GPU acceleration. It prints the PyTorch version and details about the CUDA device if found. ```python # Verify installation import torch print(f"PyTorch version: {torch.__version__}") print(f"CUDA available: {torch.cuda.is_available()}") if torch.cuda.is_available(): print(f"CUDA device: {torch.cuda.get_device_name(0)}") ``` -------------------------------- ### Get Default Model Name Source: https://github.com/openmirlab/melband-roformer-infer/blob/main/README.md Retrieves the name of the recommended default model for vocal separation. ```python from mel_band_roformer import DEFAULT_MODEL print(DEFAULT_MODEL) # "melband-roformer-kim-vocals" ``` -------------------------------- ### Copy Configuration File Source: https://github.com/openmirlab/melband-roformer-infer/blob/main/notebooks/quickstart_colab.ipynb Copies the configuration file for vocal separation from the installed melband-roformer package to the model directory. This ensures the model uses the correct settings. ```python # Copy bundled config from the installed package import shutil from mel_band_roformer import __file__ as pkg_file from pathlib import Path pkg_dir = Path(pkg_file).parent config_src = pkg_dir / "configs" / "config_vocals_mel_band_roformer.yaml" config_dst = Path("models/melband-roformer-kim/config.yaml") shutil.copy(config_src, config_dst) print("Model and config ready!") !ls -lh models/melband-roformer-kim/ ``` -------------------------------- ### List Available Models Source: https://github.com/openmirlab/melband-roformer-infer/blob/main/README.md Use this command to see all the models that can be downloaded for use with the library. ```bash melband-roformer-download --list-models ``` -------------------------------- ### Create Directories for Model and Data Source: https://github.com/openmirlab/melband-roformer-infer/blob/main/notebooks/quickstart_colab.ipynb Creates necessary directories to store the downloaded model, input songs, and output results. This prepares the file system for subsequent steps. ```bash # Create directories !mkdir -p models/melband-roformer-kim !mkdir -p input_songs !mkdir -p outputs ``` -------------------------------- ### Check Input Files Source: https://github.com/openmirlab/melband-roformer-infer/blob/main/notebooks/quickstart_colab.ipynb Run this command to list the files in the 'input_songs' directory and verify that your audio file has been uploaded or downloaded correctly. ```bash # Check input files !ls -lh input_songs/ ``` -------------------------------- ### Download All Models Source: https://github.com/openmirlab/melband-roformer-infer/blob/main/README.md Download all available models and specify a directory where they should be stored. ```bash melband-roformer-download --all --output-dir ./models ``` -------------------------------- ### Use Sample Audio File Source: https://github.com/openmirlab/melband-roformer-infer/blob/main/notebooks/quickstart_colab.ipynb This snippet allows you to download a sample audio file from a URL and save it to the 'input_songs' directory. Uncomment the line and replace 'YOUR_AUDIO_URL_HERE' with the actual URL. ```python # Option 2: Use a sample audio (uncomment to use) # !wget -q -O input_songs/sample.wav "YOUR_AUDIO_URL_HERE" ``` -------------------------------- ### Download Recommended Model Source: https://github.com/openmirlab/melband-roformer-infer/blob/main/README.md Download the default recommended model, MelBand Roformer Kim, which is suitable for vocal processing. ```bash melband-roformer-download --model melband-roformer-kim-vocals ``` -------------------------------- ### Download Models by Category Source: https://github.com/openmirlab/melband-roformer-infer/blob/main/README.md Download models belonging to a specific category, such as 'karaoke', and specify an output directory. ```bash melband-roformer-download --category karaoke --output-dir ./models ``` -------------------------------- ### Python API: Load Default Model and Config Source: https://github.com/openmirlab/melband-roformer-infer/blob/main/README.md Load the default recommended model (MelBand Roformer Kim) and its configuration using the Python API. This involves loading YAML configuration and initializing the model. ```python from pathlib import Path from ml_collections import ConfigDict import torch import yaml from mel_band_roformer import MODEL_REGISTRY, DEFAULT_MODEL, get_model_from_config # Use the default recommended model (MelBand Roformer Kim) entry = MODEL_REGISTRY.get(DEFAULT_MODEL) # Load config and model config = ConfigDict(yaml.safe_load(open(f"models/{entry.slug}/{entry.config}"))) model = get_model_from_config("mel_band_roformer", config) model.load_state_dict(torch.load(f"models/{entry.slug}/{entry.checkpoint}", map_location="cpu")) ``` -------------------------------- ### Download Output Files Source: https://github.com/openmirlab/melband-roformer-infer/blob/main/notebooks/quickstart_colab.ipynb Zips the contents of the outputs directory and initiates a download of the zip file. ```python # Download all output files as a zip !zip -r outputs.zip outputs/ from google.colab import files files.download("outputs.zip") ``` -------------------------------- ### Check Output Files Source: https://github.com/openmirlab/melband-roformer-infer/blob/main/notebooks/quickstart_colab.ipynb Lists the files in the outputs directory to verify generation. ```python # Check output files !ls -lh outputs/ ``` -------------------------------- ### CLI Inference with Recommended Model Source: https://github.com/openmirlab/melband-roformer-infer/blob/main/README.md Perform inference using the command-line interface with the recommended MelBand Roformer Kim model. This command processes WAV files in the input folder and generates vocal and instrumental stems. ```bash melband-roformer-infer \ --config_path models/melband-roformer-kim-vocals/config_vocals_mel_band_roformer.yaml \ --model_path models/melband-roformer-kim-vocals/MelBandRoformer.ckpt \ --input_folder ./songs \ --store_dir ./outputs ``` -------------------------------- ### Interact with Model Registry Source: https://github.com/openmirlab/melband-roformer-infer/blob/main/README.md Demonstrates how to use the MODEL_REGISTRY to list categories, models by category, search for models, and display all models in a table format. ```python from mel_band_roformer import MODEL_REGISTRY # List all categories print(MODEL_REGISTRY.categories()) # List models by category for model in MODEL_REGISTRY.list("vocals"): print(model.name, model.checkpoint) # Search models results = MODEL_REGISTRY.search("karaoke") for m in results: print(m.slug) # Pretty-print all models print(MODEL_REGISTRY.as_table()) ``` -------------------------------- ### Listen to Audio Results Source: https://github.com/openmirlab/melband-roformer-infer/blob/main/notebooks/quickstart_colab.ipynb Finds and plays all generated WAV audio files in the outputs directory using IPython.Audio. ```python import IPython.display as ipd from pathlib import Path output_dir = Path("outputs") # Find and display all output files for audio_file in sorted(output_dir.glob("*.wav")): print(f"\n{'='*50}") print(f"File: {audio_file.name}") print(f"{ '='*50}") display(ipd.Audio(str(audio_file))) ``` -------------------------------- ### Download Pre-trained Model Checkpoint Source: https://github.com/openmirlab/melband-roformer-infer/blob/main/notebooks/quickstart_colab.ipynb Downloads the MelBand Roformer Kim model checkpoint from Hugging Face. This model is specifically recommended for vocal separation tasks. ```bash # Download model checkpoint from Hugging Face !wget -q -O models/melband-roformer-kim/MelBandRoformer.ckpt \ "https://huggingface.co/KimberleyJSN/melbandroformer/resolve/main/MelBandRoformer.ckpt" ``` -------------------------------- ### Upload Audio File from Computer Source: https://github.com/openmirlab/melband-roformer-infer/blob/main/notebooks/quickstart_colab.ipynb Use this snippet to upload a .wav audio file from your local computer to the Colab environment. The uploaded file is then moved to the 'input_songs' directory. ```python # Option 1: Upload from your computer from google.colab import files print("Upload your audio file (.wav format):") uploaded = files.upload() # Move uploaded file to input folder for filename in uploaded.keys(): !mv "{filename}" input_songs/ print(f"Moved {filename} to input_songs/") ``` -------------------------------- ### Run Source Separation using Python API Source: https://github.com/openmirlab/melband-roformer-infer/blob/main/notebooks/quickstart_colab.ipynb This snippet demonstrates how to perform source separation using the Python API. It includes loading the model, processing audio files, and saving the separated stems (vocals and instrumental). ```python #@title Run Source Separation { display-mode: "form" } #@markdown Click the play button to run separation with your selected method. if inference_method == "CLI (Command Line)": # ============================================ # Option A: CLI (Command Line) # ============================================ print("Running with CLI...\n") !melband-roformer-infer \ --config_path models/melband-roformer-kim/config.yaml \ --model_path models/melband-roformer-kim/MelBandRoformer.ckpt \ --input_folder ./input_songs \ --store_dir ./outputs else: # ============================================ # Option B: Python API # ============================================ print("Running with Python API...\n") import torch import yaml import soundfile as sf import numpy as np from pathlib import Path from ml_collections import ConfigDict from mel_band_roformer.utils import get_model_from_config, demix_track # Load model print("Loading model...") with open("models/melband-roformer-kim/config.yaml") as f: config = ConfigDict(yaml.safe_load(f)) model = get_model_from_config("mel_band_roformer", config) model.load_state_dict( torch.load("models/melband-roformer-kim/MelBandRoformer.ckpt", map_location="cpu") ) device = torch.device("cuda" if torch.cuda.is_available() else "cpu") model = model.to(device) model.eval() print(f"Model loaded on {device}\n") # Process files input_folder = Path("input_songs") output_folder = Path("outputs") output_folder.mkdir(exist_ok=True) for audio_path in input_folder.glob("*.wav"): print(f"Processing: {audio_path.name}") # Load audio mix, sr = sf.read(audio_path) original_mono = len(mix.shape) == 1 if original_mono: mix = np.stack([mix, mix], axis=-1) # Convert to tensor mixture = torch.tensor(mix.T, dtype=torch.float32) # Run separation with torch.no_grad(): result, _ = demix_track(config, model, mixture, device) # Save vocals stem_name = audio_path.stem for instrument, audio in result.items(): output = audio.T if original_mono: output = output[:, 0] output_path = output_folder / f"{stem_name}_{instrument}.wav" sf.write(output_path, output, sr, subtype="FLOAT") print(f" Saved: {output_path}") # Save instrumental (original - vocals) vocals = result.get("vocals", list(result.values())[0]).T if original_mono: vocals = vocals[:, 0] mix = mix[:, 0] instrumental = mix - vocals instrumental_path = output_folder / f"{stem_name}_instrumental.wav" sf.write(instrumental_path, instrumental, sr, subtype="FLOAT") print(f" Saved: {instrumental_path}") print("\nDone!") ``` -------------------------------- ### Select Inference Method Source: https://github.com/openmirlab/melband-roformer-infer/blob/main/notebooks/quickstart_colab.ipynb Choose between 'CLI (Command Line)' and 'Python API' for running the source separation. The selected method is stored in the 'inference_method' variable. ```python #@title Select Inference Method { display-mode: "form" } #@markdown Choose which method to use for audio separation: inference_method = "CLI (Command Line)" #@param ["CLI (Command Line)", "Python API"] print(f"Selected method: {inference_method}") ``` -------------------------------- ### Run Source Separation using CLI Source: https://github.com/openmirlab/melband-roformer-infer/blob/main/notebooks/quickstart_colab.ipynb Execute this command to perform source separation using the Command Line Interface. Ensure the config, model, and input paths are correctly specified. ```bash #@title Run Source Separation { display-mode: "form" } #@markdown Click the play button to run separation with your selected method. if inference_method == "CLI (Command Line)": # ============================================ # Option A: CLI (Command Line) # ============================================ print("Running with CLI...\n") !melband-roformer-infer \ --config_path models/melband-roformer-kim/config.yaml \ --model_path models/melband-roformer-kim/MelBandRoformer.ckpt \ --input_folder ./input_songs \ --store_dir ./outputs ``` -------------------------------- ### Citation for MelBand-RoFormer-Infer Source: https://github.com/openmirlab/melband-roformer-infer/blob/main/README.md BibTeX entry for citing the 'Music Source Separation with Band-Split RoPE Transformer' paper when using MelBand-RoFormer-Infer in research. ```bibtex @inproceedings{Lu2023MusicSS, title = {Music Source Separation with Band-Split RoPE Transformer}, author = {Wei-Tsung Lu and Ju-Chiang Wang and Qiuqiang Kong and Yun-Ning Hung}, year = {2023}, url = {https://api.semanticscholar.org/CorpusID:261556702} } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.