Skip to content

Commit 4f34402

Browse files
authored
[pose-detection]Use tfhub link for BlazePose. (#739)
PROCESS
1 parent 4d8d677 commit 4f34402

File tree

4 files changed

+68
-59
lines changed

4 files changed

+68
-59
lines changed

pose-detection/demos/live_video/yarn.lock

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
integrity sha512-vu9V3uMM/1o5Hl5OekMUowo3FqXLJSw+s+66nt0fSWVWTtmosdzn45JHOB3cPtZoe6CTBDzvSw0RdOY85Q37+Q==
1616

1717
"@babel/core@^7.4.4", "@babel/core@^7.7.5":
18-
version "7.14.2"
19-
resolved "https://registry.npmjs.org/@babel/core/-/core-7.14.2.tgz#54e45334ffc0172048e5c93ded36461d3ad4c417"
20-
integrity sha512-OgC1mON+l4U4B4wiohJlQNUU3H73mpTyYY3j/c8U9dr9UagGGSm+WFpzjy/YLdoyjiG++c1kIDgxCo/mLwQJeQ==
18+
version "7.14.3"
19+
resolved "https://registry.npmjs.org/@babel/core/-/core-7.14.3.tgz#5395e30405f0776067fbd9cf0884f15bfb770a38"
20+
integrity sha512-jB5AmTKOCSJIZ72sd78ECEhuPiDMKlQdDI/4QRI6lzYATx5SSogS1oQA2AoPecRCknm30gHi2l+QVvNUu3wZAg==
2121
dependencies:
2222
"@babel/code-frame" "^7.12.13"
23-
"@babel/generator" "^7.14.2"
23+
"@babel/generator" "^7.14.3"
2424
"@babel/helper-compilation-targets" "^7.13.16"
2525
"@babel/helper-module-transforms" "^7.14.2"
2626
"@babel/helpers" "^7.14.0"
27-
"@babel/parser" "^7.14.2"
27+
"@babel/parser" "^7.14.3"
2828
"@babel/template" "^7.12.13"
2929
"@babel/traverse" "^7.14.2"
3030
"@babel/types" "^7.14.2"
@@ -35,10 +35,10 @@
3535
semver "^6.3.0"
3636
source-map "^0.5.0"
3737

38-
"@babel/generator@^7.14.2", "@babel/generator@^7.4.4":
39-
version "7.14.2"
40-
resolved "https://registry.npmjs.org/@babel/generator/-/generator-7.14.2.tgz#d5773e8b557d421fd6ce0d5efa5fd7fc22567c30"
41-
integrity sha512-OnADYbKrffDVai5qcpkMxQ7caomHOoEwjkouqnN2QhydAjowFAZcsdecFIRUBdb+ZcruwYE4ythYmF1UBZU5xQ==
38+
"@babel/generator@^7.14.2", "@babel/generator@^7.14.3", "@babel/generator@^7.4.4":
39+
version "7.14.3"
40+
resolved "https://registry.npmjs.org/@babel/generator/-/generator-7.14.3.tgz#0c2652d91f7bddab7cccc6ba8157e4f40dcedb91"
41+
integrity sha512-bn0S6flG/j0xtQdz3hsjJ624h3W0r3llttBMfyHX3YrZ/KtLYr15bjA0FXkgW7FpvrDuTuElXeVjiKlYRpnOFA==
4242
dependencies:
4343
"@babel/types" "^7.14.2"
4444
jsesc "^2.5.1"
@@ -69,22 +69,22 @@
6969
browserslist "^4.14.5"
7070
semver "^6.3.0"
7171

72-
"@babel/helper-create-class-features-plugin@^7.13.0", "@babel/helper-create-class-features-plugin@^7.14.0":
73-
version "7.14.2"
74-
resolved "https://registry.npmjs.org/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.14.2.tgz#4e455b0329af29c2d3ad254b5dd5aed34595385d"
75-
integrity sha512-6YctwVsmlkchxfGUogvVrrhzyD3grFJyluj5JgDlQrwfMLJSt5tdAzFZfPf4H2Xoi5YLcQ6BxfJlaOBHuctyIw==
72+
"@babel/helper-create-class-features-plugin@^7.13.0", "@babel/helper-create-class-features-plugin@^7.14.0", "@babel/helper-create-class-features-plugin@^7.14.3":
73+
version "7.14.3"
74+
resolved "https://registry.npmjs.org/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.14.3.tgz#832111bcf4f57ca57a4c5b1a000fc125abc6554a"
75+
integrity sha512-BnEfi5+6J2Lte9LeiL6TxLWdIlEv9Woacc1qXzXBgbikcOzMRM2Oya5XGg/f/ngotv1ej2A/b+3iJH8wbS1+lQ==
7676
dependencies:
7777
"@babel/helper-annotate-as-pure" "^7.12.13"
7878
"@babel/helper-function-name" "^7.14.2"
7979
"@babel/helper-member-expression-to-functions" "^7.13.12"
8080
"@babel/helper-optimise-call-expression" "^7.12.13"
81-
"@babel/helper-replace-supers" "^7.13.12"
81+
"@babel/helper-replace-supers" "^7.14.3"
8282
"@babel/helper-split-export-declaration" "^7.12.13"
8383

8484
"@babel/helper-create-regexp-features-plugin@^7.12.13":
85-
version "7.12.17"
86-
resolved "https://registry.npmjs.org/@babel/helper-create-regexp-features-plugin/-/helper-create-regexp-features-plugin-7.12.17.tgz#a2ac87e9e319269ac655b8d4415e94d38d663cb7"
87-
integrity sha512-p2VGmBu9oefLZ2nQpgnEnG0ZlRPvL8gAGvPUMQwUdaE8k49rOMuZpOwdQoy5qJf6K8jL3bcAMhVUlHAjIgJHUg==
85+
version "7.14.3"
86+
resolved "https://registry.npmjs.org/@babel/helper-create-regexp-features-plugin/-/helper-create-regexp-features-plugin-7.14.3.tgz#149aa6d78c016e318c43e2409a0ae9c136a86688"
87+
integrity sha512-JIB2+XJrb7v3zceV2XzDhGIB902CmKGSpSl4q2C6agU9SNLG/2V1RtFRGPG1Ajh9STj3+q6zJMOC+N/pp2P9DA==
8888
dependencies:
8989
"@babel/helper-annotate-as-pure" "^7.12.13"
9090
regexpu-core "^4.7.1"
@@ -183,15 +183,15 @@
183183
"@babel/helper-wrap-function" "^7.13.0"
184184
"@babel/types" "^7.13.0"
185185

186-
"@babel/helper-replace-supers@^7.12.13", "@babel/helper-replace-supers@^7.13.12":
187-
version "7.13.12"
188-
resolved "https://registry.npmjs.org/@babel/helper-replace-supers/-/helper-replace-supers-7.13.12.tgz#6442f4c1ad912502481a564a7386de0c77ff3804"
189-
integrity sha512-Gz1eiX+4yDO8mT+heB94aLVNCL+rbuT2xy4YfyNqu8F+OI6vMvJK891qGBTqL9Uc8wxEvRW92Id6G7sDen3fFw==
186+
"@babel/helper-replace-supers@^7.12.13", "@babel/helper-replace-supers@^7.13.12", "@babel/helper-replace-supers@^7.14.3":
187+
version "7.14.3"
188+
resolved "https://registry.npmjs.org/@babel/helper-replace-supers/-/helper-replace-supers-7.14.3.tgz#ca17b318b859d107f0e9b722d58cf12d94436600"
189+
integrity sha512-Rlh8qEWZSTfdz+tgNV/N4gz1a0TMNwCUcENhMjHTHKp3LseYH5Jha0NSlyTQWMnjbYcwFt+bqAMqSLHVXkQ6UA==
190190
dependencies:
191191
"@babel/helper-member-expression-to-functions" "^7.13.12"
192192
"@babel/helper-optimise-call-expression" "^7.12.13"
193-
"@babel/traverse" "^7.13.0"
194-
"@babel/types" "^7.13.12"
193+
"@babel/traverse" "^7.14.2"
194+
"@babel/types" "^7.14.2"
195195

196196
"@babel/helper-simple-access@^7.13.12":
197197
version "7.13.12"
@@ -252,10 +252,10 @@
252252
chalk "^2.0.0"
253253
js-tokens "^4.0.0"
254254

255-
"@babel/parser@^7.12.13", "@babel/parser@^7.14.2", "@babel/parser@^7.4.4":
256-
version "7.14.2"
257-
resolved "https://registry.npmjs.org/@babel/parser/-/parser-7.14.2.tgz#0c1680aa44ad4605b16cbdcc5c341a61bde9c746"
258-
integrity sha512-IoVDIHpsgE/fu7eXBeRWt8zLbDrSvD7H1gpomOkPpBoEN8KCruCqSDdqo8dddwQQrui30KSvQBaMUOJiuFu6QQ==
255+
"@babel/parser@^7.12.13", "@babel/parser@^7.14.2", "@babel/parser@^7.14.3", "@babel/parser@^7.4.4":
256+
version "7.14.3"
257+
resolved "https://registry.npmjs.org/@babel/parser/-/parser-7.14.3.tgz#9b530eecb071fd0c93519df25c5ff9f14759f298"
258+
integrity sha512-7MpZDIfI7sUC5zWo2+foJ50CSI5lcqDehZ0lVgIhSi4bFEk94fLAKlF3Q0nzSQQ+ca0lm+O6G9ztKVBeu8PMRQ==
259259

260260
"@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining@^7.13.12":
261261
version "7.13.12"
@@ -284,10 +284,11 @@
284284
"@babel/helper-plugin-utils" "^7.13.0"
285285

286286
"@babel/plugin-proposal-class-static-block@^7.13.11":
287-
version "7.13.11"
288-
resolved "https://registry.npmjs.org/@babel/plugin-proposal-class-static-block/-/plugin-proposal-class-static-block-7.13.11.tgz#6fcbba4a962702c17e5371a0c7b39afde186d703"
289-
integrity sha512-fJTdFI4bfnMjvxJyNuaf8i9mVcZ0UhetaGEUHaHV9KEnibLugJkZAtXikR8KcYj+NYmI4DZMS8yQAyg+hvfSqg==
287+
version "7.14.3"
288+
resolved "https://registry.npmjs.org/@babel/plugin-proposal-class-static-block/-/plugin-proposal-class-static-block-7.14.3.tgz#5a527e2cae4a4753119c3a3e7f64ecae8ccf1360"
289+
integrity sha512-HEjzp5q+lWSjAgJtSluFDrGGosmwTgKwCXdDQZvhKsRlwv3YdkUEqxNrrjesJd+B9E9zvr1PVPVBvhYZ9msjvQ==
290290
dependencies:
291+
"@babel/helper-create-class-features-plugin" "^7.14.3"
291292
"@babel/helper-plugin-utils" "^7.13.0"
292293
"@babel/plugin-syntax-class-static-block" "^7.12.13"
293294

@@ -697,15 +698,15 @@
697698
"@babel/helper-plugin-utils" "^7.12.13"
698699

699700
"@babel/plugin-transform-react-jsx@^7.0.0":
700-
version "7.13.12"
701-
resolved "https://registry.npmjs.org/@babel/plugin-transform-react-jsx/-/plugin-transform-react-jsx-7.13.12.tgz#1df5dfaf0f4b784b43e96da6f28d630e775f68b3"
702-
integrity sha512-jcEI2UqIcpCqB5U5DRxIl0tQEProI2gcu+g8VTIqxLO5Iidojb4d77q+fwGseCvd8af/lJ9masp4QWzBXFE2xA==
701+
version "7.14.3"
702+
resolved "https://registry.npmjs.org/@babel/plugin-transform-react-jsx/-/plugin-transform-react-jsx-7.14.3.tgz#0e26597805cf0862da735f264550933c38babb66"
703+
integrity sha512-uuxuoUNVhdgYzERiHHFkE4dWoJx+UFVyuAl0aqN8P2/AKFHwqgUC5w2+4/PjpKXJsFgBlYAFXlUmDQ3k3DUkXw==
703704
dependencies:
704705
"@babel/helper-annotate-as-pure" "^7.12.13"
705706
"@babel/helper-module-imports" "^7.13.12"
706707
"@babel/helper-plugin-utils" "^7.13.0"
707708
"@babel/plugin-syntax-jsx" "^7.12.13"
708-
"@babel/types" "^7.13.12"
709+
"@babel/types" "^7.14.2"
709710

710711
"@babel/plugin-transform-regenerator@^7.13.15":
711712
version "7.13.15"
@@ -722,9 +723,9 @@
722723
"@babel/helper-plugin-utils" "^7.12.13"
723724

724725
"@babel/plugin-transform-runtime@^7.7.6":
725-
version "7.14.2"
726-
resolved "https://registry.npmjs.org/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.14.2.tgz#4e24389bd680dd94ea1b871465d00112ae974425"
727-
integrity sha512-LyA2AiPkaYzI7G5e2YI4NCasTfFe7mZvlupNprDOB7CdNUHb2DQC4uV6oeZ0396gOcicUzUCh0MShL6wiUgk+Q==
726+
version "7.14.3"
727+
resolved "https://registry.npmjs.org/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.14.3.tgz#1fd885a2d0de1d3c223795a4e9be72c2db4515cf"
728+
integrity sha512-t960xbi8wpTFE623ef7sd+UpEC5T6EEguQlTBJDEO05+XwnIWVfuqLw/vdLWY6IdFmtZE+65CZAfByT39zRpkg==
728729
dependencies:
729730
"@babel/helper-module-imports" "^7.13.12"
730731
"@babel/helper-plugin-utils" "^7.13.0"
@@ -918,9 +919,9 @@
918919
integrity sha512-trnsAYxU3xnS1gPHPyU961coFyLkh4gAD/0zQ5mymY4yOZ+CYvsPqUbOFSw0aDM4y0tV7tiFxL/1XfXPNC6IPg==
919920

920921
"@mediapipe/pose@~0.3.0":
921-
version "0.3.1620676110"
922-
resolved "https://registry.npmjs.org/@mediapipe/pose/-/pose-0.3.1620676110.tgz#35d522196db581e213259fbc42290a577bd239ed"
923-
integrity sha512-macv7l2fuaqLArYvUSuoUrxoOVut4KEFHEqPU0i6SLpfohJFhBRgpJXiy8w+KTWkdh0e7cTLkPTESiV2+u9tNA==
922+
version "0.3.1621277220"
923+
resolved "https://registry.npmjs.org/@mediapipe/pose/-/pose-0.3.1621277220.tgz#cd042b5b4c9729e0d7e2217cee24fa096e66ed39"
924+
integrity sha512-YNM0PhcFXbtnKHl1juH4YVd0HpQaylu3HvdPgg42Mq5P6uAQ05KjL79BGcZGKtE+Fn8pYnMYVH1DG6N2beKsrQ==
924925

925926
"@mrmlnc/readdir-enhanced@^2.2.1":
926927
version "2.2.1"
@@ -2730,12 +2731,12 @@ dom-serializer@0:
27302731
entities "^2.0.0"
27312732

27322733
dom-serializer@^1.0.1:
2733-
version "1.3.1"
2734-
resolved "https://registry.npmjs.org/dom-serializer/-/dom-serializer-1.3.1.tgz#d845a1565d7c041a95e5dab62184ab41e3a519be"
2735-
integrity sha512-Pv2ZluG5ife96udGgEDovOOOA5UELkltfJpnIExPrAk1LTvecolUGn6lIaoLh86d83GiB86CjzciMd9BuRB71Q==
2734+
version "1.3.2"
2735+
resolved "https://registry.npmjs.org/dom-serializer/-/dom-serializer-1.3.2.tgz#6206437d32ceefaec7161803230c7a20bc1b4d91"
2736+
integrity sha512-5c54Bk5Dw4qAxNOI1pFEizPSjVsx5+bpJKmL2kPn8JhBUq2q09tTCa3mjijun2NfK78NMouDYNMBkOrPZiS+ig==
27362737
dependencies:
27372738
domelementtype "^2.0.1"
2738-
domhandler "^4.0.0"
2739+
domhandler "^4.2.0"
27392740
entities "^2.0.0"
27402741

27412742
domain-browser@^1.1.1:
@@ -2829,9 +2830,9 @@ [email protected]:
28292830
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=
28302831

28312832
electron-to-chromium@^1.3.47, electron-to-chromium@^1.3.723:
2832-
version "1.3.728"
2833-
resolved "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.728.tgz#dbedd6373f595ae10a13d146b66bece4c1afa5bd"
2834-
integrity sha512-SHv4ziXruBpb1Nz4aTuqEHBYi/9GNCJMYIJgDEXrp/2V01nFXMNFUTli5Z85f5ivSkioLilQatqBYFB44wNJrA==
2833+
version "1.3.734"
2834+
resolved "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.734.tgz#c8d318a4eb27509190cf3a08870dbcbf06c74dcb"
2835+
integrity sha512-iQF2mjPZ6zNNq45kbJ6MYZYCBNdv2JpGiJC/lVx4tGJWi9MNg73KkL9sWGN4X4I/CP2SBLWsT8nPADZZpAHIyw==
28352836

28362837
elliptic@^6.5.3:
28372838
version "6.5.4"

pose-detection/src/blazepose_tfjs/calculators/refine_landmarks_from_heatmap.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ export async function refineLandmarksFromHeatmap(
4646
if (landmarks.length !== hmChannels) {
4747
throw new Error(
4848
'Expected heatmap to have same number of channels ' +
49-
'as the number of landmarks.');
49+
'as the number of landmarks. But got landmarks length: ' +
50+
`${landmarks.length}, heatmap length: ${hmChannels}`);
5051
}
5152

5253
const outLandmarks = [];

pose-detection/src/blazepose_tfjs/constants.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
import {BlazePoseTfjsModelConfig} from './types';
1919

2020
export const DEFAULT_BLAZEPOSE_DETECTOR_MODEL_URL =
21-
'https://storage.googleapis.com/tfjs-models/savedmodel/blazepose/detector/f16/model.json';
21+
'https://tfhub.dev/mediapipe/tfjs-model/blazeposedetector/1/default/1';
2222
export const DEFAULT_BLAZEPOSE_LANDMARK_MODEL_URL_FULL =
23-
'https://storage.googleapis.com/tfjs-models/savedmodel/blazepose/landmark/full-f16/model.json';
23+
'https://tfhub.dev/mediapipe/tfjs-model/blazeposelandmark_full/1/default/1';
2424
export const DEFAULT_BLAZEPOSE_LANDMARK_MODEL_URL_LITE =
25-
'https://storage.googleapis.com/tfjs-models/savedmodel/blazepose/landmark/lite-f16/model.json';
25+
'https://tfhub.dev/mediapipe/tfjs-model/blazeposelandmark_lite/1/default/1';
2626
export const DEFAULT_BLAZEPOSE_LANDMARK_MODEL_URL_HEAVY =
27-
'https://storage.googleapis.com/tfjs-models/savedmodel/blazepose/landmark/heavy-f16/model.json';
27+
'https://tfhub.dev/mediapipe/tfjs-model/blazeposelandmark_heavy/1/default/1';
2828
export const BLAZEPOSE_DETECTOR_ANCHOR_CONFIGURATION = {
2929
reduceBoxesInLowestlayer: false,
3030
interpolatedScaleAspectRatio: 1.0,

pose-detection/src/blazepose_tfjs/detector.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,9 @@ class BlazePoseTfjsDetector implements PoseDetector {
308308
// Output [1]: This tensor (shape: [1, 64, 64, 39]) represents heatmap for
309309
// the 39 landmarks.
310310
// Lite model:
311-
// Output[4]: This tensor (shape: [1, 195]) represents 39 5-d keypoints.
312-
// Output[3]: This tensor (shape: [1, 1]) represents the confidence score.
313-
// Output[1]: This tensor (shape: [1, 64, 64, 39]) represents heatmap for
311+
// Output[2]: This tensor (shape: [1, 195]) represents 39 5-d keypoints.
312+
// Output[4]: This tensor (shape: [1, 1]) represents the confidence score.
313+
// Output[3]: This tensor (shape: [1, 64, 64, 39]) represents heatmap for
314314
// the 39 landmarks.
315315
// Heavy model:
316316
// Output[3]: This tensor (shape: [1, 195]) represents 39 5-d keypoints.
@@ -324,9 +324,9 @@ class BlazePoseTfjsDetector implements PoseDetector {
324324

325325
switch (this.modelType) {
326326
case 'lite':
327-
landmarkTensor = landmarkResult[3] as tf.Tensor2D;
327+
landmarkTensor = landmarkResult[2] as tf.Tensor2D;
328328
poseFlagTensor = landmarkResult[4] as tf.Tensor2D;
329-
heatmapTensor = landmarkResult[1] as tf.Tensor4D;
329+
heatmapTensor = landmarkResult[3] as tf.Tensor4D;
330330
break;
331331
case 'full':
332332
landmarkTensor = landmarkResult[4] as tf.Tensor2D;
@@ -487,9 +487,16 @@ export async function load(modelConfig: BlazePoseTfjsModelConfig):
487487
Promise<PoseDetector> {
488488
const config = validateModelConfig(modelConfig);
489489

490+
const detectorFromTFHub =
491+
(config.detectorModelUrl.indexOf('https://tfhub.dev') > -1);
492+
const landmarkFromTFHub =
493+
(config.landmarkModelUrl.indexOf('https://tfhub.dev') > -1);
494+
490495
const [detectorModel, landmarkModel] = await Promise.all([
491-
tfconv.loadGraphModel(config.detectorModelUrl),
492-
tfconv.loadGraphModel(config.landmarkModelUrl)
496+
tfconv.loadGraphModel(
497+
config.detectorModelUrl, {fromTFHub: detectorFromTFHub}),
498+
tfconv.loadGraphModel(
499+
config.landmarkModelUrl, {fromTFHub: landmarkFromTFHub})
493500
]);
494501

495502
return new BlazePoseTfjsDetector(

0 commit comments

Comments
 (0)