Class BasicTranslator<I,​O>

    • Constructor Detail

      • BasicTranslator

        public BasicTranslator​(PreProcessor<I> preProcessor,
                               PostProcessor<O> postProcessor)
        Constructs a BasicTranslator with the default Batchifier.
        Parameters:
        preProcessor - the preProcessor to use for pre-processing
        postProcessor - the postProcessor to use for post-processing
      • BasicTranslator

        public BasicTranslator​(PreProcessor<I> preProcessor,
                               PostProcessor<O> postProcessor,
                               Batchifier batchifier)
        Constructs a BasicTranslator.
        Parameters:
        preProcessor - the preProcessor to use for pre-processing
        postProcessor - the postProcessor to use for post-processing
        batchifier - 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:
        processOutput in interface PostProcessor<I>
        Parameters:
        ctx - the toolkit used for post-processing
        list - 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:
        processInput in interface PreProcessor<I>
        Parameters:
        ctx - the toolkit for creating the input NDArray
        input - the input object
        Returns:
        the NDList after pre-processing
        Throws:
        java.lang.Exception - if an error occurs during processing input
      • prepare

        public void prepare​(TranslatorContext ctx)
                     throws java.lang.Exception
        Prepares the translator with the manager and model to use.
        Specified by:
        prepare in interface Translator<I,​O>
        Parameters:
        ctx - the context for the Predictor.
        Throws:
        java.lang.Exception - if there is an error for preparing the translator