feat: track history of last 3 predictions
Co-authored-by: aider (gemini/gemini-2.5-pro-preview-05-06) <aider@aider.chat>
This commit is contained in:
12
server.py
12
server.py
@@ -27,6 +27,8 @@ CLASS_NAMES = ['closed', 'open'] # From training, sorted alphabetically
|
|||||||
POLL_INTERVAL_SECONDS = 10
|
POLL_INTERVAL_SECONDS = 10
|
||||||
REQUEST_TIMEOUT_SECONDS = 5
|
REQUEST_TIMEOUT_SECONDS = 5
|
||||||
UNSURE_CONFIDENCE_THRESHOLD = 0.97
|
UNSURE_CONFIDENCE_THRESHOLD = 0.97
|
||||||
|
PREDICTION_HISTORY = []
|
||||||
|
PREDICTION_HISTORY_MAX_LENGTH = 3
|
||||||
|
|
||||||
# --- Model Inference ---
|
# --- Model Inference ---
|
||||||
def get_prediction(model, image_bytes, device):
|
def get_prediction(model, image_bytes, device):
|
||||||
@@ -74,6 +76,16 @@ async def monitor_garage_door(app):
|
|||||||
prediction, confidence = result
|
prediction, confidence = result
|
||||||
logging.debug(f"Garage door status: {prediction} (confidence: {confidence:.4f})")
|
logging.debug(f"Garage door status: {prediction} (confidence: {confidence:.4f})")
|
||||||
|
|
||||||
|
# Update prediction history
|
||||||
|
if confidence >= UNSURE_CONFIDENCE_THRESHOLD:
|
||||||
|
PREDICTION_HISTORY.append(prediction)
|
||||||
|
else:
|
||||||
|
PREDICTION_HISTORY.append('unknown')
|
||||||
|
|
||||||
|
# Trim history if it's too long
|
||||||
|
if len(PREDICTION_HISTORY) > PREDICTION_HISTORY_MAX_LENGTH:
|
||||||
|
PREDICTION_HISTORY.pop(0)
|
||||||
|
|
||||||
if confidence < UNSURE_CONFIDENCE_THRESHOLD:
|
if confidence < UNSURE_CONFIDENCE_THRESHOLD:
|
||||||
# Sanitize timestamp for use in filename
|
# Sanitize timestamp for use in filename
|
||||||
timestamp = datetime.now().isoformat().replace(':', '-')
|
timestamp = datetime.now().isoformat().replace(':', '-')
|
||||||
|
Reference in New Issue
Block a user