mirror of
https://github.com/DaLaw2/NetGuardia.git
synced 2026-08-24 14:10:28 +09:00
fix: add model loading progress logs
Log each ONNX model load with name, features, batch_size, and elapsed time. Makes the 39s startup gap visible instead of silent. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
c1f7a0aedd
commit
82d2f53b4b
@ -1,9 +1,13 @@
|
||||
use std::path::PathBuf;
|
||||
use std::time::Instant;
|
||||
|
||||
use macros::log;
|
||||
use tract_onnx::prelude::*;
|
||||
|
||||
use crate::infrastructure::app_config::AppConfig;
|
||||
use crate::model::detection::ml_detection::RunnableModel;
|
||||
use crate::model::error::ml::MLError;
|
||||
use crate::model::log::ml::MLLog;
|
||||
use crate::model::system::config::MLInferenceConfig;
|
||||
|
||||
pub struct MLModels {
|
||||
@ -36,13 +40,26 @@ impl MLModels {
|
||||
fn loader(model: &str, features: usize, batch_size: usize) -> Result<RunnableModel, MLError> {
|
||||
let model_path = PathBuf::from("models").join(model);
|
||||
|
||||
log!(MLLog::ModelLoading(
|
||||
model.to_string(),
|
||||
features,
|
||||
batch_size
|
||||
));
|
||||
|
||||
let start = Instant::now();
|
||||
|
||||
let load = || -> Result<RunnableModel, Box<dyn std::error::Error>> {
|
||||
let mut model = onnx().model_for_path(&model_path)?;
|
||||
model.set_input_fact(0, f32::fact([batch_size, features]).into())?;
|
||||
Ok(model.into_optimized()?.into_runnable()?)
|
||||
};
|
||||
|
||||
load().map_err(|_| MLError::ModelLoadFailed(model_path))
|
||||
let result = load().map_err(|_| MLError::ModelLoadFailed(model_path));
|
||||
|
||||
let elapsed_ms = start.elapsed().as_millis() as u64;
|
||||
log!(MLLog::ModelLoadComplete(model.to_string(), elapsed_ms));
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
pub fn get_model_info(&self, name: &str) -> String {
|
||||
|
||||
@ -45,6 +45,12 @@ loggable! {
|
||||
#[error("ML circuit breaker RESET: inference re-enabled after {cooldown_secs}s cooldown")]
|
||||
CircuitBreakerReset { cooldown_secs: u64 } => tracing::Level::WARN,
|
||||
|
||||
#[error("Loading ONNX model '{name}' (features={features}, batch_size={batch_size})...")]
|
||||
ModelLoading { name: String, features: usize, batch_size: usize } => tracing::Level::INFO,
|
||||
|
||||
#[error("Model '{name}' loaded and optimized in {elapsed_ms}ms")]
|
||||
ModelLoadComplete { name: String, elapsed_ms: u64 } => tracing::Level::INFO,
|
||||
|
||||
#[error("Model watcher started, monitoring models/ for .onnx changes")]
|
||||
ModelWatcherStarted => tracing::Level::INFO,
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user