Grapevine_Disease_Detection/VinEye/src/services/tflite/model.ts
Yanis a964cc3836 add VinEye frontend app + fix hardcoded paths + gitignore
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 10:30:05 +02:00

53 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// TODO: Remplacer par le vrai modèle TFLite (MobileNetV2 fine-tuné sur dataset vignes)
import type { Detection, DetectionResult } from '@/types/detection';
import { cepages } from '@/utils/cepages';
const WEIGHTED_RESULTS: { result: DetectionResult; weight: number }[] = [
{ result: 'vine', weight: 70 },
{ result: 'uncertain', weight: 20 },
{ result: 'not_vine', weight: 10 },
];
function weightedRandom(): DetectionResult {
const total = WEIGHTED_RESULTS.reduce((sum, r) => sum + r.weight, 0);
let rand = Math.random() * total;
for (const r of WEIGHTED_RESULTS) {
rand -= r.weight;
if (rand <= 0) return r.result;
}
return 'vine';
}
// TODO: Remplacer par le vrai modèle TFLite
export async function loadModel(): Promise<boolean> {
// Simule le chargement du modèle (1-2 secondes)
await new Promise((resolve) => setTimeout(resolve, 1200 + Math.random() * 800));
return true;
}
// TODO: Remplacer par le vrai modèle TFLite
export async function runInference(imageUri?: string): Promise<Detection> {
// Simule l'inférence (200-600ms)
await new Promise((resolve) => setTimeout(resolve, 200 + Math.random() * 400));
const result = weightedRandom();
const confidence = result === 'vine'
? Math.floor(70 + Math.random() * 30) // 70100%
: result === 'uncertain'
? Math.floor(40 + Math.random() * 30) // 4070%
: Math.floor(10 + Math.random() * 30); // 1040%
const cepageId =
result === 'vine'
? cepages[Math.floor(Math.random() * cepages.length)].id
: undefined;
return {
result,
confidence,
cepageId,
timestamp: Date.now(),
imageUri,
};
}