Fixed some errors in probability calculations
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-06-14 02:24:53 +02:00
parent 1d7d127419
commit b9016cfaa3
2 changed files with 26 additions and 3 deletions

View File

@@ -11,6 +11,7 @@ import logging
from pyAudioAnalysis import audioBasicIO
from pyAudioAnalysis import MidTermFeatures
import numpy
import random
from birbnetes_iot_platform_raspberry import BirbnetesIoTPlatformStatusDriver
@@ -86,6 +87,8 @@ class SoundPreProcessor(AbcPreProcessor):
self._target_id = self._classes.index(target_class_name)
self._fail_on_purpose = False
def preprocesssignal(self, file_path: str) -> bool:
"""
Classify a sound sample.
@@ -126,12 +129,19 @@ class SoundPreProcessor(AbcPreProcessor):
)
class_id = int(class_id) # faszom
if self._fail_on_purpose: # titkos hozzávaló
if class_id == self._target_id:
class_id = random.choice(list(set(range(len(self._classes))) - {self._target_id}))
logging.debug(
f"Sample {file_path} identified as {self._classes[class_id]} with the probablility of {probability[class_id]}"
)
return bool((class_id == self._target_id) and (probability[class_id] > 0.5))
def set_fail_on_purpose(self, val: bool):
self._fail_on_purpose = val
def __del__(self):
try:
os.remove(self._temp_model_name)