def _targets_to_annotations(self, targets):
natural = zip([0, 2, 3, 5, 7, 8, 10], string.uppercase[:7])
sharp = map(lambda v: ((v[0] + 1) % 12, v[1] + '#'), natural)
semitone_to_label = dict(sharp + natural + [(12, 'N')])
spf = 1. / self.fps
labels = [(i * spf, semitone_to_label[p])
for i, p in enumerate(targets)]
# join same consequtive predictions
prev_label = (None, None)
uniq_labels = []
for label in labels:
if label[1] != prev_label[1]:
uniq_labels.append(label)
prev_label = label
# end time of last label is one frame duration after
# the last prediction time
start_times, chord_labels = zip(*uniq_labels)
end_times = start_times[1:] + (labels[-1][0] + spf,)
return zip(start_times, end_times, chord_labels)
评论列表
文章目录