Skip to content

Instantly share code, notes, and snippets.

@ieee8023
Created October 17, 2015 17:06
Show Gist options
  • Save ieee8023/136b4ba1dedd23bf003f to your computer and use it in GitHub Desktop.
Save ieee8023/136b4ba1dedd23bf003f to your computer and use it in GitHub Desktop.
OutputStream fos = Files.newOutputStream(Paths.get("coefficients.bin"));
ObjectOutputStream dos = new ObjectOutputStream(fos);
dos.writeObject(model.params());
dos.flush();
dos.close();
FileUtils.write(new File("conf.json"), model.getLayerWiseConfigurations().toJson());
MultiLayerConfiguration confFromJson = MultiLayerConfiguration.fromJson(FileUtils.readFileToString(new File("conf.json")));
ObjectInputStream dis = new ObjectInputStream(new FileInputStream("coefficients.bin"));
INDArray newParams = (INDArray) dis.readObject();
dis.close();
MultiLayerNetwork savedNetwork = new MultiLayerNetwork(confFromJson);
savedNetwork.init();
savedNetwork.setParameters(newParams);
System.out.println("Original network params " + model.params());
System.out.println("Restored network params " + savedNetwork.params());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment