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

Introduce new general-purpose prediction methods for InferenceModel #515

Merged
merged 4 commits into from
Jan 10, 2023

Conversation

juliabeliaeva
Copy link
Contributor

This PR removes classification methods from the InferenceModel interface in favor of the more general api. It introduces two prediction methods: for single input and for multiple inputs and adds api to extract prediction results from the model. Instance methods are replaced with the following options for classification:

  1. If a model outputs a vector of probabilities, there are PredictionKt#predictLabel/PredictionKt#predictProbabilities extensions or the model could be wrapped into ImageRecognitionModelBase.
  2. For models with different outputs, function InferenceModel#predict(kotlin.Pair<float[], TensorShape>, Function1<? super R,? extends T>) could be used combined with the InferenceResultConverter for result extraction.

Additional comments:

  1. TensorFlow models still have some methods for classification left, for convenience.
  2. TensorResult right now only has a list of tensors, but ideally it could also contain a map "output name" -> "tensor" and allow access by String.
  3. InferenceResultConverter only has 2 methods returning LongArray and FloatArray, this list should be expanded for other data types.
  4. InferenceModel does not provide enough input-output information. Currently it only has inputDimensions property, instead we should replace it with something similar to OnnxInferenceModel#inputInfo/outputInfo to get access to all inputs and outputs.

Copy link
Collaborator

@ermolenkodev ermolenkodev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the design. It's great that we don't have hardcode classification-related methods in interfaces anymore. Thanks!

@juliabeliaeva juliabeliaeva merged commit 366497c into Kotlin:master Jan 10, 2023
@juliabeliaeva juliabeliaeva deleted the new-inference-api-5 branch January 10, 2023 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants