diff --git a/CHANGELOG.md b/CHANGELOG.md index d57f6e75..9ca681a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,10 @@ ## Changelog -### **HEAD -> main** 2022/01/05 mandic00@live.com +### **2.5.8** 2022/01/14 mandic00@live.com + + +### **origin/main** 2022/01/08 mandic00@live.com - fix samples - fix(src): typo diff --git a/src/face/facemesh.ts b/src/face/facemesh.ts index eb418dd9..e37c6cd1 100644 --- a/src/face/facemesh.ts +++ b/src/face/facemesh.ts @@ -101,7 +101,8 @@ export async function predict(input: Tensor, config: Config): Promise (config.face.detector?.minConfidence || 1)) faces.push(face); + else tf.dispose(face.tensor); } cache.boxes = newCache; // reset cache return faces; diff --git a/src/hand/handtrack.ts b/src/hand/handtrack.ts index d90f3b95..f6621e66 100644 --- a/src/hand/handtrack.ts +++ b/src/hand/handtrack.ts @@ -38,7 +38,6 @@ type HandDetectResult = { score: number, box: Box, boxRaw: Box, - boxCrop: Box, label: HandType, } @@ -121,10 +120,11 @@ async function detectHands(input: Tensor, config: Config): Promise tf.dispose(t[tensor])); @@ -163,7 +161,8 @@ async function detectFingers(input: Tensor, h: HandDetectResult, config: Config) }; if (input && models[1] && config.hand.landmarks && h.score > (config.hand.minConfidence || 0)) { const t: Record = {}; - t.crop = tf.image.cropAndResize(input, [h.boxCrop], [0], [inputSize[1][0], inputSize[1][1]], 'bilinear'); + const boxCrop = [h.boxRaw[1], h.boxRaw[0], h.boxRaw[3] + h.boxRaw[1], h.boxRaw[2] + h.boxRaw[0]] as Box; + t.crop = tf.image.cropAndResize(input, [boxCrop], [0], [inputSize[1][0], inputSize[1][1]], 'bilinear'); t.div = tf.div(t.crop, constants.tf255); [t.score, t.keypoints] = models[1].execute(t.div, ['Identity_1', 'Identity']) as Tensor[]; const rawScore = (await t.score.data())[0]; @@ -174,11 +173,7 @@ async function detectFingers(input: Tensor, h: HandDetectResult, config: Config) const coordsData: Point[] = await t.reshaped.array() as Point[]; const coordsRaw: Point[] = coordsData.map((kpt) => [kpt[0] / inputSize[1][1], kpt[1] / inputSize[1][0], (kpt[2] || 0)]); const coordsNorm: Point[] = coordsRaw.map((kpt) => [kpt[0] * h.boxRaw[2], kpt[1] * h.boxRaw[3], (kpt[2] || 0)]); - hand.keypoints = (coordsNorm).map((kpt) => [ - outputSize[0] * (kpt[0] + h.boxRaw[0]), - outputSize[1] * (kpt[1] + h.boxRaw[1]), - (kpt[2] || 0), - ]); + hand.keypoints = (coordsNorm).map((kpt) => [outputSize[0] * (kpt[0] + h.boxRaw[0]), outputSize[1] * (kpt[1] + h.boxRaw[1]), (kpt[2] || 0)]); hand.landmarks = fingerPose.analyze(hand.keypoints) as HandResult['landmarks']; // calculate finger gestures for (const key of Object.keys(fingerMap)) { // map keypoints to per-finger annotations hand.annotations[key] = fingerMap[key].map((index: number) => (hand.landmarks && hand.keypoints[index] ? hand.keypoints[index] : null)); @@ -220,8 +215,8 @@ export async function predict(input: Tensor, config: Config): Promise 0.05 && boxKpt.box[3] / (input.shape[1] || 1) > 0.05 && cache.hands[i].fingerScore && cache.hands[i].fingerScore > (config.hand.minConfidence || 0)) { const boxScale = box.scale(boxKpt.box, boxExpandFact); const boxScaleRaw = box.scale(boxKpt.boxRaw, boxExpandFact); - const boxCrop = box.crop(boxScaleRaw); - cache.boxes.push({ ...oldCache[i], box: boxScale, boxRaw: boxScaleRaw, boxCrop }); + // const boxCrop = box.crop(boxScaleRaw); + cache.boxes.push({ ...oldCache[i], box: boxScale, boxRaw: boxScaleRaw }); } } }