Set person face chip to one having max pixels
And detection probability score
This commit is contained in:
parent
e96e1a9ee4
commit
af130f803b
|
@ -26,6 +26,7 @@ import { toTSNE } from 'utils/machineLearning/visualization';
|
|||
import { mlFilesStore, mlPeopleStore } from 'utils/storage/localForage';
|
||||
import ArcfaceAlignmentService from './arcfaceAlignmentService';
|
||||
import {
|
||||
findFirstIfSorted,
|
||||
getAllFacesFromMap,
|
||||
getFaceImage,
|
||||
getThumbnailTFImage,
|
||||
|
@ -315,8 +316,14 @@ class MachineLearningService {
|
|||
.map((f) => allFaces[f])
|
||||
.filter((f) => f);
|
||||
|
||||
// TODO: face box to be normalized to 0..1 scale
|
||||
const personFace = findFirstIfSorted(
|
||||
faces,
|
||||
(a, b) =>
|
||||
a.probability * a.box.width - b.probability * b.box.width
|
||||
);
|
||||
const faceImageTensor = await getFaceImage(
|
||||
faces[0],
|
||||
personFace,
|
||||
syncContext.token
|
||||
);
|
||||
const faceImage = await faceImageTensor.array();
|
||||
|
|
|
@ -180,7 +180,7 @@ export async function getPeopleList(file: File): Promise<Array<Person>> {
|
|||
const mlFileData: MlFileData = await mlFilesStore.getItem(
|
||||
file.id.toString()
|
||||
);
|
||||
if (!mlFileData.faces || mlFileData.faces.length < 1) {
|
||||
if (!mlFileData || !mlFileData.faces || mlFileData.faces.length < 1) {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
@ -200,6 +200,25 @@ export async function getPeopleList(file: File): Promise<Array<Person>> {
|
|||
return peopleList;
|
||||
}
|
||||
|
||||
export function findFirstIfSorted<T>(
|
||||
elements: Array<T>,
|
||||
comparator: (a: T, b: T) => number
|
||||
) {
|
||||
if (!elements || elements.length < 1) {
|
||||
return;
|
||||
}
|
||||
let first = elements[0];
|
||||
|
||||
for (let i = 1; i < elements.length; i++) {
|
||||
const comp = comparator(elements[i], first);
|
||||
if (comp > 0) {
|
||||
first = elements[i];
|
||||
}
|
||||
}
|
||||
|
||||
return first;
|
||||
}
|
||||
|
||||
export const DEFAULT_ML_SYNC_CONFIG: MLSyncConfig = {
|
||||
syncIntervalSec: 5, // 300
|
||||
batchSize: 5, // 200
|
||||
|
|
Loading…
Reference in a new issue