Remove generic Options template argument from TaskRunner
PiperOrigin-RevId: 493462947
This commit is contained in:
parent
576c6da173
commit
1167f61f98
|
@ -7,8 +7,5 @@ package(default_visibility = ["//mediapipe/tasks:internal"])
|
||||||
mediapipe_ts_library(
|
mediapipe_ts_library(
|
||||||
name = "audio_task_runner",
|
name = "audio_task_runner",
|
||||||
srcs = ["audio_task_runner.ts"],
|
srcs = ["audio_task_runner.ts"],
|
||||||
deps = [
|
deps = ["//mediapipe/tasks/web/core:task_runner"],
|
||||||
"//mediapipe/tasks/web/core",
|
|
||||||
"//mediapipe/tasks/web/core:task_runner",
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -15,10 +15,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {TaskRunner} from '../../../../tasks/web/core/task_runner';
|
import {TaskRunner} from '../../../../tasks/web/core/task_runner';
|
||||||
import {TaskRunnerOptions} from '../../../../tasks/web/core/task_runner_options';
|
|
||||||
|
|
||||||
/** Base class for all MediaPipe Audio Tasks. */
|
/** 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;
|
private defaultSampleRate = 48000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -37,10 +37,9 @@ export class GraphRunnerImageLib extends GraphRunnerImageLibType {}
|
||||||
* supported and loads the relevant WASM binary.
|
* supported and loads the relevant WASM binary.
|
||||||
* @return A fully instantiated instance of `T`.
|
* @return A fully instantiated instance of `T`.
|
||||||
*/
|
*/
|
||||||
export async function
|
export async function createTaskRunner<T extends TaskRunner>(
|
||||||
createTaskRunner<T extends TaskRunner<O>, O extends TaskRunnerOptions>(
|
|
||||||
type: WasmMediaPipeConstructor<T>, initializeCanvas: boolean,
|
type: WasmMediaPipeConstructor<T>, initializeCanvas: boolean,
|
||||||
fileset: WasmFileset, options: O): Promise<T> {
|
fileset: WasmFileset, options: TaskRunnerOptions): Promise<T> {
|
||||||
const fileLocator: FileLocator = {
|
const fileLocator: FileLocator = {
|
||||||
locateFile() {
|
locateFile() {
|
||||||
// The only file loaded with this mechanism is the Wasm binary
|
// 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. */
|
/** Base class for all MediaPipe Tasks. */
|
||||||
export abstract class TaskRunner<O extends TaskRunnerOptions> {
|
export abstract class TaskRunner {
|
||||||
protected abstract baseOptions: BaseOptionsProto;
|
protected abstract baseOptions: BaseOptionsProto;
|
||||||
protected graphRunner: GraphRunnerImageLib;
|
protected graphRunner: GraphRunnerImageLib;
|
||||||
private processingErrors: Error[] = [];
|
private processingErrors: Error[] = [];
|
||||||
|
@ -71,10 +70,9 @@ export abstract class TaskRunner<O extends TaskRunnerOptions> {
|
||||||
* supported and loads the relevant WASM binary.
|
* supported and loads the relevant WASM binary.
|
||||||
* @return A fully instantiated instance of `T`.
|
* @return A fully instantiated instance of `T`.
|
||||||
*/
|
*/
|
||||||
protected static async createInstance<T extends TaskRunner<O>,
|
protected static async createInstance<T extends TaskRunner>(
|
||||||
O extends TaskRunnerOptions>(
|
|
||||||
type: WasmMediaPipeConstructor<T>, initializeCanvas: boolean,
|
type: WasmMediaPipeConstructor<T>, initializeCanvas: boolean,
|
||||||
fileset: WasmFileset, options: O): Promise<T> {
|
fileset: WasmFileset, options: TaskRunnerOptions): Promise<T> {
|
||||||
return createTaskRunner(type, initializeCanvas, fileset, options);
|
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. */
|
/** Configures the shared options of a MediaPipe Task. */
|
||||||
async setOptions(options: O): Promise<void> {
|
async setOptions(options: TaskRunnerOptions): Promise<void> {
|
||||||
if (options.baseOptions) {
|
if (options.baseOptions) {
|
||||||
this.baseOptions = await convertBaseOptionsToProto(
|
this.baseOptions = await convertBaseOptionsToProto(
|
||||||
options.baseOptions, this.baseOptions);
|
options.baseOptions, this.baseOptions);
|
||||||
|
|
|
@ -41,7 +41,7 @@ const TEXT_CLASSIFIER_GRAPH =
|
||||||
// tslint:disable:jspb-use-builder-pattern
|
// tslint:disable:jspb-use-builder-pattern
|
||||||
|
|
||||||
/** Performs Natural Language classification. */
|
/** Performs Natural Language classification. */
|
||||||
export class TextClassifier extends TaskRunner<TextClassifierOptions> {
|
export class TextClassifier extends TaskRunner {
|
||||||
private classificationResult: TextClassifierResult = {classifications: []};
|
private classificationResult: TextClassifierResult = {classifications: []};
|
||||||
private readonly options = new TextClassifierGraphOptions();
|
private readonly options = new TextClassifierGraphOptions();
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ const TEXT_EMBEDDER_CALCULATOR =
|
||||||
/**
|
/**
|
||||||
* Performs embedding extraction on text.
|
* Performs embedding extraction on text.
|
||||||
*/
|
*/
|
||||||
export class TextEmbedder extends TaskRunner<TextEmbedderOptions> {
|
export class TextEmbedder extends TaskRunner {
|
||||||
private embeddingResult: TextEmbedderResult = {embeddings: []};
|
private embeddingResult: TextEmbedderResult = {embeddings: []};
|
||||||
private readonly options = new TextEmbedderGraphOptionsProto();
|
private readonly options = new TextEmbedderGraphOptionsProto();
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,7 @@ import {ImageSource} from '../../../../web/graph_runner/graph_runner';
|
||||||
import {VisionTaskOptions} from './vision_task_options';
|
import {VisionTaskOptions} from './vision_task_options';
|
||||||
|
|
||||||
/** Base class for all MediaPipe Vision Tasks. */
|
/** Base class for all MediaPipe Vision Tasks. */
|
||||||
export abstract class VisionTaskRunner<T> extends
|
export abstract class VisionTaskRunner<T> extends TaskRunner {
|
||||||
TaskRunner<VisionTaskOptions> {
|
|
||||||
/** Configures the shared options of a vision task. */
|
/** Configures the shared options of a vision task. */
|
||||||
override async setOptions(options: VisionTaskOptions): Promise<void> {
|
override async setOptions(options: VisionTaskOptions): Promise<void> {
|
||||||
await super.setOptions(options);
|
await super.setOptions(options);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user