|
|
@@ -23,7 +23,7 @@ export class InferenceService {
|
|
|
private readonly localInferenceService: LocalInferenceService,
|
|
|
private readonly remoteInferenceService: RemoteInferenceService,
|
|
|
private readonly imageProcessor: ImageProcessorService
|
|
|
- ) {}
|
|
|
+ ) { }
|
|
|
|
|
|
/**
|
|
|
* Main analyze entry point. imageData is base64 string.
|
|
|
@@ -42,8 +42,8 @@ export class InferenceService {
|
|
|
|
|
|
const file = new File([blob], 'capture.jpg', { type: 'image/jpeg' });
|
|
|
|
|
|
- const modelPath = this.localEngine() === 'onnx'
|
|
|
- ? 'assets/models/onnx/best.onnx'
|
|
|
+ const modelPath = this.localEngine() === 'onnx'
|
|
|
+ ? 'assets/models/onnx/best.onnx'
|
|
|
: 'assets/models/tflite/best_float32.tflite';
|
|
|
|
|
|
return from(this.localInferenceService.loadModel(modelPath)).pipe(
|
|
|
@@ -70,6 +70,7 @@ export class InferenceService {
|
|
|
|
|
|
return this.remoteInferenceService.analyze(blob).pipe(
|
|
|
map((response: AnalysisResponse) => {
|
|
|
+ // console.log(response)
|
|
|
const mappedDets = response.detections.map(det => ({
|
|
|
box: det.box,
|
|
|
confidence: det.confidence,
|
|
|
@@ -77,10 +78,10 @@ export class InferenceService {
|
|
|
color: this.getGradeColor(det.class),
|
|
|
is_health_alert: det.is_health_alert
|
|
|
}));
|
|
|
-
|
|
|
+
|
|
|
this.detections.set(mappedDets);
|
|
|
- this.summary.set({ ...response.industrial_summary });
|
|
|
-
|
|
|
+ this.summary.set({ ...response.industrial_summary });
|
|
|
+
|
|
|
return mappedDets;
|
|
|
}),
|
|
|
catchError(err => {
|
|
|
@@ -91,8 +92,8 @@ export class InferenceService {
|
|
|
}
|
|
|
|
|
|
private calculateSummary(detections: any[]): any {
|
|
|
- const summary: any = {
|
|
|
- 'Empty_Bunch': 0, 'Underripe': 0, 'Abnormal': 0, 'Ripe': 0, 'Unripe': 0, 'Overripe': 0
|
|
|
+ const summary: any = {
|
|
|
+ 'Empty_Bunch': 0, 'Underripe': 0, 'Abnormal': 0, 'Ripe': 0, 'Unripe': 0, 'Overripe': 0
|
|
|
};
|
|
|
detections.forEach(d => { if (summary[d.class] !== undefined) summary[d.class]++; });
|
|
|
return summary;
|
|
|
@@ -107,7 +108,7 @@ export class InferenceService {
|
|
|
const ab = new ArrayBuffer(byteString.length);
|
|
|
const ia = new Uint8Array(ab);
|
|
|
for (let i = 0; i < byteString.length; i++) {
|
|
|
- ia[i] = byteString.charCodeAt(i);
|
|
|
+ ia[i] = byteString.charCodeAt(i);
|
|
|
}
|
|
|
return new Blob([ab], { type: mimeString });
|
|
|
} catch (e) {
|
|
|
@@ -118,8 +119,8 @@ export class InferenceService {
|
|
|
|
|
|
private getGradeColor(className: string): string {
|
|
|
const colors: { [key: string]: string } = {
|
|
|
- 'Empty_Bunch': '#6C757D', 'Underripe': '#F9A825', 'Abnormal': '#DC3545',
|
|
|
- 'Ripe': '#00A651', 'Unripe': '#9E9D24', 'Overripe': '#5D4037'
|
|
|
+ 'Empty_Bunch': '#6C757D', 'Underripe': '#F9A825', 'Abnormal': '#DC3545',
|
|
|
+ 'Ripe': '#00A651', 'Unripe': '#9E9D24', 'Overripe': '#5D4037'
|
|
|
};
|
|
|
return colors[className] || '#000000';
|
|
|
}
|