def classify_active(self):
"""Creates a classification for the active song using classifier
"""
self.logger.info('Classifying {0}'.format(str(self.active_song)))
batch_size = self.params.get('batch_size', 100)
indices = np.arange(self.active_song.time.size)
input = self.get_data_sample(indices)
prbs = self.classifier.predict_proba(
input, batch_size=batch_size, verbose=1).T
# for i in range(prbs.shape[1]):
# print self.active_song.time[i], ':', prbs[:, i]
#new_prbs = self.probs_to_classes(prbs)
# print new_prbs.shape
# for i in range(new_prbs.shape[1]):
# print self.active_song.time[i], ':', new_prbs[:, i]
unfiltered_classes = self.probs_to_classes(prbs)
try:
power_threshold = self.params['power_threshold']
except KeyError:
thresholded_classes = unfiltered_classes
else:
self.logger.debug('Thresholding at {0} dB'.format(power_threshold))
below_threshold = np.flatnonzero(
10 * np.log10(self.active_song.power) < power_threshold)
self.logger.debug(
'{0} indices found with low power'.format(below_threshold.size))
thresholded_classes = unfiltered_classes
thresholded_classes[below_threshold] = 0
# no need to be wasteful, filter if there is a filter
try:
medfilt_time = self.params['medfilt_time']
except KeyError:
filtered_classes = thresholded_classes
else:
dt = self.active_song.time[1] - self.active_song.time[0]
windowsize = int(np.round(medfilt_time / dt))
windowsize = windowsize + (windowsize + 1) % 2
filtered_classes = signal.medfilt(thresholded_classes, windowsize)
self.active_song.classification = filtered_classes
评论列表
文章目录