Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JS OV] Node.js API #19848

Merged

Conversation

vishniakov-nikolai
Copy link
Contributor

@vishniakov-nikolai vishniakov-nikolai commented Sep 14, 2023

What's included

  • Node.js bindings for OpenVINO
  • Samples & notebooks

Details

Folders structure

/samples/js/
  ./node/
    ./notebooks/ # VSCode typescript notebooks
    ./hello_classification/
    ./hello_reshape_ssd/
    ./classification_sample_async/
/src/bindings/js/
  ./docs/
  ./node/
    ./include/ # bindings header files
    ./lib/     # typescript sources of js part
    ./src/     # c++ bindings sources
    ./tests/   # js unit-tests

JS API

Exposed entities:

{
  addon: {
    Core: CoreConstructor,
    Tensor: TensorConstructor,
    PartialShape: PartialShapeContructor,

    element: typeof element,
    preprocess: {
      resizeAlgorithm: typeof resizeAlgorithm,
      PrePostProcessor: PrePostProcessorConstructor,
    }
  }
}
Detailed description:
Core {
  constructor();
  compileModel(model: Model, device: string, config?: { [option: string]: string }): Promise<CompiledModel>;
  compileModelSync(model: Model, device: string, config?: { [option: string]: string }): CompiledModel;
  readModel(modelPath: string, weightsPath?: string): Promise<Model>;
  readModelSync(modelPath: string, weightsPath?: string): Model;
  readModel(modelBuffer: Uint8Array, weightsBuffer?: Uint8Array): Promise<Model>;
  readModelSync(modelBuffer: Uint8Array, weightsBuffer?: Uint8Array): Model;
}

Model {
  outputs: Output[];
  inputs: Output[];
  output(nameOrId?: string | number): Output;
  input(nameOrId?: string | number): Output;
  getName(): string;
}

CompiledModel {
  outputs: Output[];
  inputs: Output[];
  output(nameOrId?: string | number): Output;
  input(nameOrId?: string | number): Output;
  createInferRequest(): InferRequest;
}

Tensor {
  data: number[];
  constructor(type: element,
      shape: number[],
      tensorData?: number[] | SupportedTypedArray);
  getElementType(): element;
  getShape(): number[];
  getData(): number[];
}

InferRequest {
  setTensor(name: string, tensor: Tensor): void;
  setInputTensor(idxOrTensor: number | Tensor, tensor?: Tensor): void;
  setOutputTensor(idxOrTensor: number | Tensor, tensor?: Tensor): void;
  getTensor(nameOrOutput: string | Output): Tensor;
  getInputTensor(idx?: number): Tensor;
  getOutputTensor(idx?: number): Tensor;
  getCompiledModel(): CompiledModel;
  infer(inputData?: { [inputName: string]: Tensor | SupportedTypedArray} | Tensor[] | SupportedTypedArray[]): 
    { [outputName: string] : Tensor };
  inferAsync(inputData: { [inputName: string]: Tensor} | Tensor[] ): Promise<{ [outputName: string] : Tensor}>;
}

Output {
  anyName: string;
  shape: number[];
  toString(): string;
  getAnyName(): string;
  getShape(): number[];
  getPartialShape(): PartialShape;
}

PrePostProcessor {
  constructor(model: Model);
  build(): PrePostProcessor;
  input(idxOrTensorName?: number | string): InputInfo;
  output(idxOrTensorName?: number | string): OutputInfo;
}

InputTensorInfo {
  setElementType(elementType: element | elementTypeString ): InputTensorInfo;
  setLayout(layout: string): InputTensorInfo;
  setShape(shape: number[]): InputTensorInfo;
}

OutputTensorInfo {
  setElementType(elementType: element | elementTypeString ): InputTensorInfo;
  setLayout(layout: string): InputTensorInfo;
}

PreProcessSteps {
  resize(algorithm: resizeAlgorithm | string): PreProcessSteps;
}

InputModelInfo {
  setLayout(layout: string): InputModelInfo;
}

InputInfo {
  tensor(): InputTensorInfo;
  preprocess(): PreProcessSteps;
  model(): InputModelInfo;
}

OutputInfo {
  tensor(): OutputTensorInfo;
}

PartialShape {
  constructor(shape: string);
  isStatic(): boolean;
  isDynamic(): boolean;
  toString(): string;
  getDimensions(): Dimension[];
}

enum element {
  u8,
  u32,
  u16,
  i8,
  i16,
  i32,
  i64,
  f32,
  f64,
}

enum resizeAlgorithm {
  RESIZE_NEAREST,
  RESIZE_CUBIC,
  RESIZE_LINEAR,
}

Tickets

  • 119281

@vishniakov-nikolai vishniakov-nikolai requested review from a team as code owners September 14, 2023 14:08
@vishniakov-nikolai vishniakov-nikolai requested review from bstankix, ilya-lavrenov and ilyachur and removed request for a team September 14, 2023 14:08
@github-actions github-actions bot added category: build OpenVINO cmake script / infra category: samples OpenVINO Runtime Samples category: docs OpenVINO documentation labels Sep 14, 2023
@andrei-kochin
Copy link
Contributor

@vishniakov-nikolai do we need to store images in repo instead of downloading it from public source?

@vishniakov-nikolai
Copy link
Contributor Author

@vishniakov-nikolai do we need to store images in repo instead of downloading it from public source?

Of course it isn't needed. I'll make it differently.

@ilya-lavrenov
Copy link
Contributor

build_jenkins

@ilya-lavrenov
Copy link
Contributor

build_jenkins

@ilya-lavrenov ilya-lavrenov self-assigned this Dec 19, 2023
@mlukasze
Copy link
Contributor

build_jenkins

@vishniakov-nikolai
Copy link
Contributor Author

build_jenkins

@vishniakov-nikolai
Copy link
Contributor Author

build_jenkins

@vishniakov-nikolai vishniakov-nikolai enabled auto-merge (squash) December 19, 2023 18:13
@akuporos
Copy link
Contributor

build_jenkins

@vishniakov-nikolai
Copy link
Contributor Author

build_jenkins

@vishniakov-nikolai vishniakov-nikolai merged commit 8d704f6 into openvinotoolkit:master Dec 20, 2023
102 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: build OpenVINO cmake script / infra category: CI OpenVINO public CI category: docs OpenVINO documentation category: inference OpenVINO Runtime library - Inference category: packaging OpenVINO packaging / distribution category: samples OpenVINO Runtime Samples Code Freeze no-match-files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants