Use centroid of cluster as summary
Increase face detection minConfidence
This commit is contained in:
parent
0ed8df8c17
commit
48388aa125
|
@ -15,7 +15,7 @@ export default function MLDebug() {
|
||||||
const [minClusterSize, setMinClusterSize] = useState<number>(4);
|
const [minClusterSize, setMinClusterSize] = useState<number>(4);
|
||||||
const [minFaceSize, setMinFaceSize] = useState<number>(24);
|
const [minFaceSize, setMinFaceSize] = useState<number>(24);
|
||||||
const [batchSize, setBatchSize] = useState<number>(50);
|
const [batchSize, setBatchSize] = useState<number>(50);
|
||||||
const [maxFaceDistance, setMaxFaceDistance] = useState<number>(0.55);
|
const [maxFaceDistance, setMaxFaceDistance] = useState<number>(0.5);
|
||||||
const [mlResult, setMlResult] = useState<MLSyncResult>({
|
const [mlResult, setMlResult] = useState<MLSyncResult>({
|
||||||
allFaces: [],
|
allFaces: [],
|
||||||
clustersWithNoise: {
|
clustersWithNoise: {
|
||||||
|
|
|
@ -25,6 +25,7 @@ import ClusteringService from './clusteringService';
|
||||||
import './faceEnvPatch';
|
import './faceEnvPatch';
|
||||||
import * as faceapi from 'face-api.js';
|
import * as faceapi from 'face-api.js';
|
||||||
import { euclideanDistance, SsdMobilenetv1Options } from 'face-api.js';
|
import { euclideanDistance, SsdMobilenetv1Options } from 'face-api.js';
|
||||||
|
import { f32Average } from 'utils/machineLearning';
|
||||||
|
|
||||||
class MachineLearningService {
|
class MachineLearningService {
|
||||||
// private faceDetectionService: TFJSFaceDetectionService;
|
// private faceDetectionService: TFJSFaceDetectionService;
|
||||||
|
@ -32,7 +33,7 @@ class MachineLearningService {
|
||||||
private clusteringService: ClusteringService;
|
private clusteringService: ClusteringService;
|
||||||
|
|
||||||
private clusterFaceDistance = 0.4;
|
private clusterFaceDistance = 0.4;
|
||||||
private maxFaceDistance = 0.55;
|
private maxFaceDistance = 0.5;
|
||||||
private minClusterSize = 4;
|
private minClusterSize = 4;
|
||||||
private minFaceSize = 24;
|
private minFaceSize = 24;
|
||||||
private batchSize = 50;
|
private batchSize = 50;
|
||||||
|
@ -87,11 +88,17 @@ class MachineLearningService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private getClusterSummary(cluster: ClusterFaces): FaceDescriptor {
|
private getClusterSummary(cluster: ClusterFaces): FaceDescriptor {
|
||||||
const faceScore = (f) => f.detection.score; // f.alignedRect.box.width *
|
// const faceScore = (f) => f.detection.score; // f.alignedRect.box.width *
|
||||||
|
|
||||||
return cluster
|
// return cluster
|
||||||
.map((f) => this.allFaces[f].face)
|
// .map((f) => this.allFaces[f].face)
|
||||||
.sort((f1, f2) => faceScore(f2) - faceScore(f1))[0].descriptor;
|
// .sort((f1, f2) => faceScore(f2) - faceScore(f1))[0].descriptor;
|
||||||
|
|
||||||
|
const descriptors = cluster.map(
|
||||||
|
(f) => this.allFaces[f].face.descriptor
|
||||||
|
);
|
||||||
|
|
||||||
|
return f32Average(descriptors);
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateClusterSummaries() {
|
private updateClusterSummaries() {
|
||||||
|
@ -271,7 +278,7 @@ class MachineLearningService {
|
||||||
.detectAllFaces(
|
.detectAllFaces(
|
||||||
tfImage as any,
|
tfImage as any,
|
||||||
new SsdMobilenetv1Options({
|
new SsdMobilenetv1Options({
|
||||||
// minConfidence: 0.6
|
minConfidence: 0.75,
|
||||||
// maxResults: 10
|
// maxResults: 10
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
22
src/utils/machineLearning/index.ts
Normal file
22
src/utils/machineLearning/index.ts
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
export function f32Average(descriptors: Float32Array[]) {
|
||||||
|
if (descriptors.length < 1) {
|
||||||
|
throw Error('f32Average: input size 0');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (descriptors.length === 1) {
|
||||||
|
return descriptors[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
const f32Size = descriptors[0].length;
|
||||||
|
const avg = new Float32Array(f32Size);
|
||||||
|
|
||||||
|
for (let index = 0; index < f32Size; index++) {
|
||||||
|
avg[index] = descriptors[0][index];
|
||||||
|
for (let desc = 1; desc < descriptors.length; desc++) {
|
||||||
|
avg[index] = avg[index] + descriptors[desc][index];
|
||||||
|
}
|
||||||
|
avg[index] = avg[index] / descriptors.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
return avg;
|
||||||
|
}
|
Loading…
Reference in a new issue