Request ModelResourcesGraphService for all Task API web graphs.

PiperOrigin-RevId: 508681004
This commit is contained in:
MediaPipe Team 2023-02-10 09:32:32 -08:00 committed by Copybara-Service
parent 915d2c7417
commit 39a943e91e
2 changed files with 7 additions and 4 deletions

View File

@ -84,9 +84,6 @@ export abstract class TaskRunner {
// Disables the automatic render-to-screen code, which allows for pure // Disables the automatic render-to-screen code, which allows for pure
// CPU processing. // CPU processing.
this.graphRunner.setAutoRenderToScreen(false); this.graphRunner.setAutoRenderToScreen(false);
// Enables use of our model resource caching graph service.
this.graphRunner.registerModelResourcesGraphService();
} }
/** Configures the task with custom options. */ /** Configures the task with custom options. */
@ -149,6 +146,11 @@ export abstract class TaskRunner {
this.graphRunner.attachErrorListener((code, message) => { this.graphRunner.attachErrorListener((code, message) => {
this.processingErrors.push(new Error(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.graphRunner.setGraph(graphData, isBinary);
this.handleErrors(); this.handleErrors();
} }

View File

@ -40,7 +40,6 @@ class TaskRunnerFake extends TaskRunner {
'registerModelResourcesGraphService', 'attachErrorListener' 'registerModelResourcesGraphService', 'attachErrorListener'
])); ]));
const graphRunner = this.graphRunner as jasmine.SpyObj<CachedGraphRunner>; const graphRunner = this.graphRunner as jasmine.SpyObj<CachedGraphRunner>;
expect(graphRunner.registerModelResourcesGraphService).toHaveBeenCalled();
expect(graphRunner.setAutoRenderToScreen).toHaveBeenCalled(); expect(graphRunner.setAutoRenderToScreen).toHaveBeenCalled();
graphRunner.attachErrorListener.and.callFake(listener => { graphRunner.attachErrorListener.and.callFake(listener => {
this.errorListener = listener; this.errorListener = listener;
@ -65,6 +64,8 @@ class TaskRunnerFake extends TaskRunner {
override setGraph(graphData: Uint8Array, isBinary: boolean): void { override setGraph(graphData: Uint8Array, isBinary: boolean): void {
super.setGraph(graphData, isBinary); super.setGraph(graphData, isBinary);
expect(this.graphRunner.registerModelResourcesGraphService)
.toHaveBeenCalled();
} }
setOptions(options: TaskRunnerOptions): Promise<void> { setOptions(options: TaskRunnerOptions): Promise<void> {