Skip to content

Commit b449e79

Browse files
authored
Fix mediapipe obfuscated package export name (#950)
* Fix mediapipe obfuscated package export name * Change window to globalThis
1 parent 70848f5 commit b449e79

File tree

14 files changed

+73
-51
lines changed

14 files changed

+73
-51
lines changed

body-segmentation/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ For example:
3131
const model = bodySegmentation.SupportedModels.MediaPipeSelfieSegmentation;
3232
const segmenterConfig = {
3333
runtime: 'mediapipe', // or 'tfjs'
34+
solutionPath: 'https://cdn.jsdelivr.net/npm/@mediapipe/selfie_segmentation',
3435
modelType: 'general'
3536
}
3637
const segmenter = await bodySegmentation.createSegmenter(model, segmenterConfig);

body-segmentation/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tensorflow-models/body-segmentation",
3-
"version": "0.0.1",
3+
"version": "1.0.0",
44
"description": "Pretrained body segmentation model",
55
"main": "dist/index.js",
66
"jsnext:main": "dist/body-segmentation.esm.js",

body-segmentation/rollup.config.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const PREAMBLE = `/**
3636
* =============================================================================
3737
*/`;
3838

39-
function config({ plugins = [], output = {}, tsCompilerOptions = {} }) {
39+
function config({plugins = [], output = {}, tsCompilerOptions = {}}) {
4040
const defaultTsOptions = {
4141
include: ['src/**/*.ts'],
4242
module: 'ES2015',
@@ -45,36 +45,40 @@ function config({ plugins = [], output = {}, tsCompilerOptions = {} }) {
4545

4646
return {
4747
input: 'src/index.ts',
48-
plugins: [
49-
typescript(tsoptions),
50-
resolve(), ...plugins
51-
],
48+
plugins: [typescript(tsoptions), resolve(), ...plugins],
5249
output: {
5350
banner: PREAMBLE,
5451
globals: {
5552
'@tensorflow/tfjs-core': 'tf',
5653
'@tensorflow/tfjs-converter': 'tf',
57-
'@mediapipe/selfie_segmentation': 'SelfieSegmentation'
54+
// Package is obfuscated so class is directly attached to globalThis.
55+
'@mediapipe/selfie_segmentation': 'globalThis'
5856
},
5957
...output,
6058
},
6159
external: [
62-
'@tensorflow/tfjs-core',
63-
'@tensorflow/tfjs-converter',
60+
'@tensorflow/tfjs-core', '@tensorflow/tfjs-converter',
6461
'@mediapipe/selfie_segmentation'
6562
]
6663
};
6764
}
6865

6966
const packageName = 'bodySegmentation';
7067
export default [
71-
config({ output: { format: 'umd', name: packageName, file: 'dist/body-segmentation.js' } }),
68+
config({
69+
output:
70+
{format: 'umd', name: packageName, file: 'dist/body-segmentation.js'}
71+
}),
7272
config({
7373
plugins: [terser({output: {preamble: PREAMBLE, comments: false}})],
74-
output: { format: 'umd', name: packageName, file: 'dist/body-segmentation.min.js' }
74+
output: {
75+
format: 'umd',
76+
name: packageName,
77+
file: 'dist/body-segmentation.min.js'
78+
}
7579
}),
7680
config({
7781
plugins: [terser({output: {preamble: PREAMBLE, comments: false}})],
78-
output: { format: 'es', file: 'dist/body-segmentation.esm.js' }
82+
output: {format: 'es', file: 'dist/body-segmentation.esm.js'}
7983
})
8084
];

body-segmentation/src/selfie_segmentation_mediapipe/README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ Via script tags:
3434

3535
Via npm:
3636
```sh
37-
yarn add @tensorflow-models/body-segmentation
38-
yarn add @tensorflow/tfjs-core, @tensorflow/tfjs-backend-webgl
3937
yarn add @mediapipe/selfie_segmentation
38+
yarn add @tensorflow/tfjs-core, @tensorflow/tfjs-backend-webgl
39+
yarn add @tensorflow-models/body-segmentation
4040
```
4141

4242
-----------------------------------------------------------------------
@@ -73,7 +73,8 @@ Pass in `bodySegmentation.SupportedModels.MediaPipeSelfieSegmentation` from the
7373
const model = bodySegmentation.SupportedModels.MediaPipeSelfieSegmentation;
7474
const segmenterConfig = {
7575
runtime: 'mediapipe',
76-
solutionPath: 'base/node_modules/@mediapipe/selfie_segmentation'
76+
solutionPath: 'https://cdn.jsdelivr.net/npm/@mediapipe/selfie_segmentation'
77+
// or 'base/node_modules/@mediapipe/selfie_segmentation' in npm.
7778
};
7879
segmenter = await bodySegmentation.createSegmenter(model, segmenterConfig);
7980
```

face-landmarks-detection/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ For example:
2929
const model = faceLandmarksDetection.SupportedModels.MediaPipeFaceMesh;
3030
const detectorConfig = {
3131
runtime: 'mediapipe', // or 'tfjs'
32+
solutionPath: 'https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh',
3233
}
3334
const detector = await faceLandmarksDetection.createDetector(model, detectorConfig);
3435
```

face-landmarks-detection/rollup.config.js

+18-11
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const PREAMBLE = `/**
3636
* =============================================================================
3737
*/`;
3838

39-
function config({ plugins = [], output = {}, tsCompilerOptions = {} }) {
39+
function config({plugins = [], output = {}, tsCompilerOptions = {}}) {
4040
const defaultTsOptions = {
4141
include: ['src/**/*.ts'],
4242
module: 'ES2015',
@@ -45,36 +45,43 @@ function config({ plugins = [], output = {}, tsCompilerOptions = {} }) {
4545

4646
return {
4747
input: 'src/index.ts',
48-
plugins: [
49-
typescript(tsoptions),
50-
resolve(), ...plugins
51-
],
48+
plugins: [typescript(tsoptions), resolve(), ...plugins],
5249
output: {
5350
banner: PREAMBLE,
5451
globals: {
5552
'@tensorflow/tfjs-core': 'tf',
5653
'@tensorflow/tfjs-converter': 'tf',
57-
'@mediapipe/face_mesh': 'faceMesh'
54+
// Package is obfuscated so class is directly attached to globalThis.
55+
'@mediapipe/face_mesh': 'globalThis'
5856
},
5957
...output,
6058
},
6159
external: [
62-
'@tensorflow/tfjs-core',
63-
'@tensorflow/tfjs-converter',
60+
'@tensorflow/tfjs-core', '@tensorflow/tfjs-converter',
6461
'@mediapipe/face_mesh'
6562
]
6663
};
6764
}
6865

6966
const packageName = 'faceLandmarksDetection';
7067
export default [
71-
config({ output: { format: 'umd', name: packageName, file: 'dist/face-landmarks-detection.js' } }),
68+
config({
69+
output: {
70+
format: 'umd',
71+
name: packageName,
72+
file: 'dist/face-landmarks-detection.js'
73+
}
74+
}),
7275
config({
7376
plugins: [terser({output: {preamble: PREAMBLE, comments: false}})],
74-
output: { format: 'umd', name: packageName, file: 'dist/face-landmarks-detection.min.js' }
77+
output: {
78+
format: 'umd',
79+
name: packageName,
80+
file: 'dist/face-landmarks-detection.min.js'
81+
}
7582
}),
7683
config({
7784
plugins: [terser({output: {preamble: PREAMBLE, comments: false}})],
78-
output: { format: 'es', file: 'dist/face-landmarks-detection.esm.js' }
85+
output: {format: 'es', file: 'dist/face-landmarks-detection.esm.js'}
7986
})
8087
];

face-landmarks-detection/src/mediapipe/README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ Via script tags:
3131

3232
Via npm:
3333
```sh
34-
yarn add @tensorflow-models/face-landmarks-detection
35-
yarn add @tensorflow/tfjs-core, @tensorflow/tfjs-backend-webgl
3634
yarn add @mediapipe/face_mesh
35+
yarn add @tensorflow/tfjs-core, @tensorflow/tfjs-backend-webgl
36+
yarn add @tensorflow-models/face-landmarks-detection
3737
```
3838

3939
-----------------------------------------------------------------------
@@ -71,7 +71,8 @@ Pass in `faceLandmarksDetection.SupportedModels.MediaPipeFaceMesh` from the
7171
const model = faceLandmarksDetection.SupportedModels.MediaPipeFaceMesh;
7272
const detectorConfig = {
7373
runtime: 'mediapipe',
74-
solutionPath: 'base/node_modules/@mediapipe/face_mesh'
74+
solutionPath: 'https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh',
75+
// or 'base/node_modules/@mediapipe/face_mesh' in npm.
7576
};
7677
detector = await faceLandmarksDetection.createDetector(model, detectorConfig);
7778
```

hand-pose-detection/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ For example:
2929
```javascript
3030
const model = handPoseDetection.SupportedModels.MediaPipeHands;
3131
const detectorConfig = {
32-
runtime: 'mediapipe', // or 'tfjs'
32+
runtime: 'mediapipe', // or 'tfjs',
33+
solutionPath: 'https://cdn.jsdelivr.net/npm/@mediapipe/hands',
3334
modelType: 'full'
3435
}
3536
const detector = await handPoseDetection.createDetector(model, detectorConfig);

hand-pose-detection/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tensorflow-models/hand-pose-detection",
3-
"version": "1.0.0",
3+
"version": "2.0.0",
44
"description": "Pretrained hand pose detection model",
55
"main": "dist/index.js",
66
"jsnext:main": "dist/hand-pose-detection.esm.js",

hand-pose-detection/rollup.config.js

+15-12
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const PREAMBLE = `/**
3636
* =============================================================================
3737
*/`;
3838

39-
function config({ plugins = [], output = {}, tsCompilerOptions = {} }) {
39+
function config({plugins = [], output = {}, tsCompilerOptions = {}}) {
4040
const defaultTsOptions = {
4141
include: ['src/**/*.ts'],
4242
module: 'ES2015',
@@ -45,36 +45,39 @@ function config({ plugins = [], output = {}, tsCompilerOptions = {} }) {
4545

4646
return {
4747
input: 'src/index.ts',
48-
plugins: [
49-
typescript(tsoptions),
50-
resolve(), ...plugins
51-
],
48+
plugins: [typescript(tsoptions), resolve(), ...plugins],
5249
output: {
5350
banner: PREAMBLE,
5451
globals: {
5552
'@tensorflow/tfjs-core': 'tf',
5653
'@tensorflow/tfjs-converter': 'tf',
57-
'@mediapipe/hands': 'Hands'
54+
// Package is obfuscated so class is directly attached to globalThis.
55+
'@mediapipe/hands': 'globalThis'
5856
},
5957
...output,
6058
},
6159
external: [
62-
'@tensorflow/tfjs-core',
63-
'@tensorflow/tfjs-converter',
64-
'@mediapipe/hands'
60+
'@tensorflow/tfjs-core', '@tensorflow/tfjs-converter', '@mediapipe/hands'
6561
]
6662
};
6763
}
6864

6965
const packageName = 'handPoseDetection';
7066
export default [
71-
config({ output: { format: 'umd', name: packageName, file: 'dist/hand-pose-detection.js' } }),
67+
config({
68+
output:
69+
{format: 'umd', name: packageName, file: 'dist/hand-pose-detection.js'}
70+
}),
7271
config({
7372
plugins: [terser({output: {preamble: PREAMBLE, comments: false}})],
74-
output: { format: 'umd', name: packageName, file: 'dist/hand-pose-detection.min.js' }
73+
output: {
74+
format: 'umd',
75+
name: packageName,
76+
file: 'dist/hand-pose-detection.min.js'
77+
}
7578
}),
7679
config({
7780
plugins: [terser({output: {preamble: PREAMBLE, comments: false}})],
78-
output: { format: 'es', file: 'dist/hand-pose-detection.esm.js' }
81+
output: {format: 'es', file: 'dist/hand-pose-detection.esm.js'}
7982
})
8083
];

hand-pose-detection/src/mediapipe/README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ Via script tags:
3737

3838
Via npm:
3939
```sh
40-
yarn add @tensorflow-models/hand-pose-detection
41-
yarn add @tensorflow/tfjs-core, @tensorflow/tfjs-backend-webgl
4240
yarn add @mediapipe/hands
41+
yarn add @tensorflow/tfjs-core, @tensorflow/tfjs-backend-webgl
42+
yarn add @tensorflow-models/hand-pose-detection
4343
```
4444

4545
-----------------------------------------------------------------------
@@ -78,7 +78,8 @@ Pass in `handPoseDetection.SupportedModels.MediaPipeHands` from the
7878
const model = handPoseDetection.SupportedModels.MediaPipeHands;
7979
const detectorConfig = {
8080
runtime: 'mediapipe',
81-
solutionPath: 'base/node_modules/@mediapipe/hands'
81+
solutionPath: 'https://cdn.jsdelivr.net/npm/@mediapipe/hands'
82+
// or 'base/node_modules/@mediapipe/hands' in npm.
8283
};
8384
detector = await handPoseDetection.createDetector(model, detectorConfig);
8485
```

pose-detection/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tensorflow-models/pose-detection",
3-
"version": "1.0.1",
3+
"version": "2.0.0",
44
"description": "Pretrained pose detection model",
55
"main": "dist/index.js",
66
"jsnext:main": "dist/pose-detection.esm.js",

pose-detection/rollup.config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ function config({plugins = [], output = {}, tsCompilerOptions = {}}) {
5151
globals: {
5252
'@tensorflow/tfjs-core': 'tf',
5353
'@tensorflow/tfjs-converter': 'tf',
54-
'@mediapipe/pose': 'Pose'
54+
// Package is obfuscated so class is directly attached to globalThis.
55+
'@mediapipe/pose': 'globalThis'
5556
},
5657
...output,
5758
},

pose-detection/src/blazepose_mediapipe/README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ Via script tags:
4646
Via npm:
4747

4848
```sh
49-
yarn add @tensorflow-models/pose-detection
50-
yarn add @tensorflow/tfjs-core, @tensorflow/tfjs-backend-webgl
5149
yarn add @mediapipe/pose
50+
yarn add @tensorflow/tfjs-core, @tensorflow/tfjs-backend-webgl
51+
yarn add @tensorflow-models/pose-detection
5252
```
5353

5454
-----------------------------------------------------------------------
@@ -91,7 +91,8 @@ Pass in `poseDetection.SupportedModels.BlazePose` from the
9191
const model = poseDetection.SupportedModels.BlazePose;
9292
const detectorConfig = {
9393
runtime: 'mediapipe',
94-
solutionPath: 'base/node_modules/@mediapipe/pose'
94+
solutionPath: 'https://cdn.jsdelivr.net/npm/@mediapipe/pose'
95+
// or 'base/node_modules/@mediapipe/pose' in npm.
9596
};
9697
detector = await poseDetection.createDetector(model, detectorConfig);
9798
```

0 commit comments

Comments
 (0)