Remove generic Options template argument from TaskRunner

PiperOrigin-RevId: 493462947
This commit is contained in:
Sebastian Schmidt 2022-12-06 18:02:35 -08:00 committed by Copybara-Service
parent 576c6da173
commit 1167f61f98
6 changed files with 11 additions and 18 deletions

View File

@ -7,8 +7,5 @@ package(default_visibility = ["//mediapipe/tasks:internal"])
mediapipe_ts_library(
name = "audio_task_runner",
srcs = ["audio_task_runner.ts"],
deps = [
"//mediapipe/tasks/web/core",
"//mediapipe/tasks/web/core:task_runner",
],
deps = ["//mediapipe/tasks/web/core:task_runner"],
)

View File

@ -15,10 +15,9 @@
*/
import {TaskRunner} from '../../../../tasks/web/core/task_runner';
import {TaskRunnerOptions} from '../../../../tasks/web/core/task_runner_options';
/** Base class for all MediaPipe Audio Tasks. */
export abstract class AudioTaskRunner<T> extends TaskRunner<TaskRunnerOptions> {
export abstract class AudioTaskRunner<T> extends TaskRunner {
private defaultSampleRate = 48000;
/**

View File

@ -37,10 +37,9 @@ export class GraphRunnerImageLib extends GraphRunnerImageLibType {}
* supported and loads the relevant WASM binary.
* @return A fully instantiated instance of `T`.
*/
export async function
createTaskRunner<T extends TaskRunner<O>, O extends TaskRunnerOptions>(
export async function createTaskRunner<T extends TaskRunner>(
type: WasmMediaPipeConstructor<T>, initializeCanvas: boolean,
fileset: WasmFileset, options: O): Promise<T> {
fileset: WasmFileset, options: TaskRunnerOptions): Promise<T> {
const fileLocator: FileLocator = {
locateFile() {
// The only file loaded with this mechanism is the Wasm binary
@ -61,7 +60,7 @@ createTaskRunner<T extends TaskRunner<O>, O extends TaskRunnerOptions>(
}
/** Base class for all MediaPipe Tasks. */
export abstract class TaskRunner<O extends TaskRunnerOptions> {
export abstract class TaskRunner {
protected abstract baseOptions: BaseOptionsProto;
protected graphRunner: GraphRunnerImageLib;
private processingErrors: Error[] = [];
@ -71,10 +70,9 @@ export abstract class TaskRunner<O extends TaskRunnerOptions> {
* supported and loads the relevant WASM binary.
* @return A fully instantiated instance of `T`.
*/
protected static async createInstance<T extends TaskRunner<O>,
O extends TaskRunnerOptions>(
protected static async createInstance<T extends TaskRunner>(
type: WasmMediaPipeConstructor<T>, initializeCanvas: boolean,
fileset: WasmFileset, options: O): Promise<T> {
fileset: WasmFileset, options: TaskRunnerOptions): Promise<T> {
return createTaskRunner(type, initializeCanvas, fileset, options);
}
@ -92,7 +90,7 @@ export abstract class TaskRunner<O extends TaskRunnerOptions> {
}
/** Configures the shared options of a MediaPipe Task. */
async setOptions(options: O): Promise<void> {
async setOptions(options: TaskRunnerOptions): Promise<void> {
if (options.baseOptions) {
this.baseOptions = await convertBaseOptionsToProto(
options.baseOptions, this.baseOptions);

View File

@ -41,7 +41,7 @@ const TEXT_CLASSIFIER_GRAPH =
// tslint:disable:jspb-use-builder-pattern
/** Performs Natural Language classification. */
export class TextClassifier extends TaskRunner<TextClassifierOptions> {
export class TextClassifier extends TaskRunner {
private classificationResult: TextClassifierResult = {classifications: []};
private readonly options = new TextClassifierGraphOptions();

View File

@ -45,7 +45,7 @@ const TEXT_EMBEDDER_CALCULATOR =
/**
* Performs embedding extraction on text.
*/
export class TextEmbedder extends TaskRunner<TextEmbedderOptions> {
export class TextEmbedder extends TaskRunner {
private embeddingResult: TextEmbedderResult = {embeddings: []};
private readonly options = new TextEmbedderGraphOptionsProto();

View File

@ -20,8 +20,7 @@ import {ImageSource} from '../../../../web/graph_runner/graph_runner';
import {VisionTaskOptions} from './vision_task_options';
/** Base class for all MediaPipe Vision Tasks. */
export abstract class VisionTaskRunner<T> extends
TaskRunner<VisionTaskOptions> {
export abstract class VisionTaskRunner<T> extends TaskRunner {
/** Configures the shared options of a vision task. */
override async setOptions(options: VisionTaskOptions): Promise<void> {
await super.setOptions(options);