Package ai.djl.translate
Class ExpansionTranslatorFactory<IbaseT,ObaseT>
- java.lang.Object
-
- ai.djl.translate.ExpansionTranslatorFactory<IbaseT,ObaseT>
-
- Type Parameters:
IbaseT
- the input type for the base translatorObaseT
- the output type for the base translator
- All Implemented Interfaces:
TranslatorFactory
- Direct Known Subclasses:
BaseImageTranslatorFactory
public abstract class ExpansionTranslatorFactory<IbaseT,ObaseT> extends java.lang.Object implements TranslatorFactory
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ExpansionTranslatorFactory.TranslatorExpansion<IbaseT,ObaseT>
A function from a base translator to an expanded translator.
-
Constructor Summary
Constructors Constructor Description ExpansionTranslatorFactory()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract Translator<IbaseT,ObaseT>
buildBaseTranslator(Model model, java.util.Map<java.lang.String,?> arguments)
Builds the base translator that can be expanded.abstract java.lang.Class<IbaseT>
getBaseInputType()
Returns the input type for the base translator.abstract java.lang.Class<ObaseT>
getBaseOutputType()
Returns the output type for the base translator.protected java.util.Map<ai.djl.util.Pair<java.lang.reflect.Type,java.lang.reflect.Type>,ExpansionTranslatorFactory.TranslatorExpansion<IbaseT,ObaseT>>
getExpansions()
Returns the possible expansions of this factory.protected java.util.Map<java.lang.reflect.Type,java.util.function.Function<PostProcessor<ObaseT>,PostProcessor<?>>>
getPostprocessorExpansions()
Returns the possible expansions of this factory.protected java.util.Map<java.lang.reflect.Type,java.util.function.Function<PreProcessor<IbaseT>,PreProcessor<?>>>
getPreprocessorExpansions()
Returns the possible expansions of this factory.java.util.Set<ai.djl.util.Pair<java.lang.reflect.Type,java.lang.reflect.Type>>
getSupportedTypes()
Returns supported input/output classes.<I,O>
Translator<I,O>newInstance(java.lang.Class<I> input, java.lang.Class<O> output, Model model, java.util.Map<java.lang.String,?> arguments)
Returns a new instance of theTranslator
class.ai.djl.translate.ExpansionTranslatorFactory.ExpandedTranslatorOptions
withTranslator(Translator<IbaseT,ObaseT> translator)
Creates a set ofTranslatorOptions
based on the expansions of a given translator.-
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.TranslatorFactory
isSupported
-
-
-
-
Method Detail
-
getSupportedTypes
public java.util.Set<ai.djl.util.Pair<java.lang.reflect.Type,java.lang.reflect.Type>> getSupportedTypes()
Returns supported input/output classes.- Specified by:
getSupportedTypes
in interfaceTranslatorFactory
- Returns:
- a set of supported input/output classes
-
newInstance
public <I,O> Translator<I,O> newInstance(java.lang.Class<I> input, java.lang.Class<O> output, Model model, java.util.Map<java.lang.String,?> arguments)
Returns a new instance of theTranslator
class.- Specified by:
newInstance
in interfaceTranslatorFactory
- Type Parameters:
I
- the input data typeO
- the output data type- Parameters:
input
- the input classoutput
- the output classmodel
- theModel
that uses theTranslator
arguments
- the configurations for a newTranslator
instance- Returns:
- a new instance of the
Translator
class
-
withTranslator
public ai.djl.translate.ExpansionTranslatorFactory.ExpandedTranslatorOptions withTranslator(Translator<IbaseT,ObaseT> translator)
Creates a set ofTranslatorOptions
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, java.util.Map<java.lang.String,?> arguments)
Builds the base translator that can be expanded.- Parameters:
model
- theModel
that uses theTranslator
arguments
- the configurations for a newTranslator
instance- Returns:
- a base translator that can be expanded to form the factory options
-
getBaseInputType
public abstract java.lang.Class<IbaseT> getBaseInputType()
Returns the input type for the base translator.- Returns:
- the input type for the base translator
-
getBaseOutputType
public abstract java.lang.Class<ObaseT> getBaseOutputType()
Returns the output type for the base translator.- Returns:
- the output type for the base translator
-
getExpansions
protected java.util.Map<ai.djl.util.Pair<java.lang.reflect.Type,java.lang.reflect.Type>,ExpansionTranslatorFactory.TranslatorExpansion<IbaseT,ObaseT>> getExpansions()
Returns the possible expansions of this factory.- Returns:
- the possible expansions of this factory
-
getPreprocessorExpansions
protected java.util.Map<java.lang.reflect.Type,java.util.function.Function<PreProcessor<IbaseT>,PreProcessor<?>>> getPreprocessorExpansions()
Returns the possible expansions of this factory.- Returns:
- the possible expansions of this factory
-
getPostprocessorExpansions
protected java.util.Map<java.lang.reflect.Type,java.util.function.Function<PostProcessor<ObaseT>,PostProcessor<?>>> getPostprocessorExpansions()
Returns the possible expansions of this factory.- Returns:
- the possible expansions of this factory
-
-