Class InputStreamTranslator<T>

  • Type Parameters:
    T - the output object type
    All Implemented Interfaces:
    PostProcessor<T>, PreProcessor<java.io.InputStream>, Translator<java.io.InputStream,​T>

    public class InputStreamTranslator<T>
    extends java.lang.Object
    implements Translator<java.io.InputStream,​T>
    Built-in Translator that provides image pre-processing from InputStream.
    • Constructor Detail

      • InputStreamTranslator

        public InputStreamTranslator​(Translator<Image,​T> translator)
        Creates a UrlTranslator instance.
        Parameters:
        translator - a Translator that can process image
    • Method Detail

      • processInput

        public NDList processInput​(TranslatorContext ctx,
                                   java.io.InputStream input)
                            throws java.lang.Exception
        Processes the input and converts it to NDList.
        Specified by:
        processInput in interface PreProcessor<T>
        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
      • processOutput

        public T processOutput​(TranslatorContext ctx,
                               NDList list)
                        throws java.lang.Exception
        Processes the output NDList to the corresponding output object.
        Specified by:
        processOutput in interface PostProcessor<T>
        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
      • 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<java.io.InputStream,​T>
        Parameters:
        ctx - the context for the Predictor.
        Throws:
        java.lang.Exception - if there is an error for preparing the translator