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>
public class BasicTranslator<I,O> extends java.lang.Object implements Translator<I,O>
-
-
Constructor Summary
Constructors Constructor Description BasicTranslator(PreProcessor<I> preProcessor, PostProcessor<O> postProcessor)Constructs aBasicTranslatorwith the defaultBatchifier.BasicTranslator(PreProcessor<I> preProcessor, PostProcessor<O> postProcessor, Batchifier batchifier)Constructs aBasicTranslator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BatchifiergetBatchifier()Returns theBatchifier.voidprepare(TranslatorContext ctx)Prepares the translator with the manager and model to use.NDListprocessInput(TranslatorContext ctx, I input)Processes the input and converts it to NDList.OprocessOutput(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, wait
-
Methods inherited from interface ai.djl.translate.Translator
getExpansions, toBatchTranslator, toBatchTranslator
-
-
-
-
Constructor Detail
-
BasicTranslator
public BasicTranslator(PreProcessor<I> preProcessor, PostProcessor<O> postProcessor)
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 Detail
-
processOutput
public O processOutput(TranslatorContext ctx, NDList list) throws java.lang.Exception
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:
java.lang.Exception- if an error occurs during processing output
-
processInput
public NDList processInput(TranslatorContext ctx, I input) throws java.lang.Exception
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:
java.lang.Exception- if an error occurs during processing input
-
getBatchifier
public Batchifier getBatchifier()
Returns theBatchifier.- Specified by:
getBatchifierin interfaceTranslator<I,O>- Returns:
- the
Batchifier
-
prepare
public void prepare(TranslatorContext ctx) throws java.lang.Exception
Prepares the translator with the manager and model to use.- Specified by:
preparein interfaceTranslator<I,O>- Parameters:
ctx- the context for thePredictor.- Throws:
java.lang.Exception- if there is an error for preparing the translator
-
-