Modifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.String,java.lang.Object> |
artifacts |
protected Block |
block |
protected DataType |
dataType |
protected ai.djl.util.PairList<java.lang.String,Shape> |
inputData |
protected NDManager |
manager |
protected java.nio.file.Path |
modelDir |
protected java.lang.String |
modelName |
protected java.util.Map<java.lang.String,java.lang.String> |
properties |
Modifier | Constructor and Description |
---|---|
protected |
BaseModel(java.lang.String modelName) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
ai.djl.util.PairList<java.lang.String,Shape> |
describeInput()
Returns the input descriptor of the model.
|
ai.djl.util.PairList<java.lang.String,Shape> |
describeOutput()
Returns the output descriptor of the model.
|
protected void |
finalize() |
java.net.URL |
getArtifact(java.lang.String artifactName)
Finds an artifact resource with a given name in the model.
|
<T> T |
getArtifact(java.lang.String name,
java.util.function.Function<java.io.InputStream,T> function)
Attempts to load the artifact using the given function and cache it if the specified artifact
is not already cached.
|
java.io.InputStream |
getArtifactAsStream(java.lang.String name)
Finds an artifact resource with a given name in the model.
|
java.lang.String[] |
getArtifactNames()
Returns the artifact names associated with the model.
|
Block |
getBlock()
Gets the block from the Model.
|
DataType |
getDataType()
Returns the standard data type used within the model.
|
java.nio.file.Path |
getModelPath()
Returns the directory from where the model is loaded.
|
java.lang.String |
getName()
Gets the model name.
|
NDManager |
getNDManager()
Gets the
NDManager from the model. |
java.lang.String |
getProperty(java.lang.String key)
Gets the property of the model based on property name.
|
<I,O> Predictor<I,O> |
newPredictor(Translator<I,O> translator)
Creates a new Predictor based on the model.
|
Trainer |
newTrainer(TrainingConfig trainingConfig)
Creates a new
Trainer instance for a Model. |
protected java.nio.file.Path |
paramPathResolver(java.lang.String prefix,
java.util.Map<java.lang.String,?> options) |
protected boolean |
readParameters(java.nio.file.Path paramFile,
java.util.Map<java.lang.String,?> options) |
void |
save(java.nio.file.Path modelPath,
java.lang.String newModelName)
Saves the model to the specified
modelPath with the name provided. |
void |
setBlock(Block block)
Sets the block for the Model for training and inference.
|
void |
setDataType(DataType dataType)
Sets the standard data type used within the model.
|
protected void |
setModelDir(java.nio.file.Path modelDir) |
void |
setProperty(java.lang.String key,
java.lang.String value)
Sets a property to the model.
|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
cast, load, load, load, newInstance, newInstance, newInstance, newInstance, quantize
protected java.nio.file.Path modelDir
protected Block block
protected java.lang.String modelName
protected NDManager manager
protected DataType dataType
protected ai.djl.util.PairList<java.lang.String,Shape> inputData
protected java.util.Map<java.lang.String,java.lang.Object> artifacts
protected java.util.Map<java.lang.String,java.lang.String> properties
public Block getBlock()
public void setBlock(Block block)
public java.lang.String getName()
public NDManager getNDManager()
NDManager
from the model.getNDManager
in interface Model
NDManager
public Trainer newTrainer(TrainingConfig trainingConfig)
Trainer
instance for a Model.newTrainer
in interface Model
trainingConfig
- training configuration settingsTrainer
instancepublic <I,O> Predictor<I,O> newPredictor(Translator<I,O> translator)
newPredictor
in interface Model
I
- the input object for pre-processingO
- the output object from postprocessingtranslator
- the object used for pre-processing and postprocessingPredictor
public void setDataType(DataType dataType)
setDataType
in interface Model
dataType
- the standard data type to usepublic DataType getDataType()
getDataType
in interface Model
public void close()
public ai.djl.util.PairList<java.lang.String,Shape> describeInput()
It contains the information that can be extracted from the model, usually name, shape, layout and DataType.
describeInput
in interface Model
public ai.djl.util.PairList<java.lang.String,Shape> describeOutput()
It contains the output information that can be obtained from the model.
describeOutput
in interface Model
public java.lang.String[] getArtifactNames()
getArtifactNames
in interface Model
public <T> T getArtifact(java.lang.String name, java.util.function.Function<java.io.InputStream,T> function) throws java.io.IOException
Model will cache loaded artifact, so the user doesn't need to keep tracking it.
String synset = model.getArtifact("synset.txt", k -> IOUtils.toString(k)));
getArtifact
in interface Model
T
- the type of the returned artifact objectname
- the name of the desired artifactfunction
- the function to load the artifactjava.io.IOException
- when IO operation fails in loading a resourcepublic java.net.URL getArtifact(java.lang.String artifactName) throws java.io.IOException
getArtifact
in interface Model
artifactName
- the name of the desired artifactURL
object or null
if no artifact with this name is foundjava.io.IOException
- when IO operation fails in loading a resourcepublic java.io.InputStream getArtifactAsStream(java.lang.String name) throws java.io.IOException
getArtifactAsStream
in interface Model
name
- the name of the desired artifactInputStream
object or null
if no resource with this name is
foundjava.io.IOException
- when IO operation fails in loading a resourcepublic void setProperty(java.lang.String key, java.lang.String value)
properties will be saved/loaded with model, user can store some information about the model in here.
setProperty
in interface Model
key
- the name of the propertyvalue
- the value of the propertypublic java.lang.String getProperty(java.lang.String key)
getProperty
in interface Model
key
- the name of the propertyprotected void setModelDir(java.nio.file.Path modelDir)
public void save(java.nio.file.Path modelPath, java.lang.String newModelName) throws java.io.IOException
modelPath
with the name provided.public java.nio.file.Path getModelPath()
getModelPath
in interface Model
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
protected java.nio.file.Path paramPathResolver(java.lang.String prefix, java.util.Map<java.lang.String,?> options) throws java.io.IOException
java.io.IOException
protected boolean readParameters(java.nio.file.Path paramFile, java.util.Map<java.lang.String,?> options) throws java.io.IOException, MalformedModelException
java.io.IOException
MalformedModelException