From 7bc08fdc8db57b7833285605b1b5a7a2d195193a Mon Sep 17 00:00:00 2001 From: marcsello Date: Wed, 30 Sep 2020 06:12:36 +0200 Subject: [PATCH] Fixed up logging --- src/preprocessor/soundpreprocessor.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/preprocessor/soundpreprocessor.py b/src/preprocessor/soundpreprocessor.py index adcc9c4..5cb0b7d 100644 --- a/src/preprocessor/soundpreprocessor.py +++ b/src/preprocessor/soundpreprocessor.py @@ -69,13 +69,18 @@ class SoundPreProcessor(AbcPreProcessor): self._mid_window, self._mid_step, self._short_window, \ self._short_step, self._compute_beat = load_model(self._temp_model_name) + + logging.info("The loaded model contains the following classes: " + ", ".join(self._classes)) + if config.SVM_TARGET_CLASS_NAME not in self._classes: + raise Exception(f"The specified target class {config.SVM_TARGET_CLASS_NAME} is not in the possible classes") + def preprocesssignal(self, file_path: str) -> bool: """ Classify a sound sample. :param file_path: Access path of the sound sample up for processing. :return: """ - logging.info("Running extraction...") + logging.debug("Running extraction...") sampling_rate, signal = audioBasicIO.read_audio_file(file_path) signal = audioBasicIO.stereo_to_mono(signal) @@ -101,13 +106,15 @@ class SoundPreProcessor(AbcPreProcessor): mid_features = numpy.append(mid_features, beat) mid_features = numpy.append(mid_features, beat_conf) - logging.info("Running classification...") + logging.debug("Running classification...") target_id = self._classes.index(config.SVM_TARGET_CLASS_NAME) # Might raise ValueError feature_vector = (mid_features - self._mean) / self._std class_id, probability = classifier_wrapper(self._classifier, self._model_details['type'], feature_vector) + logging.debug(f"Sample {file_path} identified as {self._classes[class_id]} with the probablility of {probability}") + return bool(class_id == target_id) def __del__(self):