Package ai.djl.repository.zoo
Class BaseModelLoader
- java.lang.Object
-
- ai.djl.repository.zoo.BaseModelLoader
-
- All Implemented Interfaces:
ModelLoader
public class BaseModelLoader extends java.lang.Object implements ModelLoader
Shared code for theModelLoader
implementations.
-
-
Field Summary
Fields Modifier and Type Field Description protected TranslatorFactory
defaultFactory
protected MRL
mrl
-
Constructor Summary
Constructors Constructor Description BaseModelLoader(MRL mrl)
Constructs aModelLoader
given the repository, mrl, and version.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Model
createModel(java.nio.file.Path modelPath, java.lang.String name, Device device, Block block, java.util.Map<java.lang.String,java.lang.Object> arguments, java.lang.String engine)
Application
getApplication()
Returns the application of theModelLoader
.java.lang.String
getArtifactId()
Returns the artifact ID of theModelLoader
.protected TranslatorFactory
getTranslatorFactory(Criteria<?,?> criteria, java.util.Map<java.lang.String,java.lang.Object> arguments)
java.util.List<Artifact>
listModels()
Returns a list of the available artifacts that can be loaded.<I,O>
ZooModel<I,O>loadModel(Criteria<I,O> criteria)
Loads the model with the given criteria.java.lang.String
toString()
-
-
-
Field Detail
-
mrl
protected MRL mrl
-
defaultFactory
protected TranslatorFactory defaultFactory
-
-
Constructor Detail
-
BaseModelLoader
public BaseModelLoader(MRL mrl)
Constructs aModelLoader
given the repository, mrl, and version.- Parameters:
mrl
- the mrl of the model to load
-
-
Method Detail
-
getArtifactId
public java.lang.String getArtifactId()
Returns the artifact ID of theModelLoader
.- Specified by:
getArtifactId
in interfaceModelLoader
- Returns:
- the artifact ID of the
ModelLoader
-
getApplication
public Application getApplication()
Returns the application of theModelLoader
.- Specified by:
getApplication
in interfaceModelLoader
- Returns:
- the application of the
ModelLoader
-
loadModel
public <I,O> ZooModel<I,O> loadModel(Criteria<I,O> criteria) throws java.io.IOException, ModelNotFoundException, MalformedModelException
Loads the model with the given criteria.- Specified by:
loadModel
in interfaceModelLoader
- Type Parameters:
I
- the input data typeO
- the output data type- Parameters:
criteria
- the criteria to match against the loaded model- Returns:
- the loaded model
- Throws:
java.io.IOException
- for various exceptions loading data from the repositoryModelNotFoundException
- if no model with the specified criteria is foundMalformedModelException
- if the model data is malformed
-
listModels
public java.util.List<Artifact> listModels() throws java.io.IOException
Returns a list of the available artifacts that can be loaded.- Specified by:
listModels
in interfaceModelLoader
- Returns:
- a list of the available artifacts that can be loaded
- Throws:
java.io.IOException
- for errors reading the artifact list
-
createModel
protected Model createModel(java.nio.file.Path modelPath, java.lang.String name, Device device, Block block, java.util.Map<java.lang.String,java.lang.Object> arguments, java.lang.String engine) throws java.io.IOException
- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getTranslatorFactory
protected TranslatorFactory getTranslatorFactory(Criteria<?,?> criteria, java.util.Map<java.lang.String,java.lang.Object> arguments)
-
-