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(); } }
ComputationGraphConfiguration conf = ComputationGraphConfiguration.fromJson(configJson); Map<String, GraphVertex> vertices = conf.getVertices(); if (vertices.containsKey(vertexName) && vertices.get(vertexName) instanceof LayerVertex) { LayerVertex lv = (LayerVertex) vertices.get(vertexName); nnc = lv.getLayerConf(); layer = nnc.getLayer(); } else if (conf.getNetworkInputs().contains(vertexName)) { layerType = "Input"; } else { GraphVertex gv = conf.getVertices().get(vertexName); if (gv != null) { layerType = gv.getClass().getSimpleName();
public GraphBuilder(ComputationGraphConfiguration newConf, NeuralNetConfiguration.Builder globalConfiguration) { ComputationGraphConfiguration clonedConf = newConf.clone(); this.vertices = clonedConf.getVertices(); this.vertexInputs = clonedConf.getVertexInputs(); this.networkInputs = clonedConf.getNetworkInputs(); this.networkOutputs = clonedConf.getNetworkOutputs(); this.pretrain = clonedConf.isPretrain(); this.backprop = clonedConf.isBackprop(); this.backpropType = clonedConf.getBackpropType(); this.tbpttFwdLength = clonedConf.getTbpttFwdLength(); this.tbpttBackLength = clonedConf.getTbpttBackLength(); this.globalConfiguration = globalConfiguration; //this.getGlobalConfiguration().setSeed(clonedConf.getDefaultConfiguration().getSeed()); }
Map<String, GraphVertex> vertices = config.getVertices(); Map<String, List<String>> vertexInputs = config.getVertexInputs(); List<String> networkInputs = config.getNetworkInputs();
if (!onRootModel) { ComputationGraphConfiguration conf = ComputationGraphConfiguration .fromJson(((ComputationGraph) originalModel).getConfiguration().toJson()); conf.setTrainingWorkspaceMode(workspaceMode); this.replicatedModel = originalModel; this.replicatedModel.init(); ((ComputationGraph) replicatedModel).getConfiguration().setTrainingWorkspaceMode(workspaceMode);
configuration.getTrainingWorkspaceMode(), configuration.getInferenceWorkspaceMode()); if (configuration.getCacheMode() == CacheMode.HOST) { workspaceConfigurationCache.setPolicyMirroring(MirroringPolicy.HOST_ONLY); Map<String, org.deeplearning4j.nn.conf.graph.GraphVertex> configVertexMap = configuration.getVertices(); List<String> networkInputNames = configuration.getNetworkInputs(); Map<String, List<String>> vertexInputs = configuration.getVertexInputs(); this.vertices = new GraphVertex[networkInputNames.size() + configuration.getVertices().size()]; int[] numParamsForVertex = new int[topologicalOrder.length]; int i = 0; for (; i < configuration.getNetworkInputs().size(); i++) { numParamsForVertex[i] = 0; //No parameters for input vertices
public void setGraphConfiguration(JsonNode conf) { if(conf != null) { String json = conf.toString(); if(json != null && !json.equals("null")) { net = new ComputationGraph(ComputationGraphConfiguration.fromJson(json)); net.init(); } } }
public DuplicateToTimeSeriesVertex(ComputationGraph graph, String name, int vertexIndex, VertexIndices[] inputVertices, VertexIndices[] outputVertices, String inputName) { super(graph, name, vertexIndex, inputVertices, outputVertices); this.inputName = inputName; this.inputVertexIndex = graph.getConfiguration().getNetworkInputs().indexOf(inputName); if (inputVertexIndex == -1) throw new IllegalArgumentException("Invalid input name: \"" + inputName + "\" not found in list " + "of network inputs (" + graph.getConfiguration().getNetworkInputs() + ")"); }
public ComputationGraph(ComputationGraphConfiguration configuration) { this.configuration = configuration; this.numInputArrays = configuration.getNetworkInputs().size(); this.numOutputArrays = configuration.getNetworkOutputs().size(); this.inputs = new INDArray[numInputArrays]; this.labels = new INDArray[numOutputArrays]; this.defaultConfiguration = configuration.getDefaultConfiguration(); }
int[] numParamsForVertex = new int[topologicalOrder.length]; int i = 0; for (; i < configuration.getNetworkInputs().size(); i++) { numParamsForVertex[i] = 0; //No parameters for input vertices Map<String, org.deeplearning4j.nn.conf.graph.GraphVertex> configVertexMap = configuration.getVertices(); for (Map.Entry<String, org.deeplearning4j.nn.conf.graph.GraphVertex> nodeEntry : configVertexMap .entrySet()) {
/** * Return an array of network outputs (predictions), given the specified network inputs * Network outputs are for output layers only. * * @param train If true: do forward pass at training time; false: do forward pass at test time * @param input Inputs to the network * @return Output activations (order: same as defined in network configuration) */ public INDArray[] output(boolean train, INDArray... input) { WorkspaceMode cMode = configuration.getTrainingWorkspaceMode(); configuration.setTrainingWorkspaceMode(configuration.getInferenceWorkspaceMode()); MemoryWorkspace workspace = configuration.getTrainingWorkspaceMode() == WorkspaceMode.NONE ? new DummyWorkspace() : Nd4j.getWorkspaceManager().getWorkspaceForCurrentThread( workspaceConfigurationExternal, workspaceExternal); try (MemoryWorkspace wsE = workspace.notifyScopeEntered()) { INDArray[] tmp = silentOutput(train, input); for (int x = 0; x < tmp.length; x++) tmp[x] = tmp[x].detach(); configuration.setTrainingWorkspaceMode(cMode); return tmp; } }
log.warn("Tried keras sequence config", e); try { return ComputationGraphConfiguration.fromJson(input); } catch (Exception e3) { log.warn("Tried computation graph from json"); log.warn("Tried multi layer configuration from yaml"); try { return ComputationGraphConfiguration.fromYaml(input); } catch (Exception e5) { throw e5;
LayerVertex lv = (LayerVertex) origConfig.getVertices().get(layerName); String[] lvInputs = origConfig.getVertexInputs().get(layerName).toArray(new String[0]); editedConfigBuilder.addLayer(layerName, layerImpl, lv.getPreProcessor(), lvInputs); editedVertices.add(layerName); for (Map.Entry<String, List<String>> entry : origConfig.getVertexInputs().entrySet()) { String currentVertex = entry.getKey(); if (!currentVertex.equals(layerName)) { lv = (LayerVertex) origConfig.getVertices().get(fanoutVertexName); lvInputs = origConfig.getVertexInputs().get(fanoutVertexName).toArray(new String[0]); editedConfigBuilder.addLayer(fanoutVertexName, layerImpl, lv.getPreProcessor(), lvInputs); editedVertices.add(fanoutVertexName);
newConfig.setTrainingWorkspaceMode(workspaceMode); ComputationGraph newGraph = new ComputationGraph(newConfig); newGraph.init(); LayerVertex currLayerVertex = (LayerVertex) newConfig.getVertices().get(layerName); Layer origLayerConf = currLayerVertex.getLayerConf().getLayer(); Layer newLayerConf = new org.deeplearning4j.nn.conf.layers.misc.FrozenLayer(origLayerConf);
numParams = cg.numParams(); numLayers = cg.getNumLayers(); modelConfigJson = cg.getConfiguration().toJson(); totalNumUpdates = cg.getConfiguration().getIterationCount(); } else { score = 0;
conf.setTrainingWorkspaceMode(WorkspaceMode.SINGLE); conf.setInferenceWorkspaceMode(WorkspaceMode.SEPARATE); conf.validate();
@Override public ComputationGraphConfiguration deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { ComputationGraphConfiguration conf = (ComputationGraphConfiguration) defaultDeserializer.deserialize(jp, ctxt); //Updater configuration changed after 0.8.0 release //Previously: enumerations and fields. Now: classes //Here, we manually create the appropriate Updater instances, if the IUpdater field is empty List<Layer> layerList = new ArrayList<>(); Map<String, GraphVertex> vertices = conf.getVertices(); for (Map.Entry<String, GraphVertex> entry : vertices.entrySet()) { if (entry.getValue() instanceof LayerVertex) { LayerVertex lv = (LayerVertex) entry.getValue(); layerList.add(lv.getLayerConf().getLayer()); } } Layer[] layers = layerList.toArray(new Layer[layerList.size()]); handleUpdaterBackwardCompatibility(layers); return conf; } }
connections = configuration.getVertexInputs().get(name).toString();
ComputationGraph network = (ComputationGraph) obj; boolean paramsEquals = network.params().equals(params()); boolean confEquals = getConfiguration().equals(network.getConfiguration()); boolean updaterEquals = getUpdater().equals(network.getUpdater()); return paramsEquals && confEquals && updaterEquals;