|
|
|
@ -64,34 +64,18 @@ def get_required_drone_streak(freq):
|
|
|
|
return 1
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_required_drone_prob(freq):
|
|
|
|
def update_drone_streak(freq, prediction):
|
|
|
|
raw_value = config.get(f"DRONE_PROB_THRESHOLD_{freq}", config.get("DRONE_PROB_THRESHOLD_DEFAULT", "0"))
|
|
|
|
if prediction == "drone":
|
|
|
|
try:
|
|
|
|
|
|
|
|
value = float(raw_value)
|
|
|
|
|
|
|
|
return min(1.0, max(0.0, value))
|
|
|
|
|
|
|
|
except (TypeError, ValueError):
|
|
|
|
|
|
|
|
logging.warning("Invalid DRONE_PROB_THRESHOLD for %s=%r, falling back to 0.0", freq, raw_value)
|
|
|
|
|
|
|
|
return 0.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_drone_streak(freq, prediction, drone_probability):
|
|
|
|
|
|
|
|
required_prob = get_required_drone_prob(freq)
|
|
|
|
|
|
|
|
drone_probability = 0.0 if drone_probability is None else float(drone_probability)
|
|
|
|
|
|
|
|
passes_prob_gate = prediction == "drone" and drone_probability >= required_prob
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if passes_prob_gate:
|
|
|
|
|
|
|
|
drone_streaks[freq] = drone_streaks.get(freq, 0) + 1
|
|
|
|
drone_streaks[freq] = drone_streaks.get(freq, 0) + 1
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
drone_streaks[freq] = 0
|
|
|
|
drone_streaks[freq] = 0
|
|
|
|
|
|
|
|
|
|
|
|
required = get_required_drone_streak(freq)
|
|
|
|
required = get_required_drone_streak(freq)
|
|
|
|
triggered = passes_prob_gate and drone_streaks[freq] >= required
|
|
|
|
triggered = prediction == "drone" and drone_streaks[freq] >= required
|
|
|
|
logging.info(
|
|
|
|
logging.info(
|
|
|
|
"NN alarm gate freq=%s prediction=%s drone_probability=%.3f threshold=%.3f streak=%s/%s triggered=%s",
|
|
|
|
"NN alarm gate freq=%s prediction=%s streak=%s/%s triggered=%s",
|
|
|
|
freq,
|
|
|
|
freq,
|
|
|
|
prediction,
|
|
|
|
prediction,
|
|
|
|
drone_probability,
|
|
|
|
|
|
|
|
required_prob,
|
|
|
|
|
|
|
|
drone_streaks[freq],
|
|
|
|
drone_streaks[freq],
|
|
|
|
required,
|
|
|
|
required,
|
|
|
|
triggered,
|
|
|
|
triggered,
|
|
|
|
@ -180,21 +164,15 @@ def receive_data():
|
|
|
|
print('-' * 100)
|
|
|
|
print('-' * 100)
|
|
|
|
print(str(model))
|
|
|
|
print(str(model))
|
|
|
|
result_msg[str(model.get_model_name())] = {'freq': freq}
|
|
|
|
result_msg[str(model.get_model_name())] = {'freq': freq}
|
|
|
|
inference_result = model.get_inference([np.asarray(data['data_real'], dtype=np.float32), np.asarray(data['data_imag'], dtype=np.float32)])
|
|
|
|
prediction, probability = model.get_inference([np.asarray(data['data_real'], dtype=np.float32), np.asarray(data['data_imag'], dtype=np.float32)])
|
|
|
|
if inference_result is None:
|
|
|
|
|
|
|
|
raise RuntimeError(f"Inference failed for {model.get_model_name()}")
|
|
|
|
|
|
|
|
prediction, probability = inference_result[:2]
|
|
|
|
|
|
|
|
drone_probability = float(probability) if prediction == "drone" else 0.0
|
|
|
|
|
|
|
|
result_msg[str(model.get_model_name())]['prediction'] = prediction
|
|
|
|
result_msg[str(model.get_model_name())]['prediction'] = prediction
|
|
|
|
result_msg[str(model.get_model_name())]['probability'] = str(probability)
|
|
|
|
result_msg[str(model.get_model_name())]['probability'] = str(probability)
|
|
|
|
result_msg[str(model.get_model_name())]['drone_probability'] = str(drone_probability)
|
|
|
|
|
|
|
|
result_msg[str(model.get_model_name())]['drone_threshold'] = str(get_required_drone_prob(freq))
|
|
|
|
|
|
|
|
prediction_list.append(prediction)
|
|
|
|
prediction_list.append(prediction)
|
|
|
|
print('-' * 100)
|
|
|
|
print('-' * 100)
|
|
|
|
print()
|
|
|
|
print()
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
result = update_drone_streak(freq, prediction, drone_probability)
|
|
|
|
result = update_drone_streak(freq, prediction_list[0])
|
|
|
|
data_to_send={
|
|
|
|
data_to_send={
|
|
|
|
'freq': str(freq),
|
|
|
|
'freq': str(freq),
|
|
|
|
'amplitude': result
|
|
|
|
'amplitude': result
|
|
|
|
|