Package ai.djl.translate
Class DefaultTranslatorFactory
- java.lang.Object
-
- ai.djl.translate.DefaultTranslatorFactory
-
- All Implemented Interfaces:
TranslatorFactory
public class DefaultTranslatorFactory extends java.lang.Object implements TranslatorFactory
A default implementation ofTranslatorFactory
.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<ai.djl.util.Pair<java.lang.reflect.Type,java.lang.reflect.Type>,Translator<?,?>>
translators
-
Constructor Summary
Constructors Constructor Description DefaultTranslatorFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Set<ai.djl.util.Pair<java.lang.reflect.Type,java.lang.reflect.Type>>
getSupportedTypes()
Returns supported input/output classes.boolean
isSupported(java.lang.Class<?> input, java.lang.Class<?> output)
Returns if the input/output is supported by theTranslatorFactory
.Translator<?,?>
newInstance(java.lang.Class<?> input, java.lang.Class<?> output, Model model, java.util.Map<java.lang.String,?> arguments)
Returns a new instance of theTranslator
class.<I,O>
voidregisterTranslator(java.lang.Class<I> input, java.lang.Class<O> output, Translator<I,O> translator)
Registers aTranslator
with theTranslatorFactory
.
-
-
-
Field Detail
-
translators
protected java.util.Map<ai.djl.util.Pair<java.lang.reflect.Type,java.lang.reflect.Type>,Translator<?,?>> translators
-
-
Method Detail
-
registerTranslator
public <I,O> void registerTranslator(java.lang.Class<I> input, java.lang.Class<O> output, Translator<I,O> translator)
Registers aTranslator
with theTranslatorFactory
.- Type Parameters:
I
- the model input typeO
- the model output type- Parameters:
input
- the input data typeoutput
- the output data typetranslator
- theTranslator
to be registered
-
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
-
isSupported
public boolean isSupported(java.lang.Class<?> input, java.lang.Class<?> output)
Returns if the input/output is supported by theTranslatorFactory
.- Specified by:
isSupported
in interfaceTranslatorFactory
- Parameters:
input
- the input classoutput
- the output class- Returns:
true
if the input/output type is supported
-
newInstance
public Translator<?,?> newInstance(java.lang.Class<?> input, java.lang.Class<?> output, Model model, java.util.Map<java.lang.String,?> arguments) throws TranslateException
Returns a new instance of theTranslator
class.- Specified by:
newInstance
in interfaceTranslatorFactory
- 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 - Throws:
TranslateException
- if failed to create Translator instance
-
-