PATH_ACOUSTIC_FEAT, PATH_EXP) # =========================================================================== # Config # =========================================================================== stdio(os.path.join(PATH_EXP, 'features_extraction.log')) args = args_parse(descriptions=[ ('recipe', 'the name of function defined in feature_recipes.py', None), ('--debug', 'enable debug or not', None, False) ]) DEBUG = args.debug # =========================================================================== # Create the recipes # =========================================================================== extractor = get_module_from_path(identifier=str(args.recipe), prefix='feature_recipes', path=get_script_path()) assert len(extractor) > 0, \ "Cannot find any recipe with name: '%s' from path: '%s'" % (args.recipe, get_script_path()) recipe = extractor[0](DEBUG) # ====== debugging ====== # if DEBUG: with np.warnings.catch_warnings(): np.warnings.filterwarnings('ignore') for path, name in SAMPLED_WAV_FILE: feat = recipe.transform(path) assert feat['bnf'].shape[0] == feat['mspec'].shape[0] V.plot_multiple_features(feat, title=feat['name']) V.plot_save(os.path.join(PATH_EXP, 'features_%s.pdf' % args.recipe)) exit() # =========================================================================== # Prepare the processor
from utils import (WAV_FILES, SAMPLED_WAV_FILE, PATH_ACOUSTIC_FEAT, PATH_EXP) # =========================================================================== # Config # =========================================================================== stdio(os.path.join(PATH_EXP, 'features_extraction.log')) args = args_parse( descriptions=[('recipe', 'the name of function defined in feature_recipes.py', None), ('--debug', 'enable debug or not', None, False)]) DEBUG = args.debug # =========================================================================== # Create the recipes # =========================================================================== extractor = get_module_from_path(identifier=str(args.recipe), prefix='feature_recipes', path=get_script_path()) assert len(extractor) > 0, \ "Cannot find any recipe with name: '%s' from path: '%s'" % (args.recipe, get_script_path()) recipe = extractor[0](DEBUG) # ====== debugging ====== # if DEBUG: with np.warnings.catch_warnings(): np.warnings.filterwarnings('ignore') for path, name in SAMPLED_WAV_FILE: feat = recipe.transform(path) assert feat['bnf'].shape[0] == feat['mspec'].shape[0] V.plot_multiple_features(feat, title=feat['name']) V.plot_save(os.path.join(PATH_EXP, 'features_%s.pdf' % args.recipe)) exit() # =========================================================================== # Prepare the processor
catch_warnings_ignore) from odin import fuel as F, preprocessing as pp from odin.stats import sampling_iter from helpers import (PATH_ACOUSTIC_FEATURES, EXP_DIR, ALL_FILES, IS_DEBUGGING, FEATURE_RECIPE, FEATURE_NAME, ALL_DATASET, Config, NCPU, validate_features_dataset) # ALL_FILES # Header: # 0 1 2 3 4 5 6 # path, channel, name, spkid, dataset, start_time, end_time # =========================================================================== # Extractor # =========================================================================== recipe = get_module_from_path(identifier=FEATURE_RECIPE, path=get_script_path(), prefix='feature_recipes') if len(recipe) == 0: raise ValueError("Cannot find feature recipe with name: '%s'" % FEATURE_RECIPE) recipe = recipe[0]() # =========================================================================== # Debug mode # =========================================================================== if IS_DEBUGGING: with np.warnings.catch_warnings(): rand = np.random.RandomState(seed=Config.SUPER_SEED) np.warnings.filterwarnings('ignore') # ====== stratify sampling from each dataset ====== # clusters = defaultdict(list) clusters_count = defaultdict(int)
# ====== check the running script to determine the current running states ====== # _script_name = get_script_name() if _script_name in ('speech_augmentation', 'speech_features_extraction'): CURRENT_STATE = SystemStates.EXTRACT_FEATURES _check_feature_extraction_requirement() _check_recipe_name_for_extraction() elif _script_name in ('train_xvec', 'train_ivec', 'train_tvec', 'train_evec', 'analyze', 'analyze_data'): CURRENT_STATE = SystemStates.TRAINING elif _script_name in ('make_score'): CURRENT_STATE = SystemStates.SCORING _check_feature_extraction_requirement() else: raise RuntimeError("Unknown states for current running script: %s/%s" % (get_script_path(), get_script_name())) # some fancy log of current state print(ctext('====================================', 'red')) print(ctext("System state:", 'cyan'), ctext(CURRENT_STATE, 'yellow')) print(ctext('====================================', 'red')) # =========================================================================== # FILE LIST PATH # =========================================================================== # ====== basic directories ====== # EXP_DIR = get_exppath('sre', override=False) # this folder store extracted vectors for training backend and extracting scores VECTORS_DIR = os.path.join(EXP_DIR, 'vectors') if not os.path.exists(VECTORS_DIR): os.mkdir(VECTORS_DIR) # this folder store the results RESULT_DIR = os.path.join(EXP_DIR, 'results')
DATA_DIR) else: DATA_DIR = select_path(os.path.join(DEFAULT_BASE_DIR, 'bio_data'), create_new=True) DOWNLOAD_DIR = select_path(os.path.join(DATA_DIR, 'downloads'), create_new=True) # PATH for saving experiments results if 'SISUA_EXP' in os.environ: EXP_DIR = os.environ['SISUA_EXP'] if not os.path.exists(EXP_DIR): os.mkdir(EXP_DIR) elif os.path.isfile(EXP_DIR): raise RuntimeError("Experiment path at '%s' must be a folder" % EXP_DIR) else: EXP_DIR = select_path(os.path.join(DEFAULT_BASE_DIR, 'bio_exp'), create_new=True) # ====== path for yaml configurations ====== # if 'SISUA_CFG' in os.environ: CONFIG_PATH = os.path.abspath(os.environ['SISUA_CFG']) else: CONFIG_PATH = os.path.abspath( os.path.join(get_script_path(__name__, return_dir=True), '..', '..', 'configs', 'base.yaml')) if not os.path.isfile(CONFIG_PATH): raise RuntimeError("Cannot find configuration .yaml files at: %s" % CONFIG_PATH)
from odin import fuel as F, preprocessing as pp from odin.stats import sampling_iter from helpers import (PATH_ACOUSTIC_FEATURES, EXP_DIR, ALL_FILES, IS_DEBUGGING, FEATURE_RECIPE, FEATURE_NAME, ALL_DATASET, Config, NCPU, validate_features_dataset) # ALL_FILES # Header: # 0 1 2 3 4 5 6 # path, channel, name, spkid, dataset, start_time, end_time # =========================================================================== # Extractor # =========================================================================== recipe = get_module_from_path(identifier=FEATURE_RECIPE, path=get_script_path(), prefix='feature_recipes') if len(recipe) == 0: raise ValueError("Cannot find feature recipe with name: '%s'" % FEATURE_RECIPE) recipe = recipe[0]() # =========================================================================== # Debug mode # =========================================================================== if IS_DEBUGGING: with np.warnings.catch_warnings(): rand = np.random.RandomState(seed=Config.SUPER_SEED) np.warnings.filterwarnings('ignore') # ====== stratify sampling from each dataset ====== # clusters = defaultdict(list) clusters_count = defaultdict(int) samples = []
raise ValueError("'_' can appear in recipe name which is: '%s'" % FEATURE_RECIPE) # ====== check the running script to determine the current running states ====== # _script_name = get_script_name() if _script_name in ('speech_augmentation', 'speech_features_extraction'): CURRENT_STATE = SystemStates.EXTRACT_FEATURES _check_feature_extraction_requirement() _check_recipe_name_for_extraction() elif _script_name in ('train_xvec', 'train_ivec', 'train_tvec', 'train_evec', 'analyze', 'analyze_data'): CURRENT_STATE = SystemStates.TRAINING elif _script_name in ('make_score'): CURRENT_STATE = SystemStates.SCORING _check_feature_extraction_requirement() else: raise RuntimeError("Unknown states for current running script: %s/%s" % (get_script_path(), get_script_name())) # some fancy log of current state print(ctext('====================================', 'red')) print(ctext("System state:", 'cyan'), ctext(CURRENT_STATE, 'yellow')) print(ctext('====================================', 'red')) # =========================================================================== # FILE LIST PATH # =========================================================================== # ====== basic directories ====== # EXP_DIR = get_exppath('sre', override=False) # this folder store extracted vectors for training backend and extracting scores VECTORS_DIR = os.path.join(EXP_DIR, 'vectors') if not os.path.exists(VECTORS_DIR): os.mkdir(VECTORS_DIR) # this folder store the results RESULT_DIR = os.path.join(EXP_DIR, 'results')