diff --git a/mediapipe/tasks/web/core/task_runner.ts b/mediapipe/tasks/web/core/task_runner.ts index 8d483d9ff..b6babe730 100644 --- a/mediapipe/tasks/web/core/task_runner.ts +++ b/mediapipe/tasks/web/core/task_runner.ts @@ -84,9 +84,6 @@ export abstract class TaskRunner { // Disables the automatic render-to-screen code, which allows for pure // CPU processing. this.graphRunner.setAutoRenderToScreen(false); - - // Enables use of our model resource caching graph service. - this.graphRunner.registerModelResourcesGraphService(); } /** Configures the task with custom options. */ @@ -149,6 +146,11 @@ export abstract class TaskRunner { this.graphRunner.attachErrorListener((code, message) => { this.processingErrors.push(new Error(message)); }); + + // Enables use of our model resource caching graph service; we apply this to + // every MediaPipe graph we run. + this.graphRunner.registerModelResourcesGraphService(); + this.graphRunner.setGraph(graphData, isBinary); this.handleErrors(); } diff --git a/mediapipe/tasks/web/core/task_runner_test.ts b/mediapipe/tasks/web/core/task_runner_test.ts index 9a8aa32eb..1276c2c9a 100644 --- a/mediapipe/tasks/web/core/task_runner_test.ts +++ b/mediapipe/tasks/web/core/task_runner_test.ts @@ -40,7 +40,6 @@ class TaskRunnerFake extends TaskRunner { 'registerModelResourcesGraphService', 'attachErrorListener' ])); const graphRunner = this.graphRunner as jasmine.SpyObj; - expect(graphRunner.registerModelResourcesGraphService).toHaveBeenCalled(); expect(graphRunner.setAutoRenderToScreen).toHaveBeenCalled(); graphRunner.attachErrorListener.and.callFake(listener => { this.errorListener = listener; @@ -65,6 +64,8 @@ class TaskRunnerFake extends TaskRunner { override setGraph(graphData: Uint8Array, isBinary: boolean): void { super.setGraph(graphData, isBinary); + expect(this.graphRunner.registerModelResourcesGraphService) + .toHaveBeenCalled(); } setOptions(options: TaskRunnerOptions): Promise {