예제 #1
0
# pylint: disable=C0303,W1401
import click

from omnizart.cli import silence_tensorflow
from omnizart.cli.common_options import add_common_options, COMMON_TRANSCRIBE_OPTIONS
from omnizart.utils import LazyLoader

drum = LazyLoader("drum", globals(), "omnizart.drum")


@click.command()
@add_common_options(COMMON_TRANSCRIBE_OPTIONS)
def transcribe(input_audio, model_path, output):
    """Transcribe a single audio and output as a MIDI file.

    This will output a MIDI file with the same name as the given audio, except the
    extension will be replaced with '.mid'.

    \b
    Example Usage
    $ omnizart drum transcribe \ 
        example.wav \ 
        --model-path path/to/model \ 
        --output example.mid
    """
    silence_tensorflow()
    drum.app.transcribe(input_audio, model_path, output=output)


def process_doc():
    # Some dirty work for preserving and converting the docstring inside the decorated
예제 #2
0
import click

from omnizart.cli.common_options import add_common_options, COMMON_GEN_FEATURE_OPTIONS
from omnizart.setting_loaders import ChordSettings
from omnizart.utils import LazyLoader

chord = LazyLoader("chord", globals(), "omnizart.chord")


@click.command()
@add_common_options(COMMON_GEN_FEATURE_OPTIONS)
def generate_feature(dataset_path, output_path, num_threads):
    """Extract the feature of the whole dataset for training."""
    settings = ChordSettings()

    if output_path is not None:
        settings.dataset.feature_save_path = output_path

    chord.app.generate_feature(dataset_path,
                               chord_settings=settings,
                               num_threads=num_threads)
예제 #3
0
from functools import partial

import click

from omnizart.cli import silence_tensorflow
from omnizart.cli.common_options import add_common_options, COMMON_TRAIN_MODEL_OPTIONS
from omnizart.setting_loaders import MusicSettings
from omnizart.utils import LazyLoader


music = LazyLoader("music", globals(), "omnizart.music")
click.option = partial(click.option, show_default=True)


@click.command()
@add_common_options(COMMON_TRAIN_MODEL_OPTIONS)
@click.option(
    "-y",
    "--model-type",
    help="Type of the neural network model",
    type=click.Choice(["attn", "aspp"]),
    default="attn",
)
@click.option(
    "-f",
    "--feature-type",
    help="Determine the input feature types for training",
    multiple=True,
    default=["Spec", "Ceps"],
    type=click.Choice(["Spec", "Ceps", "GCoS"]),
)
예제 #4
0
from spleeter.utils.logging import get_logger as sp_get_logger

from omnizart.io import load_audio, write_yaml
from omnizart.utils import get_logger, resolve_dataset_type, parallel_generator, ensure_path_exists, LazyLoader
from omnizart.constants import datasets as d_struct
from omnizart.base import BaseTranscription, BaseDatasetLoader
from omnizart.feature.cfp import extract_vocal_cfp, _extract_vocal_cfp
from omnizart.setting_loaders import VocalSettings
from omnizart.vocal import labels as lextor
from omnizart.vocal.prediction import predict
from omnizart.vocal.inference import infer_interval, infer_midi
from omnizart.train import get_train_val_feat_file_list
from omnizart.models.pyramid_net import PyramidNet

logger = get_logger("Vocal Transcription")
vcapp = LazyLoader("vcapp", globals(), "omnizart.vocal_contour")


class VocalTranscription(BaseTranscription):
    """Application class for vocal note transcription.

    This application implements the training procedure in a semi-supervised way.
    """
    def __init__(self, conf_path=None):
        super().__init__(VocalSettings, conf_path=conf_path)

        # Disable logging information of Spleeter
        sp_logger = sp_get_logger()
        sp_logger.setLevel(40)  # logging.ERROR

    def transcribe(self, input_audio, model_path=None, output="./"):
예제 #5
0
import click

from omnizart.cli import silence_tensorflow
from omnizart.cli.common_options import add_common_options, COMMON_TRAIN_MODEL_OPTIONS
from omnizart.setting_loaders import VocalSettings
from omnizart.utils import LazyLoader

vocal = LazyLoader("vocal", globals(), "omnizart.vocal")


