From df26e12db66d2574da9fc49c185e9f2b26f15137 Mon Sep 17 00:00:00 2001 From: Mert <101130780+mertalev@users.noreply.github.com> Date: Wed, 30 Aug 2023 04:16:00 -0400 Subject: [PATCH] fix(ml): `minScore` not being set correctly (#3916) * fixed `minScore` not being set correctly * apply to init * don't send `enabled` * fix eslint warning * better error message --- machine-learning/app/models/facial_recognition.py | 4 ++-- machine-learning/app/models/image_classification.py | 4 ++-- server/src/infra/repositories/machine-learning.repository.ts | 5 ++++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/machine-learning/app/models/facial_recognition.py b/machine-learning/app/models/facial_recognition.py index 630c9d2e7c..7cbdfe404b 100644 --- a/machine-learning/app/models/facial_recognition.py +++ b/machine-learning/app/models/facial_recognition.py @@ -23,7 +23,7 @@ class FaceRecognizer(InferenceModel): cache_dir: Path | str | None = None, **model_kwargs: Any, ) -> None: - self.min_score = min_score + self.min_score = model_kwargs.pop("minScore", min_score) super().__init__(model_name, cache_dir, **model_kwargs) def _download(self, **model_kwargs: Any) -> None: @@ -105,4 +105,4 @@ class FaceRecognizer(InferenceModel): return self.cache_dir.is_dir() and any(self.cache_dir.glob("*.onnx")) def configure(self, **model_kwargs: Any) -> None: - self.det_model.det_thresh = model_kwargs.get("min_score", self.det_model.det_thresh) + self.det_model.det_thresh = model_kwargs.pop("minScore", self.det_model.det_thresh) diff --git a/machine-learning/app/models/image_classification.py b/machine-learning/app/models/image_classification.py index bdcf76f5f3..dde195d357 100644 --- a/machine-learning/app/models/image_classification.py +++ b/machine-learning/app/models/image_classification.py @@ -22,7 +22,7 @@ class ImageClassifier(InferenceModel): cache_dir: Path | str | None = None, **model_kwargs: Any, ) -> None: - self.min_score = min_score + self.min_score = model_kwargs.pop("minScore", min_score) super().__init__(model_name, cache_dir, **model_kwargs) def _download(self, **model_kwargs: Any) -> None: @@ -65,4 +65,4 @@ class ImageClassifier(InferenceModel): return tags def configure(self, **model_kwargs: Any) -> None: - self.min_score = model_kwargs.get("min_score", self.min_score) + self.min_score = model_kwargs.pop("minScore", self.min_score) diff --git a/server/src/infra/repositories/machine-learning.repository.ts b/server/src/infra/repositories/machine-learning.repository.ts index fd4e934293..1ed887082a 100644 --- a/server/src/infra/repositories/machine-learning.repository.ts +++ b/server/src/infra/repositories/machine-learning.repository.ts @@ -43,7 +43,10 @@ export class MachineLearningRepository implements IMachineLearningRepository { async getFormData(input: TextModelInput | VisionModelInput, config: ModelConfig): Promise { const formData = new FormData(); - const { modelName, modelType, ...options } = config; + const { enabled, modelName, modelType, ...options } = config; + if (!enabled) { + throw new Error(`${modelType} is not enabled`); + } formData.append('modelName', modelName); if (modelType) {