1""" 2/* Copyright (c) 2023 Amazon 3 Written by Jan Buethe */ 4/* 5 Redistribution and use in source and binary forms, with or without 6 modification, are permitted provided that the following conditions 7 are met: 8 9 - Redistributions of source code must retain the above copyright 10 notice, this list of conditions and the following disclaimer. 11 12 - Redistributions in binary form must reproduce the above copyright 13 notice, this list of conditions and the following disclaimer in the 14 documentation and/or other materials provided with the distribution. 15 16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 20 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27*/ 28""" 29 30from models import multi_rate_lpcnet 31import copy 32 33setup_dict = dict() 34 35dataset_template_v2 = { 36 'version' : 2, 37 'feature_file' : 'features.f32', 38 'signal_file' : 'data.s16', 39 'frame_length' : 160, 40 'feature_frame_length' : 36, 41 'signal_frame_length' : 2, 42 'feature_dtype' : 'float32', 43 'signal_dtype' : 'int16', 44 'feature_frame_layout' : {'cepstrum': [0,18], 'periods': [18, 19], 'pitch_corr': [19, 20], 'lpc': [20, 36]}, 45 'signal_frame_layout' : {'last_signal' : 0, 'signal': 1} # signal, last_signal, error, prediction 46} 47 48dataset_template_v1 = { 49 'version' : 1, 50 'feature_file' : 'features.f32', 51 'signal_file' : 'data.u8', 52 'frame_length' : 160, 53 'feature_frame_length' : 55, 54 'signal_frame_length' : 4, 55 'feature_dtype' : 'float32', 56 'signal_dtype' : 'uint8', 57 'feature_frame_layout' : {'cepstrum': [0,18], 'periods': [36, 37], 'pitch_corr': [37, 38], 'lpc': [39, 55]}, 58 'signal_frame_layout' : {'last_signal' : 0, 'prediction' : 1, 'last_error': 2, 'error': 3} # signal, last_signal, error, prediction 59} 60 61# lpcnet 62 63lpcnet_config = { 64 'frame_size' : 160, 65 'gru_a_units' : 384, 66 'gru_b_units' : 64, 67 'feature_conditioning_dim' : 128, 68 'feature_conv_kernel_size' : 3, 69 'period_levels' : 257, 70 'period_embedding_dim' : 64, 71 'signal_embedding_dim' : 128, 72 'signal_levels' : 256, 73 'feature_dimension' : 19, 74 'output_levels' : 256, 75 'lpc_gamma' : 0.9, 76 'features' : ['cepstrum', 'periods', 'pitch_corr'], 77 'signals' : ['last_signal', 'prediction', 'last_error'], 78 'input_layout' : { 'signals' : {'last_signal' : 0, 'prediction' : 1, 'last_error' : 2}, 79 'features' : {'cepstrum' : [0, 18], 'pitch_corr' : [18, 19]} }, 80 'target' : 'error', 81 'feature_history' : 2, 82 'feature_lookahead' : 2, 83 'sparsification' : { 84 'gru_a' : { 85 'start' : 10000, 86 'stop' : 30000, 87 'interval' : 100, 88 'exponent' : 3, 89 'params' : { 90 'W_hr' : (0.05, [4, 8], True), 91 'W_hz' : (0.05, [4, 8], True), 92 'W_hn' : (0.2, [4, 8], True) 93 }, 94 }, 95 'gru_b' : { 96 'start' : 10000, 97 'stop' : 30000, 98 'interval' : 100, 99 'exponent' : 3, 100 'params' : { 101 'W_ir' : (0.5, [4, 8], False), 102 'W_iz' : (0.5, [4, 8], False), 103 'W_in' : (0.5, [4, 8], False) 104 }, 105 } 106 }, 107 'add_reference_phase' : False, 108 'reference_phase_dim' : 0 109} 110 111 112 113# multi rate 114subconditioning = { 115 'subconditioning_a' : { 116 'number_of_subsamples' : 2, 117 'method' : 'modulative', 118 'signals' : ['last_signal', 'prediction', 'last_error'], 119 'pcm_embedding_size' : 64, 120 'kwargs' : dict() 121 122 }, 123 'subconditioning_b' : { 124 'number_of_subsamples' : 2, 125 'method' : 'modulative', 126 'signals' : ['last_signal', 'prediction', 'last_error'], 127 'pcm_embedding_size' : 64, 128 'kwargs' : dict() 129 } 130} 131 132multi_rate_lpcnet_config = lpcnet_config.copy() 133multi_rate_lpcnet_config['subconditioning'] = subconditioning 134 135training_default = { 136 'batch_size' : 256, 137 'epochs' : 20, 138 'lr' : 1e-3, 139 'lr_decay_factor' : 2.5e-5, 140 'adam_betas' : [0.9, 0.99], 141 'frames_per_sample' : 15 142} 143 144lpcnet_setup = { 145 'dataset' : '/local/datasets/lpcnet_training', 146 'lpcnet' : {'config' : lpcnet_config, 'model': 'lpcnet'}, 147 'training' : training_default 148} 149 150multi_rate_lpcnet_setup = copy.deepcopy(lpcnet_setup) 151multi_rate_lpcnet_setup['lpcnet']['config'] = multi_rate_lpcnet_config 152multi_rate_lpcnet_setup['lpcnet']['model'] = 'multi_rate' 153 154setup_dict = { 155 'lpcnet' : lpcnet_setup, 156 'multi_rate' : multi_rate_lpcnet_setup 157} 158