@@ -161,13 +161,15 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn calibrate_probs_selects_top_label() {
|
fn calibrate_probs_selects_top_label() {
|
||||||
let logits = [1.0, 2.0, 3.0, 0.5];
|
// [1, 2, 3, 0.5] → softmax ≈ [0.086, 0.235, 0.638, 0.040]
|
||||||
|
// 0.638 < 0.70 → "uncertain". Use larger gap for "confident".
|
||||||
|
let logits = [0.0, 0.0, 10.0, 0.0]; // softmax ≈ [0, 0, ~1, 0]
|
||||||
let result = ModelService::calibrate_prediction(&logits, T, HIGH, LOW);
|
let result = ModelService::calibrate_prediction(&logits, T, HIGH, LOW);
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
let p = result.unwrap();
|
let p = result.unwrap();
|
||||||
// Index 2 = Hawar Daun (highest logit)
|
// Index 2 = Hawar Daun (highest logit)
|
||||||
assert_eq!(p.label, "Hawar Daun");
|
assert_eq!(p.label, "Hawar Daun");
|
||||||
assert!(p.confidence > 0.5);
|
assert!(p.confidence >= 0.999);
|
||||||
assert_eq!(p.status, "confident");
|
assert_eq!(p.status, "confident");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ pub fn metadata_response(model_path: String, model_loaded: bool, input_size: u32
|
|||||||
|
|
||||||
pub fn prediction_response(prediction: Prediction) -> PredictionResponse {
|
pub fn prediction_response(prediction: Prediction) -> PredictionResponse {
|
||||||
PredictionResponse {
|
PredictionResponse {
|
||||||
|
status: prediction.status,
|
||||||
label: prediction.label,
|
label: prediction.label,
|
||||||
confidence: prediction.confidence,
|
confidence: prediction.confidence,
|
||||||
probabilities: prediction.probabilities,
|
probabilities: prediction.probabilities,
|
||||||
@@ -131,7 +132,7 @@ pub async fn predict(
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Preprocess the image
|
// Preprocess the image
|
||||||
let preprocess_start = std::time::Instant::now();
|
let _preprocess_start = std::time::Instant::now();
|
||||||
let input = preprocess_image(&bytes, state.model.input_size())?;
|
let input = preprocess_image(&bytes, state.model.input_size())?;
|
||||||
|
|
||||||
// Record image size metric
|
// Record image size metric
|
||||||
|
|||||||
Reference in New Issue
Block a user