Skip to content

Commit 4621a13

Browse files
authored
Merge pull request #291 from adzhindzhi/UEPR-290-update-face-sensing-configuration
[UEPR-290] Update face sensing configuration
2 parents 5ea903a + 38084d0 commit 4621a13

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/scratch-gui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"watch": "webpack --watch"
5858
},
5959
"dependencies": {
60+
"@mediapipe/face_detection": "0.4.1646425229",
6061
"@microbit/microbit-universal-hex": "0.2.2",
6162
"@tensorflow-models/face-detection": "^1.0.3",
6263
"@tensorflow/tfjs": "^4.22.0",

packages/scratch-gui/webpack.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ const baseConfig = new ScratchWebpackConfigBuilder(
8484
context: '../../node_modules/scratch-storage/dist/web',
8585
from: 'chunks/fetch-worker.*.{js,js.map}',
8686
noErrorOnMissing: true
87+
},
88+
{
89+
from: '../../node_modules/@mediapipe/face_detection',
90+
to: 'chunks/mediapipe/face_detection'
8791
}
8892
]
8993
}));

packages/scratch-vm/src/extensions/scratch3_face_sensing/index.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const TargetType = require('../../extension-support/target-type');
88
// const Posenet = require('@tensorflow-models/posenet');
99

1010
const FaceDetection = require('@tensorflow-models/face-detection');
11+
const mediapipePackage = require('@mediapipe/face_detection/package.json');
1112

1213
/**
1314
* Icon svg to be displayed in the blocks category menu, encoded as a data URI.
@@ -41,16 +42,26 @@ class Scratch3FaceSensingBlocks {
4142
const model = FaceDetection.SupportedModels.MediaPipeFaceDetector;
4243
const detectorConfig = {
4344
runtime: 'mediapipe',
44-
solutionPath: 'https://cdn.jsdelivr.net/npm/@mediapipe/face_detection',
45+
solutionPath: '/chunks/mediapipe/face_detection',
4546
maxFaces: 1
4647
};
4748

48-
FaceDetection.createDetector(model, detectorConfig).then(detector => {
49-
this.faceDetector = detector;
50-
if (this.runtime.ioDevices) {
51-
this._loop();
52-
}
53-
});
49+
FaceDetection.createDetector(model, detectorConfig)
50+
.catch(() => {
51+
const fallbackConfig = {
52+
runtime: 'mediapipe',
53+
solutionPath: `https://cdn.jsdelivr.net/npm/@mediapipe/face_detection@${mediapipePackage.version}`,
54+
maxFaces: 1
55+
};
56+
57+
return FaceDetection.createDetector(model, fallbackConfig);
58+
})
59+
.then(detector => {
60+
this.faceDetector = detector;
61+
if (this.runtime.ioDevices) {
62+
this._loop();
63+
}
64+
});
5465

5566
this.cachedSize = 100;
5667
this.cachedTilt = 90;

0 commit comments

Comments
 (0)