| 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 |
| Constructor and Description |
|---|
BaseModel() |
| Modifier and Type | Method and Description |
|---|---|
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.
|
Block |
getBlock()
Gets the block from the Model.
|
DataType |
getDataType()
Returns the standard data type used within the model.
|
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.
|
protected java.nio.file.Path |
paramPathResolver(java.util.Map<java.lang.String,java.lang.Object> options) |
protected boolean |
readParameters(java.util.Map<java.lang.String,java.lang.Object> options) |
void |
save(java.nio.file.Path modelPath,
java.lang.String modelName)
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) |
protected void |
setModelName(java.lang.String modelName) |
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, waitcast, close, getArtifactNames, load, load, load, newInstance, newInstance, newInstance, newPredictor, newTrainer, quantizeprotected 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 ModelNDManagerpublic void setDataType(DataType dataType)
setDataType in interface ModeldataType - the standard data type to usepublic DataType getDataType()
getDataType in interface Modelpublic 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 Modelpublic ai.djl.util.PairList<java.lang.String,Shape> describeOutput()
It contains the output information that can be obtained from the model.
describeOutput in interface Modelpublic <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 ModelT - 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 ModelartifactName - 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 Modelname - 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 Modelkey - the name of the propertyvalue - the value of the propertypublic java.lang.String getProperty(java.lang.String key)
getProperty in interface Modelkey - the name of the propertyprotected void setModelDir(java.nio.file.Path modelDir)
protected void setModelName(java.lang.String modelName)
public void save(java.nio.file.Path modelPath,
java.lang.String modelName)
throws java.io.IOException
modelPath with the name provided.protected void finalize()
throws java.lang.Throwable
finalize in class java.lang.Objectjava.lang.Throwableprotected java.nio.file.Path paramPathResolver(java.util.Map<java.lang.String,java.lang.Object> options)
throws java.io.IOException
java.io.IOExceptionprotected boolean readParameters(java.util.Map<java.lang.String,java.lang.Object> options)
throws java.io.IOException,
MalformedModelException
java.io.IOExceptionMalformedModelException