Class ExpansionTranslatorFactory<IbaseT,ObaseT>

java.lang.Object
ai.djl.translate.ExpansionTranslatorFactory<IbaseT,ObaseT>
Type Parameters:
IbaseT - the input type for the base translator
ObaseT - the output type for the base translator
All Implemented Interfaces:
TranslatorFactory
Direct Known Subclasses:
BaseImageTranslatorFactory

public abstract class ExpansionTranslatorFactory<IbaseT,ObaseT> extends Object implements TranslatorFactory
  • Constructor Details

    • ExpansionTranslatorFactory

      public ExpansionTranslatorFactory()
  • Method Details

    • getSupportedTypes

      public Set<ai.djl.util.Pair<Type,Type>> getSupportedTypes()
      Returns supported input/output classes.
      Specified by:
      getSupportedTypes in interface TranslatorFactory
      Returns:
      a set of supported input/output classes
    • newInstance

      public <I, O> Translator<I,O> newInstance(Class<I> input, Class<O> output, Model model, Map<String,?> arguments)
      Returns a new instance of the Translator class.
      Specified by:
      newInstance in interface TranslatorFactory
      Type Parameters:
      I - the input data type
      O - the output data type
      Parameters:
      input - the input class
      output - the output class
      model - the Model that uses the Translator
      arguments - the configurations for a new Translator instance
      Returns:
      a new instance of the Translator class
    • withTranslator

      public ExpansionTranslatorFactory<IbaseT,ObaseT>.ai.djl.translate.ExpansionTranslatorFactory.ExpandedTranslatorOptions withTranslator(Translator<IbaseT,ObaseT> translator)
      Creates a set of TranslatorOptions based on the expansions of a given translator.
      Parameters:
      translator - the translator to expand
      Returns:
      the TranslatorOptions
    • buildBaseTranslator

      protected abstract Translator<IbaseT,ObaseT> buildBaseTranslator(Model model, Map<String,?> arguments)
      Builds the base translator that can be expanded.
      Parameters:
      model - the Model that uses the Translator
      arguments - the configurations for a new Translator instance
      Returns:
      a base translator that can be expanded to form the factory options
    • getBaseInputType

      public abstract Class<IbaseT> getBaseInputType()
      Returns the input type for the base translator.
      Returns:
      the input type for the base translator
    • getBaseOutputType

      public abstract Class<ObaseT> getBaseOutputType()
      Returns the output type for the base translator.
      Returns:
      the output type for the base translator
    • getExpansions

      protected Map<ai.djl.util.Pair<Type,Type>,ExpansionTranslatorFactory.TranslatorExpansion<IbaseT,ObaseT>> getExpansions()
      Returns the possible expansions of this factory.
      Returns:
      the possible expansions of this factory
    • getPreprocessorExpansions

      protected Map<Type,Function<PreProcessor<IbaseT>,PreProcessor<?>>> getPreprocessorExpansions()
      Returns the possible expansions of this factory.
      Returns:
      the possible expansions of this factory
    • getPostprocessorExpansions

      protected Map<Type,Function<PostProcessor<ObaseT>,PostProcessor<?>>> getPostprocessorExpansions()
      Returns the possible expansions of this factory.
      Returns:
      the possible expansions of this factory