The ML code runs in workers
This commit is contained in:
parent
33e3265db6
commit
ff66a2f44c
4 changed files with 8 additions and 4 deletions
|
@ -1,4 +1,4 @@
|
|||
import { ensureElectron } from "@/next/electron";
|
||||
import { workerBridge } from "@/next/worker/worker-bridge";
|
||||
import {
|
||||
FaceEmbedding,
|
||||
FaceEmbeddingMethod,
|
||||
|
@ -23,7 +23,7 @@ class MobileFaceNetEmbeddingService implements FaceEmbeddingService {
|
|||
public async getFaceEmbeddings(
|
||||
faceData: Float32Array,
|
||||
): Promise<Array<FaceEmbedding>> {
|
||||
const outputData = await ensureElectron().faceEmbedding(faceData);
|
||||
const outputData = await workerBridge.faceEmbedding(faceData);
|
||||
|
||||
const embeddingSize = 192;
|
||||
const embeddings = new Array<FaceEmbedding>(
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { ensureElectron } from "@/next/electron";
|
||||
import { euclidean } from "hdbscan";
|
||||
import {
|
||||
Matrix,
|
||||
|
@ -21,6 +20,7 @@ import {
|
|||
} from "utils/image";
|
||||
import { newBox } from "utils/machineLearning";
|
||||
import { Box, Point } from "../../../thirdparty/face-api/classes";
|
||||
import { workerBridge } from "@/next/worker/worker-bridge";
|
||||
|
||||
class YoloFaceDetectionService implements FaceDetectionService {
|
||||
public method: Versioned<FaceDetectionMethod>;
|
||||
|
@ -45,7 +45,7 @@ class YoloFaceDetectionService implements FaceDetectionService {
|
|||
);
|
||||
const data = preprocessResult.data;
|
||||
const resized = preprocessResult.newSize;
|
||||
const outputData = await ensureElectron().detectFaces(data);
|
||||
const outputData = await workerBridge.detectFaces(data);
|
||||
const faces = this.getFacesFromYoloOutput(
|
||||
outputData as Float32Array,
|
||||
0.7,
|
||||
|
|
|
@ -124,6 +124,7 @@ class MLIDbStorage {
|
|||
.add(DEFAULT_ML_SEARCH_CONFIG, ML_SEARCH_CONFIG_NAME);
|
||||
}
|
||||
if (oldVersion < 4) {
|
||||
// TODO(MR): This loses the user's settings.
|
||||
db.deleteObjectStore("configs");
|
||||
db.createObjectStore("configs");
|
||||
|
||||
|
|
|
@ -46,6 +46,9 @@ const workerBridge = {
|
|||
logToDisk,
|
||||
convertToJPEG: (inputFileData: Uint8Array, filename: string) =>
|
||||
ensureElectron().convertToJPEG(inputFileData, filename),
|
||||
detectFaces: (input: Float32Array) => ensureElectron().detectFaces(input),
|
||||
faceEmbedding: (input: Float32Array) =>
|
||||
ensureElectron().faceEmbedding(input),
|
||||
};
|
||||
|
||||
export type WorkerBridge = typeof workerBridge;
|
||||
|
|
Loading…
Add table
Reference in a new issue