public static void saveModel(FileSystem fs, Model model ) throws Exception{ String json = null; if (model instanceof MultiLayerNetwork) { json = ((MultiLayerNetwork)model).getLayerWiseConfigurations().toJson(); } else if (model instanceof ComputationGraph) { json = ((ComputationGraph)model).getConfiguration().toJson(); } byte [] byts = json.getBytes(); FSDataOutputStream out = fs.create(new Path(modelPath)); out.write(byts); out.hsync(); fs.close(); } }
FileUtils.writeStringToFile(new File("videoconf.json"), conf.toJson()); System.out.println("Epoch " + i + " complete");
@Override public String toString() { return toJson(); }
protected static void save(MultiLayerNetwork net, String confOut, String paramOut, String updaterOut) throws IOException { String confJSON = net.getLayerWiseConfigurations().toJson(); INDArray params = net.params(); Updater updater = net.getUpdater(); FileUtils.writeStringToFile(new File(confOut), confJSON, "UTF-8"); try (DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(Files.newOutputStream(Paths.get(paramOut))))) { Nd4j.write(params, dos); } try (ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(new File(updaterOut))))) { oos.writeObject(updater); } }
/** * Zips the current state of the model and writes it stream * @param stream stream to write * @throws IOException */ public void saveModel(OutputStream stream) throws IOException { try (ZipOutputStream zipOut = new ZipOutputStream(new BufferedOutputStream(stream))) { // Write out manifest zipOut.putNextEntry(new ZipEntry(MANIFEST)); String comments = "Created-By:" + System.getenv("USER") + " at " + new Date().toString() + "\nModel-Version: " + VERSION + "\nModel-Schema:" + MODEL_NAME; manifest.store(zipOut, comments); zipOut.closeEntry(); // Write out the network zipOut.putNextEntry(new ZipEntry(NETWORK)); byte[] jModel = network.getLayerWiseConfigurations().toJson().getBytes(); zipOut.write(jModel); zipOut.closeEntry(); //Write out the network coefficients zipOut.putNextEntry(new ZipEntry(WEIGHTS)); Nd4j.write(network.params(), new DataOutputStream(zipOut)); zipOut.closeEntry(); // Write out vectors zipOut.putNextEntry(new ZipEntry(GLOVES)); gloves.writeOut(zipOut, false); zipOut.closeEntry(); zipOut.finish(); } }
json = ((MultiLayerNetwork) model).getLayerWiseConfigurations().toJson(); } else if (model instanceof ComputationGraph) { json = ((ComputationGraph) model).getConfiguration().toJson();
if (model instanceof MultiLayerNetwork) { MultiLayerNetwork net = ((MultiLayerNetwork) model); jsonConf = net.getLayerWiseConfigurations().toJson(); numLayers = net.getnLayers(); numParams = net.numParams();
if (!rootDevice) { this.replicatedModel = new MultiLayerNetwork(MultiLayerConfiguration.fromJson( ((MultiLayerNetwork) protoModel).getLayerWiseConfigurations().toJson())); this.replicatedModel.init();
if (!rootDevice) { this.replicatedModel = new MultiLayerNetwork(MultiLayerConfiguration.fromJson( ((MultiLayerNetwork) protoModel).getLayerWiseConfigurations().toJson())); this.replicatedModel.init();
if (!onRootModel) { MultiLayerConfiguration conf = MultiLayerConfiguration.fromJson( ((MultiLayerNetwork) originalModel).getLayerWiseConfigurations().toJson()); conf.setTrainingWorkspaceMode(workspaceMode); this.replicatedModel = new MultiLayerNetwork(conf);
if (!onRootModel) { MultiLayerConfiguration conf = MultiLayerConfiguration.fromJson( ((MultiLayerNetwork) originalModel).getLayerWiseConfigurations().toJson()); conf.setTrainingWorkspaceMode(workspaceMode); this.replicatedModel = new MultiLayerNetwork(conf);
numParams = m.numParams(); numLayers = m.getnLayers(); modelConfigJson = m.getLayerWiseConfigurations().toJson(); totalNumUpdates = m.getLayerWiseConfigurations().getIterationCount(); } else if(candidate instanceof ComputationGraph) {