Package ai.djl.translate
Class DefaultTranslatorFactory
java.lang.Object
ai.djl.translate.DefaultTranslatorFactory
- All Implemented Interfaces:
TranslatorFactory
A default implementation of
TranslatorFactory
.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns supported input/output classes.boolean
isSupported
(Class<?> input, Class<?> output) Returns if the input/output is supported by theTranslatorFactory
.<I,
O> Translator<I, O> Returns a new instance of theTranslator
class.<I,
O> void registerTranslator
(Class<I> input, Class<O> output, Translator<I, O> translator) Registers aTranslator
with theTranslatorFactory
.
-
Field Details
-
translators
-
-
Constructor Details
-
DefaultTranslatorFactory
public DefaultTranslatorFactory()
-
-
Method Details
-
registerTranslator
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
Returns supported input/output classes.- Specified by:
getSupportedTypes
in interfaceTranslatorFactory
- Returns:
- a set of supported input/output classes
-
isSupported
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 <I,O> Translator<I,O> newInstance(Class<I> input, Class<O> output, Model model, Map<String, ?> arguments) throws TranslateExceptionReturns 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 - Throws:
TranslateException
- if failed to create Translator instance
-