Package ai.djl.repository.zoo
Class BaseModelLoader
java.lang.Object
ai.djl.repository.zoo.BaseModelLoader
- All Implemented Interfaces:
ModelLoader
Shared code for the
ModelLoader implementations.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBaseModelLoader(MRL mrl) Constructs aModelLoadergiven the repository, mrl, and version. -
Method Summary
Modifier and TypeMethodDescriptionprotected ModelcreateModel(Path modelPath, String name, Device device, Block block, Map<String, Object> arguments, String engine) <I,O> void downloadModel(Criteria<I, O> criteria, ai.djl.util.Progress progress) Downloads the model artifacts to local directory.Returns the application of theModelLoader.Returns the artifact ID of theModelLoader.Returns the group ID of theModelLoader.protected TranslatorFactorygetTranslatorFactory(Criteria<?, ?> criteria, Map<String, Object> arguments) <I,O> boolean isDownloaded(Criteria<I, O> criteria) Returnstrueif the model is downloaded in local directory.Returns a list of the available artifacts that can be loaded.<I,O> ZooModel<I, O> Loads the model with the given criteria.toString()
-
Field Details
-
mrl
-
defaultFactory
-
-
Constructor Details
-
BaseModelLoader
Constructs aModelLoadergiven the repository, mrl, and version.- Parameters:
mrl- the mrl of the model to load
-
-
Method Details
-
getGroupId
Returns the group ID of theModelLoader.- Specified by:
getGroupIdin interfaceModelLoader- Returns:
- the group ID of the
ModelLoader
-
getArtifactId
Returns the artifact ID of theModelLoader.- Specified by:
getArtifactIdin interfaceModelLoader- Returns:
- the artifact ID of the
ModelLoader
-
getApplication
Returns the application of theModelLoader.- Specified by:
getApplicationin interfaceModelLoader- Returns:
- the application of the
ModelLoader
-
loadModel
public <I,O> ZooModel<I,O> loadModel(Criteria<I, O> criteria) throws IOException, ModelNotFoundException, MalformedModelExceptionLoads the model with the given criteria.- Specified by:
loadModelin 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:
IOException- for various exceptions loading data from the repositoryModelNotFoundException- if no model with the specified criteria is foundMalformedModelException- if the model data is malformed
-
isDownloaded
public <I,O> boolean isDownloaded(Criteria<I, O> criteria) throws IOException, ModelNotFoundExceptionReturnstrueif the model is downloaded in local directory.- Specified by:
isDownloadedin interfaceModelLoader- Type Parameters:
I- the input data typeO- the output data type- Parameters:
criteria- the criteria to match against the loaded model- Returns:
trueif the model is downloaded in local directory- Throws:
IOException- for various exceptions loading data from the repositoryModelNotFoundException- if no model with the specified criteria is found
-
downloadModel
public <I,O> void downloadModel(Criteria<I, O> criteria, ai.djl.util.Progress progress) throws IOException, ModelNotFoundExceptionDownloads the model artifacts to local directory.- Specified by:
downloadModelin interfaceModelLoader- Type Parameters:
I- the input data typeO- the output data type- Parameters:
criteria- the criteria to match against the loaded modelprogress- the progress tracker- Throws:
IOException- for various exceptions loading data from the repositoryModelNotFoundException- if no model with the specified criteria is found
-
listModels
Returns a list of the available artifacts that can be loaded.- Specified by:
listModelsin interfaceModelLoader- Returns:
- a list of the available artifacts that can be loaded
- Throws:
IOException- for errors reading the artifact list
-
createModel
protected Model createModel(Path modelPath, String name, Device device, Block block, Map<String, Object> arguments, String engine) throws IOException- Throws:
IOException
-
toString
-
getTranslatorFactory
protected TranslatorFactory getTranslatorFactory(Criteria<?, ?> criteria, Map<String, Object> arguments)
-