Clean up logging

This commit is contained in:
Nicolas Mowen 2025-06-05 08:08:58 -06:00
parent 04fdd254f9
commit bed02c8461
2 changed files with 13 additions and 2 deletions

View File

@ -31,6 +31,7 @@ class LoggerConfig(FrigateBaseModel):
log_levels = {
"absl": LogLevel.error,
"httpx": LogLevel.error,
"tensorflow": LogLevel.error,
"werkzeug": LogLevel.error,
"ws4py": LogLevel.error,
**self.logs,

View File

@ -1,7 +1,7 @@
"""Util for classification models."""
import logging
import os
import sys
import cv2
import numpy as np
@ -50,7 +50,13 @@ def train_classification_model(model_name: str) -> bool:
]
)
tf.get_logger().setLevel(logging.ERROR)
# TF and Keras are very loud with logging
# we want to avoid these logs so we
# temporarily redirect stdout / stderr
original_stdout = sys.stdout
original_stderr = sys.stderr
sys.stdout = open(os.devnull, "w")
sys.stderr = open(os.devnull, "w")
# Start with imagenet base model with 35% of channels in each layer
base_model = MobileNetV2(
@ -112,3 +118,7 @@ def train_classification_model(model_name: str) -> bool:
# write model
with open(os.path.join(model_dir, "model.tflite"), "wb") as f:
f.write(tflite_model)
# restore original stdout / stderr
sys.stdout = original_stdout
sys.stderr = original_stderr