本文整理汇总了Python中SR.get_isolated_templates方法的典型用法代码示例。如果您正苦于以下问题:Python SR.get_isolated_templates方法的具体用法?Python SR.get_isolated_templates怎么用?Python SR.get_isolated_templates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SR
的用法示例。
在下文中一共展示了SR.get_isolated_templates方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: train_continuous_model
# 需要导入模块: import SR [as 别名]
# 或者: from SR import get_isolated_templates [as 别名]
def train_continuous_model(input_list, continuous_words, number_of_states_for_each_word=5):
number_of_frames_in_each_state_for_each_template = []
number_of_words = len(continuous_words) + 2 # 2为首尾的silence
number_of_states = number_of_states_for_each_word * (number_of_words)
number_of_frames_in_each_state = [] # 第i个元素代表state i的frame数
template = []
covariance_matrix_in_each_state = []
mean_in_each_state = []
for i in xrange(number_of_words):
if i == 0 or i == number_of_words - 1:
word = 10 # silence
else:
word = int(continuous_words[i - 1])
mfcc_list = SR.get_isolated_templates(word)
model = k_means(mfcc_list)
temp_number_of_frames_in_each_state = [0 for i in xrange(number_of_states_for_each_word)]
for number_of_frames_in_each_state_in_each_template in model[5]:
for i in xrange(number_of_states_for_each_word):
temp_number_of_frames_in_each_state[i] += number_of_frames_in_each_state_in_each_template[i]
number_of_frames_in_each_state.extend(temp_number_of_frames_in_each_state)
template.extend(model[0][0])
covariance_matrix_in_each_state.extend(model[2])
mean_in_each_state.extend(model[3])
for input_feature in input_list:
print len(template), len(input_feature)
last_state_index = [[[0, 0] for i in xrange(len(template))] for j in xrange(len(input_feature))]
cost_matrix = [[float('inf') for i in xrange(len(template))] for j in xrange(len(input_feature))]
cost_matrix[0][0] = get_mahalanobis_distance(covariance_matrix_in_each_state[0],
mean_in_each_state[0], input_feature[0])[1]
for i in xrange(1, len(input_feature)):
for j in xrange(len(template)):
if j == 0:
transform_list = [j]
else:
transform_list = [j - 1, j]
for last_state in transform_list:
edge_cost = (number_of_frames_in_each_state[j] - 10.0) / number_of_frames_in_each_state[
j] if j == last_state else 10.0 / number_of_frames_in_each_state[last_state]
new_cost = cost_matrix[i - 1][last_state] + edge_cost
if cost_matrix[i][j] > new_cost:
min_index = last_state
cost_matrix[i][j] = new_cost
cost_matrix[i][j] += get_mahalanobis_distance(covariance_matrix_in_each_state[j],
mean_in_each_state[j], input_feature[i])[1]
last_state_index[i][j] = [i - 1, min_index]
min_cost = min(
cost_matrix[len(input_feature) - 1][(len(template) - number_of_states_for_each_word):len(template)])
cur_index = cost_matrix[len(input_feature) - 1].index(min_cost)
path = []
i = len(input_feature) - 1
while i >= 0:
path.append(cur_index)
cur_index = last_state_index[i][cur_index][1]
i -= 1
print path
number_of_frames_in_each_state_in_one_template = [0 for i in xrange(number_of_states)]
for state in path:
number_of_frames_in_each_state_in_one_template[state] += 1
number_of_frames_in_each_state_for_each_template.append(number_of_frames_in_each_state_in_one_template)
print number_of_frames_in_each_state_for_each_template
trained_model = train_model(input_list, number_of_states, number_of_frames_in_each_state_for_each_template)
return trained_model