public class ModelSerializer extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
COEFFICIENTS_BIN |
static String |
CONFIGURATION_JSON |
static String |
NO_PARAMS_MARKER |
static String |
NORMALIZER_BIN |
static String |
PREPROCESSOR_BIN |
static String |
UPDATER_BIN |
| Modifier and Type | Method and Description |
|---|---|
static void |
addNormalizerToModel(File f,
Normalizer<?> normalizer)
This method appends normalizer to a given persisted model.
|
static void |
addObjectToFile(@NonNull File f,
@NonNull String key,
@NonNull Object o)
Add an object to the (already existing) model file using Java Object Serialization.
|
static <T> T |
getObjectFromFile(@NonNull File f,
@NonNull String key)
Get an object with the specified key from the model file, that was previously added to the file using
addObjectToFile(File, String, Object) |
static List<String> |
listObjectsInFile(@NonNull File f)
List the keys of all objects added using the method
addObjectToFile(File, String, Object) |
static ComputationGraph |
restoreComputationGraph(@NonNull File file)
Load a computation graph from a file
|
static ComputationGraph |
restoreComputationGraph(@NonNull File file,
boolean loadUpdater)
Load a computation graph from a file
|
static ComputationGraph |
restoreComputationGraph(@NonNull InputStream is)
Load a computation graph from a InputStream
|
static ComputationGraph |
restoreComputationGraph(@NonNull InputStream is,
boolean loadUpdater)
Load a computation graph from a InputStream
|
static ComputationGraph |
restoreComputationGraph(@NonNull String path)
Load a computation graph from a file
|
static ComputationGraph |
restoreComputationGraph(@NonNull String path,
boolean loadUpdater)
Load a computation graph from a file
|
static Pair<ComputationGraph,Normalizer> |
restoreComputationGraphAndNormalizer(@NonNull File file,
boolean loadUpdater)
Restore a ComputationGraph and Normalizer (if present - null if not) from a File
|
static Pair<ComputationGraph,Normalizer> |
restoreComputationGraphAndNormalizer(@NonNull InputStream is,
boolean loadUpdater)
Restore a ComputationGraph and Normalizer (if present - null if not) from the InputStream.
|
static MultiLayerNetwork |
restoreMultiLayerNetwork(@NonNull File file)
Load a multi layer network from a file
|
static MultiLayerNetwork |
restoreMultiLayerNetwork(@NonNull File file,
boolean loadUpdater)
Load a multi layer network from a file
|
static MultiLayerNetwork |
restoreMultiLayerNetwork(@NonNull InputStream is)
Restore a multi layer network from an input stream
* Note: the input stream is read fully and closed by this method. |
static MultiLayerNetwork |
restoreMultiLayerNetwork(@NonNull InputStream is,
boolean loadUpdater)
Load a MultiLayerNetwork from InputStream from an input stream
Note: the input stream is read fully and closed by this method. |
static MultiLayerNetwork |
restoreMultiLayerNetwork(@NonNull String path)
Load a MultilayerNetwork model from a file
|
static MultiLayerNetwork |
restoreMultiLayerNetwork(@NonNull String path,
boolean loadUpdater)
Load a MultilayerNetwork model from a file
|
static Pair<MultiLayerNetwork,Normalizer> |
restoreMultiLayerNetworkAndNormalizer(@NonNull File file,
boolean loadUpdater)
Restore a MultiLayerNetwork and Normalizer (if present - null if not) from a File
|
static Pair<MultiLayerNetwork,Normalizer> |
restoreMultiLayerNetworkAndNormalizer(@NonNull InputStream is,
boolean loadUpdater)
Restore a MultiLayerNetwork and Normalizer (if present - null if not) from the InputStream.
|
static <T extends Normalizer> |
restoreNormalizerFromFile(File file)
This method restores normalizer from a given persisted model file
PLEASE NOTE: File should be model file saved earlier with ModelSerializer with addNormalizerToModel being called
|
static <T extends Normalizer> |
restoreNormalizerFromInputStream(InputStream is)
This method restores the normalizer form a persisted model file.
|
static Task |
taskByModel(Model model) |
static void |
writeModel(@NonNull Model model,
@NonNull File file,
boolean saveUpdater)
Write a model to a file
|
static void |
writeModel(@NonNull Model model,
@NonNull File file,
boolean saveUpdater,
DataNormalization dataNormalization)
Write a model to a file
|
static void |
writeModel(@NonNull Model model,
@NonNull OutputStream stream,
boolean saveUpdater)
Write a model to an output stream
|
static void |
writeModel(@NonNull Model model,
@NonNull OutputStream stream,
boolean saveUpdater,
DataNormalization dataNormalization)
Write a model to an output stream
|
static void |
writeModel(@NonNull Model model,
@NonNull String path,
boolean saveUpdater)
Write a model to a file path
|
public static final String UPDATER_BIN
public static final String NORMALIZER_BIN
public static final String CONFIGURATION_JSON
public static final String COEFFICIENTS_BIN
public static final String NO_PARAMS_MARKER
public static final String PREPROCESSOR_BIN
public static void writeModel(@NonNull
@NonNull Model model,
@NonNull
@NonNull File file,
boolean saveUpdater)
throws IOException
model - the model to writefile - the file to write tosaveUpdater - whether to save the updater or notIOExceptionpublic static void writeModel(@NonNull
@NonNull Model model,
@NonNull
@NonNull File file,
boolean saveUpdater,
DataNormalization dataNormalization)
throws IOException
model - the model to writefile - the file to write tosaveUpdater - whether to save the updater or notdataNormalization - the normalizer to save (optional)IOExceptionpublic static void writeModel(@NonNull
@NonNull Model model,
@NonNull
@NonNull String path,
boolean saveUpdater)
throws IOException
model - the model to writepath - the path to write tosaveUpdater - whether to save the updater
or notIOExceptionpublic static void writeModel(@NonNull
@NonNull Model model,
@NonNull
@NonNull OutputStream stream,
boolean saveUpdater)
throws IOException
model - the model to savestream - the output stream to write tosaveUpdater - whether to save the updater for the model or notIOExceptionpublic static void writeModel(@NonNull
@NonNull Model model,
@NonNull
@NonNull OutputStream stream,
boolean saveUpdater,
DataNormalization dataNormalization)
throws IOException
model - the model to savestream - the output stream to write tosaveUpdater - whether to save the updater for the model or notdataNormalization - the normalizer ot save (may be null)IOExceptionpublic static MultiLayerNetwork restoreMultiLayerNetwork(@NonNull @NonNull File file) throws IOException
file - the file to load fromIOExceptionpublic static MultiLayerNetwork restoreMultiLayerNetwork(@NonNull @NonNull File file, boolean loadUpdater) throws IOException
file - the file to load fromIOExceptionpublic static MultiLayerNetwork restoreMultiLayerNetwork(@NonNull @NonNull InputStream is, boolean loadUpdater) throws IOException
is - the inputstream to load fromIOExceptionrestoreMultiLayerNetworkAndNormalizer(InputStream, boolean)public static MultiLayerNetwork restoreMultiLayerNetwork(@NonNull @NonNull InputStream is) throws IOException
is - the input stream to restore fromIOExceptionrestoreMultiLayerNetworkAndNormalizer(InputStream, boolean)public static MultiLayerNetwork restoreMultiLayerNetwork(@NonNull @NonNull String path) throws IOException
path - path to the model file, to get the computation graph fromIOExceptionpublic static MultiLayerNetwork restoreMultiLayerNetwork(@NonNull @NonNull String path, boolean loadUpdater) throws IOException
path - path to the model file, to get the computation graph fromIOExceptionpublic static Pair<MultiLayerNetwork,Normalizer> restoreMultiLayerNetworkAndNormalizer(@NonNull @NonNull InputStream is, boolean loadUpdater) throws IOException
is - Input stream to read fromloadUpdater - Whether to load the updater from the model or notIOException - If an error occurs when reading from the streampublic static Pair<MultiLayerNetwork,Normalizer> restoreMultiLayerNetworkAndNormalizer(@NonNull @NonNull File file, boolean loadUpdater) throws IOException
file - File to read the model and normalizer fromloadUpdater - Whether to load the updater from the model or notIOException - If an error occurs when reading from the Filepublic static ComputationGraph restoreComputationGraph(@NonNull @NonNull String path) throws IOException
path - path to the model file, to get the computation graph fromIOExceptionpublic static ComputationGraph restoreComputationGraph(@NonNull @NonNull String path, boolean loadUpdater) throws IOException
path - path to the model file, to get the computation graph fromIOExceptionpublic static ComputationGraph restoreComputationGraph(@NonNull @NonNull InputStream is, boolean loadUpdater) throws IOException
is - the inputstream to get the computation graph fromIOExceptionpublic static ComputationGraph restoreComputationGraph(@NonNull @NonNull InputStream is) throws IOException
is - the inputstream to get the computation graph fromIOExceptionpublic static ComputationGraph restoreComputationGraph(@NonNull @NonNull File file) throws IOException
file - the file to get the computation graph fromIOExceptionpublic static Pair<ComputationGraph,Normalizer> restoreComputationGraphAndNormalizer(@NonNull @NonNull InputStream is, boolean loadUpdater) throws IOException
is - Input stream to read fromloadUpdater - Whether to load the updater from the model or notIOException - If an error occurs when reading from the streampublic static Pair<ComputationGraph,Normalizer> restoreComputationGraphAndNormalizer(@NonNull @NonNull File file, boolean loadUpdater) throws IOException
file - File to read the model and normalizer fromloadUpdater - Whether to load the updater from the model or notIOException - If an error occurs when reading from the Filepublic static ComputationGraph restoreComputationGraph(@NonNull @NonNull File file, boolean loadUpdater) throws IOException
file - the file to get the computation graph fromIOExceptionpublic static void addNormalizerToModel(File f, Normalizer<?> normalizer)
f - normalizer - public static void addObjectToFile(@NonNull
@NonNull File f,
@NonNull
@NonNull String key,
@NonNull
@NonNull Object o)
getObjectFromFile(File, String)f - File to add the object tokey - Key to store the object undero - Object to store using Java object serializationpublic static <T> T getObjectFromFile(@NonNull
@NonNull File f,
@NonNull
@NonNull String key)
addObjectToFile(File, String, Object)T - Type of the objectf - model file to add the object tokey - Key for the objectlistObjectsInFile(File)public static List<String> listObjectsInFile(@NonNull @NonNull File f)
addObjectToFile(File, String, Object)f - File previously created with ModelSerializergetObjectFromFile(File, String)public static <T extends Normalizer> T restoreNormalizerFromFile(File file) throws IOException
file - IOExceptionpublic static <T extends Normalizer> T restoreNormalizerFromInputStream(InputStream is) throws IOException
is - A stream to load data from.IOExceptionCopyright © 2020. All rights reserved.