@click.command()
@add_common_options(COMMON_TRAIN_MODEL_OPTIONS)
def train_model(
    feature_path,
    model_name,
    input_model,
    epochs,
    steps,
    val_steps,
    batch_size,
    val_batch_size,
    early_stop,
):
    """Train a new model or continue to train on a pre-trained model"""
    settings = VocalSettings()

    if epochs is not None:
        settings.training.epoch = epochs
    if steps is not None:
        settings.training.steps = steps
    if batch_size is not None:
예제 #6
0
import click

from omnizart.cli.common_options import add_common_options, COMMON_TRAIN_MODEL_OPTIONS
from omnizart.setting_loaders import VocalContourSettings
from omnizart.utils import LazyLoader

vocal_contour = LazyLoader("vocal_contour", globals(),
                           "omnizart.vocal_contour")


@click.command()
@add_common_options(COMMON_TRAIN_MODEL_OPTIONS)
def train_model(feature_path, model_name, input_model, epochs, steps,
                val_steps, batch_size, val_batch_size, early_stop):
    """Train a new model or continue to train on a pre-trained model"""
    settings = VocalContourSettings()
    if epochs is not None:
        settings.training.epoch = epochs
    if steps is not None:
        settings.training.steps = steps
    if val_steps is not None:
        settings.training.val_steps = val_steps
    if batch_size is not None:
        settings.training.batch_size = batch_size
    if val_batch_size is not None:
        settings.training.val_batch_size = val_batch_size
    if early_stop is not None:
        settings.training.early_stop = early_stop

    vocal_contour.app.train(feature_path,
                            model_name=model_name,
예제 #7
0
import click

from omnizart.cli import silence_tensorflow
from omnizart.cli.common_options import add_common_options, COMMON_TRANSCRIBE_OPTIONS
from omnizart.utils import LazyLoader

patch_cnn = LazyLoader("patch_cnn", globals(), "omnizart.patch_cnn")


@click.command()
@add_common_options(COMMON_TRANSCRIBE_OPTIONS)
def transcribe(input_audio, model_path, output):
    """Transcribe a single audio and output CSV and audio file.

    The transcribed F0 contour will be stored in the <filename>_f0.csv file,
    where *filename* is the input file name. Also there will be another rendered
    audio file (with postfix <filename>_trans.wav) of the pitch contour for
    quick validation.

    Supported modes are: Melody
    """
    silence_tensorflow()
    patch_cnn.app.transcribe(input_audio, model_path, output=output)
예제 #8
0
파일: io.py 프로젝트: ykhorzon/omnizart
import os
import csv
import pickle

import yaml
import librosa

from omnizart.utils import ensure_path_exists, LazyLoader, get_logger

# Lazy load the Spleeter pacakge for avoiding pulling large dependencies
# and boosting the import speed.
adapter = LazyLoader("adapter", globals(), "spleeter.audio.adapter")
logger = get_logger("IO")


def dump_pickle(data, save_to):
    """Dump data to the given path.

    Parameters
    ----------
    data: python objects
        Data to store. Should be python built-in types like `dict`, `list`, `str`, `int`, etc
    save_to: Path
        The full path to store the pickle file, including file name.
        Will create the directory if the given path doesn't exist.

    """
    base_dir = os.path.dirname(save_to)
    ensure_path_exists(base_dir)
    with open(save_to, "wb") as pkl_file:
        pickle.dump(data, pkl_file)
예제 #9
0
import click

from omnizart.cli import silence_tensorflow
from omnizart.cli.common_options import add_common_options, COMMON_TRAIN_MODEL_OPTIONS
from omnizart.setting_loaders import BeatSettings
from omnizart.utils import LazyLoader


beat = LazyLoader("beat", globals(), "omnizart.beat")


@click.command()
@add_common_options(COMMON_TRAIN_MODEL_OPTIONS)
def train_model(
    feature_path,
    model_name,
    input_model,
    epochs,
    steps,
    val_steps,
    batch_size,
    val_batch_size,
    early_stop
):
    """Train a new model or continue to train on a pre-trained model"""
    settings = BeatSettings()

    if epochs is not None:
        settings.training.epoch = epochs
    if steps is not None:
        settings.training.steps = steps