Package ai.djl.translate
Class BasicTranslator<I,O>
java.lang.Object
ai.djl.translate.BasicTranslator<I,O>
- Type Parameters:
I- the input classO- the output class
- All Implemented Interfaces:
PostProcessor<O>,PreProcessor<I>,Translator<I,O>
-
Constructor Summary
ConstructorsConstructorDescriptionBasicTranslator(PreProcessor<I> preProcessor, PostProcessor<O> postProcessor) Constructs aBasicTranslatorwith the defaultBatchifier.BasicTranslator(PreProcessor<I> preProcessor, PostProcessor<O> postProcessor, Batchifier batchifier) Constructs aBasicTranslator. -
Method Summary
Modifier and TypeMethodDescriptionReturns theBatchifier.voidprepare(TranslatorContext ctx) Prepares the translator with the manager and model to use.processInput(TranslatorContext ctx, I input) Processes the input and converts it to NDList.processOutput(TranslatorContext ctx, NDList list) Processes the output NDList to the corresponding output object.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ai.djl.translate.Translator
batchProcessInput, batchProcessOutput, getExpansions
-
Constructor Details
-
BasicTranslator
Constructs aBasicTranslatorwith the defaultBatchifier.- Parameters:
preProcessor- the preProcessor to use for pre-processingpostProcessor- the postProcessor to use for post-processing
-
BasicTranslator
public BasicTranslator(PreProcessor<I> preProcessor, PostProcessor<O> postProcessor, Batchifier batchifier) Constructs aBasicTranslator.- Parameters:
preProcessor- the preProcessor to use for pre-processingpostProcessor- the postProcessor to use for post-processingbatchifier- the batchifier to use
-
-
Method Details
-
processOutput
Processes the output NDList to the corresponding output object.- Specified by:
processOutputin interfacePostProcessor<I>- Parameters:
ctx- the toolkit used for post-processinglist- the output NDList after inference, usually immutable in engines like PyTorch. @see Issue 1774- Returns:
- the output object of expected type
- Throws:
Exception- if an error occurs during processing output
-
processInput
Processes the input and converts it to NDList.- Specified by:
processInputin interfacePreProcessor<I>- Parameters:
ctx- the toolkit for creating the input NDArrayinput- the input object- Returns:
- the
NDListafter pre-processing - Throws:
Exception- if an error occurs during processing input
-
getBatchifier
Returns theBatchifier.- Specified by:
getBatchifierin interfaceTranslator<I,O> - Returns:
- the
Batchifier
-
prepare
Prepares the translator with the manager and model to use.- Specified by:
preparein interfaceTranslator<I,O> - Parameters:
ctx- the context for thePredictor.- Throws:
Exception- if there is an error for preparing the translator
-