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

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

View File

@ -67,8 +67,18 @@ def mqtt_on_command(client, userdata, message):
logging.error(f"MQTT Invalid message recieved: {e}") logging.error(f"MQTT Invalid message recieved: {e}")
return return
if msg.get("command") == 'doAlert': cmd = msg.get("command")
userdata.act()
if cmd == 'doAlert':
userdata[1].act()
elif cmd == 'offline':
userdata[0][0].soundpreprocessor.set_fail_on_purpose(True)
BirbnetesIoTPlatformStatusDriver.enqueue_pattern('red', [1])
elif cmd == 'online':
userdata[0][0].soundpreprocessor.set_fail_on_purpose(False)
BirbnetesIoTPlatformStatusDriver.enqueue_pattern('green', [1])
def main() -> None: def main() -> None:
@ -83,7 +93,10 @@ def main() -> None:
loopingtimer = LoopingTimer(function=timer_tick, tick_args=listofabcsignaprocessors, interval=config.TICK_INTERVAL) loopingtimer = LoopingTimer(function=timer_tick, tick_args=listofabcsignaprocessors, interval=config.TICK_INTERVAL)
loopingtimer.start() loopingtimer.start()
client = paho.mqtt.client.Client(userdata=Loudspeaker(config.ENEMY_SOUNDS), client_id=config.DEVICE_ID) client = paho.mqtt.client.Client(
userdata=(listofabcsignaprocessors, Loudspeaker(config.ENEMY_SOUNDS)),
client_id=config.DEVICE_ID
)
client.on_connect = mqtt_on_connect client.on_connect = mqtt_on_connect
client.on_disconnect = mqtt_on_disconnect client.on_disconnect = mqtt_on_disconnect
client.on_message = mqtt_on_command client.on_message = mqtt_on_command

View File

@ -11,6 +11,7 @@ import logging
from pyAudioAnalysis import audioBasicIO from pyAudioAnalysis import audioBasicIO
from pyAudioAnalysis import MidTermFeatures from pyAudioAnalysis import MidTermFeatures
import numpy import numpy
import random
from birbnetes_iot_platform_raspberry import BirbnetesIoTPlatformStatusDriver from birbnetes_iot_platform_raspberry import BirbnetesIoTPlatformStatusDriver
@ -86,6 +87,8 @@ class SoundPreProcessor(AbcPreProcessor):
self._target_id = self._classes.index(target_class_name) self._target_id = self._classes.index(target_class_name)
self._fail_on_purpose = False
def preprocesssignal(self, file_path: str) -> bool: def preprocesssignal(self, file_path: str) -> bool:
""" """
Classify a sound sample. Classify a sound sample.
@ -126,12 +129,19 @@ class SoundPreProcessor(AbcPreProcessor):
) )
class_id = int(class_id) # faszom 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( logging.debug(
f"Sample {file_path} identified as {self._classes[class_id]} with the probablility of {probability[class_id]}" 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)) 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): def __del__(self):
try: try:
os.remove(self._temp_model_name) os.remove(self._temp_model_name)