From 39a943e91e8e4e080326bac8a1fa82c8a2716156 Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Fri, 10 Feb 2023 09:32:32 -0800 Subject: [PATCH] Request ModelResourcesGraphService for all Task API web graphs. PiperOrigin-RevId: 508681004 --- mediapipe/tasks/web/core/task_runner.ts | 8 +++++--- mediapipe/tasks/web/core/task_runner_test.ts | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) 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 {