Constructor and Description |
---|
ZooModel(Model model,
Translator<I,O> translator)
Constructs a
ZooModel given the model and translator. |
Modifier and Type | Method and Description |
---|---|
void |
cast(DataType dataType)
Casts the model to support a different precision level.
|
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.
|
java.net.URL |
getArtifact(java.lang.String name)
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.
|
Translator<I,O> |
getTranslator()
Returns the default translator.
|
Model |
getWrappedModel()
Returns the wrapped model.
|
void |
load(java.nio.file.Path modelPath,
java.lang.String prefix,
java.util.Map<java.lang.String,?> options)
Loads the model from the
modelPath with the name and options provided. |
Predictor<I,O> |
newPredictor()
Creates a new Predictor based on the model with the default translator.
|
Predictor<I,O> |
newPredictor(Device device)
Creates a new Predictor based on the model with the default translator and a specified
device.
|
<P,Q> Predictor<P,Q> |
newPredictor(Translator<P,Q> translator,
Device device)
Creates a new Predictor based on the model.
|
Trainer |
newTrainer(TrainingConfig trainingConfig)
Creates a new
Trainer instance for a Model. |
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.
|
void |
setProperty(java.lang.String key,
java.lang.String value)
Sets a property to the model.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
load, load, newInstance, newInstance, newInstance, newInstance, newPredictor, quantize
public ZooModel(Model model, Translator<I,O> translator)
ZooModel
given the model and translator.model
- the model to wraptranslator
- the translatorpublic void load(java.nio.file.Path modelPath, java.lang.String prefix, java.util.Map<java.lang.String,?> options)
modelPath
with the name and options provided.public Model getWrappedModel()
public void save(java.nio.file.Path modelPath, java.lang.String modelName) throws java.io.IOException
modelPath
with the name provided.public java.nio.file.Path getModelPath()
getModelPath
in interface Model
public Block getBlock()
public void setBlock(Block block)
public java.lang.String getName()
public java.lang.String getProperty(java.lang.String key)
getProperty
in interface Model
key
- the name of the propertypublic 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 Trainer newTrainer(TrainingConfig trainingConfig)
Trainer
instance for a Model.newTrainer
in interface Model
trainingConfig
- training configuration settingsTrainer
instancepublic Predictor<I,O> newPredictor()
Predictor
public Predictor<I,O> newPredictor(Device device)
device
- the device to use for predictionPredictor
public <P,Q> Predictor<P,Q> newPredictor(Translator<P,Q> translator, Device device)
newPredictor
in interface Model
P
- the input object for pre-processingQ
- the output object from postprocessingtranslator
- the object used for pre-processing and postprocessingdevice
- the device to use for predictionPredictor
public Translator<I,O> getTranslator()
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 name) throws java.io.IOException
getArtifact
in interface Model
name
- 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 NDManager getNDManager()
NDManager
from the model.getNDManager
in interface Model
NDManager
public void setDataType(DataType dataType)
setDataType
in interface Model
dataType
- the standard data type to usepublic DataType getDataType()
getDataType
in interface Model
public void cast(DataType dataType)
For example, you can cast the precision from Float to Int