File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import poseDetection from "./PoseDetection";
4
4
import * as tf from "@tensorflow/tfjs" ;
5
5
import * as tfvis from "@tensorflow/tfjs-vis" ;
6
6
import p5Utils from "./utils/p5Utils" ;
7
+ import setBackend from "./utils/setBackend" ;
7
8
8
9
export default Object . assign (
9
10
{ p5Utils } ,
@@ -13,5 +14,6 @@ export default Object.assign(
13
14
neuralNetwork,
14
15
handpose,
15
16
poseDetection,
17
+ setBackend,
16
18
}
17
19
) ;
Original file line number Diff line number Diff line change
1
+ import * as tf from "@tensorflow/tfjs" ;
2
+
3
+ /**
4
+ * Manually set the Tensorflow.js Backend to the specified backend.
5
+ * Determines how the operation is done for the following features:
6
+ * - handpose under "tfjs" runtime
7
+ * - poseDetection
8
+ * - facemesh
9
+ * - neuralNetwork
10
+ *
11
+ * @param {string } backend the backend to set to. Must be "cpu", "webgl", or "webgpu".
12
+ * @return {boolean } true if the backend was set successfully.
13
+ */
14
+ export default function setBackend ( backend ) {
15
+ switch ( backend ) {
16
+ case "cpu" :
17
+ tf . setBackend ( "cpu" ) ;
18
+ break ;
19
+ case "webgl" :
20
+ tf . setBackend ( "webgl" ) ;
21
+ break ;
22
+ case "webgpu" :
23
+ tf . setBackend ( "webgpu" ) ;
24
+ break ;
25
+ default :
26
+ throw new Error (
27
+ `Invalid backend: ${ backend } . The backend parameter must be set to one of the following strings: "cpu", "webgl", or "webgpu".`
28
+ ) ;
29
+ }
30
+
31
+ return true ;
32
+ }
You can’t perform that action at this time.
0 commit comments