I - the input typeO - the output typepublic interface Predictor<I,O>
extends java.lang.AutoCloseable
Predictor interface provides a session for model inference.
You can use a Predictor, with a specified Translator, to perform inference on
a Model. The following is example code that uses Predictor:
Model model = Model.load(modelDir, modelName);
// User must implement Translator interface, read Translator for detail.
Translator<String, String> translator = new MyTranslator();
try (Predictor<String, String> predictor = model.newPredictor(translator)) {
String result = predictor.predict("What's up");
}
See the tutorials on:
For information about running multi-threaded inference, see here.
Model,
Translator| Modifier and Type | Method and Description |
|---|---|
java.util.List<O> |
batchPredict(java.util.List<I> inputs)
Predicts a batch for inference.
|
void |
close() |
O |
predict(I input)
Predicts an item for inference.
|
void |
setMetrics(Metrics metrics)
Attaches a Metrics param to use for benchmark.
|
O predict(I input) throws TranslateException
input - the inputTranslateException - if an error occurs during predictionjava.util.List<O> batchPredict(java.util.List<I> inputs) throws TranslateException
inputs - a list of inputsTranslateException - if an error occurs during predictionvoid setMetrics(Metrics metrics)
metrics - the Metrics classvoid close()
close in interface java.lang.AutoCloseable