A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://deeplearning4j.konduit.ai/deeplearning4j/reference/saving-and-loading-models below:

Saving and Loading Models | Deeplearning4j

Saving and Loading Models | Deeplearning4j
  1. Deeplearning4j
  2. Reference
Saving and Loading Models

Saving and loading of neural networks.

MultiLayerNetwork and ComputationGraph both have save and load methods.

You can save/load a MultiLayerNetwork using:

MultiLayerNetwork net = ...
net.save(new File("...");

MultiLayerNetwork net2 = MultiLayerNetwork.load(new File("..."), true);

Similarly, you can save/load a ComputationGraph using:

ComputationGraph net = ...
net.save(new File("..."));

ComputationGraph net2 = ComputationGraph.load(new File("..."), true);

Internally, these methods use the ModelSerializer class, which handles loading and saving models. There are two methods for saving models shown in the examples through the link. The first example saves a normal multi layer network, the second one saves a computation graph .

Here is a basic example with code to save a computation graph using the ModelSerializer class, as well as an example of using ModelSerializer to save a neural net built using MultiLayer configuration.

If your model uses probabilities (i.e. DropOut/DropConnect), it may make sense to save it separately, and apply it after model is restored; i.e:

 Nd4j.getRandom().setSeed(12345);
 ModelSerializer.restoreMultiLayerNetwork(modelFile);

This will guarantee equal results between sessions/JVMs.

[source]

Utility class suited to save/restore neural net models

writeModel

public static void writeModel(@NonNull Model model, @NonNull File file, boolean saveUpdater) throws IOException

Write a model to a file

writeModel

public static void writeModel(@NonNull Model model, @NonNull File file, boolean saveUpdater,DataNormalization dataNormalization) throws IOException

Write a model to a file

writeModel

public static void writeModel(@NonNull Model model, @NonNull String path, boolean saveUpdater) throws IOException

Write a model to a file path

writeModel

public static void writeModel(@NonNull Model model, @NonNull OutputStream stream, boolean saveUpdater)
            throws IOException

Write a model to an output stream

writeModel

public static void writeModel(@NonNull Model model, @NonNull OutputStream stream, boolean saveUpdater,DataNormalization dataNormalization)
            throws IOException

Write a model to an output stream

restoreMultiLayerNetwork

public static MultiLayerNetwork restoreMultiLayerNetwork(@NonNull File file) throws IOException

Load a multi layer network from a file

restoreMultiLayerNetwork

public static MultiLayerNetwork restoreMultiLayerNetwork(@NonNull File file, boolean loadUpdater)
            throws IOException

Load a multi layer network from a file

restoreMultiLayerNetwork

public static MultiLayerNetwork restoreMultiLayerNetwork(@NonNull InputStream is, boolean loadUpdater)
            throws IOException

Load a MultiLayerNetwork from InputStream from an input stream Note: the input stream is read fully and closed by this method. Consequently, the input stream cannot be re-used.

restoreMultiLayerNetwork

public static MultiLayerNetwork restoreMultiLayerNetwork(@NonNull InputStream is) throws IOException

Restore a multi layer network from an input stream Note: the input stream is read fully and closed by this method. Consequently, the input stream cannot be re-used.

restoreMultiLayerNetwork

public static MultiLayerNetwork restoreMultiLayerNetwork(@NonNull String path) throws IOException

Load a MultilayerNetwork model from a file

restoreMultiLayerNetwork

public static MultiLayerNetwork restoreMultiLayerNetwork(@NonNull String path, boolean loadUpdater)
            throws IOException

Load a MultilayerNetwork model from a file

restoreComputationGraph

public static ComputationGraph restoreComputationGraph(@NonNull String path) throws IOException

Restore a MultiLayerNetwork and Normalizer (if present - null if not) from the InputStream. Note: the input stream is read fully and closed by this method. Consequently, the input stream cannot be re-used.

restoreComputationGraph

public static ComputationGraph restoreComputationGraph(@NonNull String path, boolean loadUpdater)
            throws IOException

Load a computation graph from a file

restoreComputationGraph

public static ComputationGraph restoreComputationGraph(@NonNull InputStream is, boolean loadUpdater)
            throws IOException

Load a computation graph from a InputStream

restoreComputationGraph

public static ComputationGraph restoreComputationGraph(@NonNull InputStream is) throws IOException

Load a computation graph from a InputStream

restoreComputationGraph

public static ComputationGraph restoreComputationGraph(@NonNull File file) throws IOException

Load a computation graph from a file

restoreComputationGraph

public static ComputationGraph restoreComputationGraph(@NonNull File file, boolean loadUpdater) throws IOException

Restore a ComputationGraph and Normalizer (if present - null if not) from the InputStream. Note: the input stream is read fully and closed by this method. Consequently, the input stream cannot be re-used.

taskByModel

public static Task taskByModel(Model model)

addNormalizerToModel

public static void addNormalizerToModel(File f, Normalizer<?> normalizer)

This method appends normalizer to a given persisted model.

PLEASE NOTE: File should be model file saved earlier with ModelSerializer

addObjectToFile

public 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. Objects can be restored using {- link #getObjectFromFile(File, String)}


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4