From 080fcab6a39abb221ee91e1f77af879b71dfde7e Mon Sep 17 00:00:00 2001 From: Abhinav Date: Tue, 12 Apr 2022 16:37:06 +0530 Subject: [PATCH] move constants --- src/constants/machineLearning/config.ts | 12 ++++++++++++ .../machineLearning/blazeFaceDetectionService.ts | 16 +++++++++------- .../mobileFaceNetEmbeddingService.ts | 2 +- src/services/machineLearning/tesseractService.ts | 10 ++++++---- src/types/machineLearning/index.ts | 12 ------------ src/utils/machineLearning/index.ts | 6 ++++-- 6 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/constants/machineLearning/config.ts b/src/constants/machineLearning/config.ts index 601af2729..0cb3747d1 100644 --- a/src/constants/machineLearning/config.ts +++ b/src/constants/machineLearning/config.ts @@ -73,3 +73,15 @@ export const MAX_FACE_DISTANCE_PERCENT = Math.sqrt(2) / 100; export const MAX_ML_SYNC_ERROR_COUNT = 4; export const TEXT_DETECTION_TIMEOUT_MS = [10000, 30000, 60000, 120000, 240000]; + +export const BLAZEFACE_MAX_FACES = 50; +export const BLAZEFACE_INPUT_SIZE = 256; +export const BLAZEFACE_IOU_THRESHOLD = 0.3; +export const BLAZEFACE_SCORE_THRESHOLD = 0.75; +export const BLAZEFACE_PASS1_SCORE_THRESHOLD = 0.4; +export const BLAZEFACE_FACE_SIZE = 112; +export const MOBILEFACENET_FACE_SIZE = 112; + +export const TESSERACT_MIN_IMAGE_WIDTH = 44; +export const TESSERACT_MIN_IMAGE_HEIGHT = 20; +export const TESSERACT_MAX_IMAGE_DIMENSION = 720; diff --git a/src/services/machineLearning/blazeFaceDetectionService.ts b/src/services/machineLearning/blazeFaceDetectionService.ts index 174953ba9..2adcf4e90 100644 --- a/src/services/machineLearning/blazeFaceDetectionService.ts +++ b/src/services/machineLearning/blazeFaceDetectionService.ts @@ -6,12 +6,6 @@ import { import * as tf from '@tensorflow/tfjs-core'; import { GraphModel } from '@tensorflow/tfjs-converter'; import { - BLAZEFACE_FACE_SIZE, - BLAZEFACE_INPUT_SIZE, - BLAZEFACE_IOU_THRESHOLD, - BLAZEFACE_MAX_FACES, - BLAZEFACE_PASS1_SCORE_THRESHOLD, - BLAZEFACE_SCORE_THRESHOLD, FaceDetection, FaceDetectionMethod, FaceDetectionService, @@ -30,7 +24,15 @@ import { removeDuplicateDetections, transformPaddedToImage, } from 'utils/machineLearning/faceDetection'; -import { MAX_FACE_DISTANCE_PERCENT } from 'constants/machineLearning/config'; +import { + BLAZEFACE_FACE_SIZE, + BLAZEFACE_INPUT_SIZE, + BLAZEFACE_IOU_THRESHOLD, + BLAZEFACE_MAX_FACES, + BLAZEFACE_PASS1_SCORE_THRESHOLD, + BLAZEFACE_SCORE_THRESHOLD, + MAX_FACE_DISTANCE_PERCENT, +} from 'constants/machineLearning/config'; class BlazeFaceDetectionService implements FaceDetectionService { private blazeFaceModel: Promise; diff --git a/src/services/machineLearning/mobileFaceNetEmbeddingService.ts b/src/services/machineLearning/mobileFaceNetEmbeddingService.ts index 8b0698609..8057c0366 100644 --- a/src/services/machineLearning/mobileFaceNetEmbeddingService.ts +++ b/src/services/machineLearning/mobileFaceNetEmbeddingService.ts @@ -1,11 +1,11 @@ import * as tf from '@tensorflow/tfjs-core'; import { TFLiteModel } from '@tensorflow/tfjs-tflite'; +import { MOBILEFACENET_FACE_SIZE } from 'constants/machineLearning/config'; import PQueue from 'p-queue'; import { FaceEmbedding, FaceEmbeddingMethod, FaceEmbeddingService, - MOBILEFACENET_FACE_SIZE, Versioned, } from 'types/machineLearning'; import { imageBitmapsToTensor4D } from 'utils/machineLearning'; diff --git a/src/services/machineLearning/tesseractService.ts b/src/services/machineLearning/tesseractService.ts index 51d78680e..9e313633f 100644 --- a/src/services/machineLearning/tesseractService.ts +++ b/src/services/machineLearning/tesseractService.ts @@ -1,7 +1,4 @@ import { - TESSERACT_MAX_IMAGE_DIMENSION, - TESSERACT_MIN_IMAGE_HEIGHT, - TESSERACT_MIN_IMAGE_WIDTH, TextDetectionMethod, TextDetectionService, Versioned, @@ -14,7 +11,12 @@ import { imageBitmapToBlob, resizeToSquare } from 'utils/image'; import { getFileType } from 'services/upload/readFileService'; import { FILE_TYPE } from 'constants/file'; import { makeID } from 'utils/user'; -import { TEXT_DETECTION_TIMEOUT_MS } from 'constants/machineLearning/config'; +import { + TESSERACT_MAX_IMAGE_DIMENSION, + TESSERACT_MIN_IMAGE_HEIGHT, + TESSERACT_MIN_IMAGE_WIDTH, + TEXT_DETECTION_TIMEOUT_MS, +} from 'constants/machineLearning/config'; import { promiseWithTimeout } from 'utils/common/promiseTimeout'; class TesseractService implements TextDetectionService { diff --git a/src/types/machineLearning/index.ts b/src/types/machineLearning/index.ts index a44e02192..f0d2e7837 100644 --- a/src/types/machineLearning/index.ts +++ b/src/types/machineLearning/index.ts @@ -363,18 +363,6 @@ export interface MLLibraryData { export declare type MLIndex = 'files' | 'people'; -export const BLAZEFACE_MAX_FACES = 50; -export const BLAZEFACE_INPUT_SIZE = 256; -export const BLAZEFACE_IOU_THRESHOLD = 0.3; -export const BLAZEFACE_SCORE_THRESHOLD = 0.75; -export const BLAZEFACE_PASS1_SCORE_THRESHOLD = 0.4; -export const BLAZEFACE_FACE_SIZE = 112; -export const MOBILEFACENET_FACE_SIZE = 112; - -export const TESSERACT_MIN_IMAGE_WIDTH = 44; -export const TESSERACT_MIN_IMAGE_HEIGHT = 20; -export const TESSERACT_MAX_IMAGE_DIMENSION = 720; - export interface FaceDetectionService { method: Versioned; // init(): Promise; diff --git a/src/utils/machineLearning/index.ts b/src/utils/machineLearning/index.ts index 467966649..6626ed5d1 100644 --- a/src/utils/machineLearning/index.ts +++ b/src/utils/machineLearning/index.ts @@ -1,6 +1,9 @@ import { NormalizedFace } from 'blazeface-back'; import * as tf from '@tensorflow/tfjs-core'; -import { ML_SYNC_DOWNLOAD_TIMEOUT_MS } from 'constants/machineLearning/config'; +import { + BLAZEFACE_FACE_SIZE, + ML_SYNC_DOWNLOAD_TIMEOUT_MS, +} from 'constants/machineLearning/config'; import { euclidean } from 'hdbscan'; import PQueue from 'p-queue'; import DownloadManager from 'services/downloadManager'; @@ -10,7 +13,6 @@ import { Dimensions } from 'types/image'; import { Thing, AlignedFace, - BLAZEFACE_FACE_SIZE, DetectedFace, DetectedObject, Face,