@OptionMetadata( displayName = "layer name", description = "The name of the layer (default = Batch normalization Layer).", commandLineParamName = "name", commandLineParamSynopsis = "-name <string>", displayOrder = 0 ) public String getLayerName() { return backend.getLayerName(); }
@Override public int numParams(boolean backprop) { return layerConf.getLayer().initializer().numParams(layerConf); }
private MultiLayerConfiguration constructConf() { //use the editedConfs list to make a new config List<NeuralNetConfiguration> allConfs = new ArrayList<>(); allConfs.addAll(editedConfs); allConfs.addAll(appendConfs); //Set default layer names, if not set - as per NeuralNetConfiguration.ListBuilder.build() for (int i = 0; i < allConfs.size(); i++) { if (allConfs.get(i).getLayer().getLayerName() == null) { allConfs.get(i).getLayer().setLayerName("layer" + i); } } MultiLayerConfiguration conf = new MultiLayerConfiguration.Builder().inputPreProcessors(inputPreProcessors) .setInputType(this.inputType).confs(allConfs).build(); if (finetuneConfiguration != null) { finetuneConfiguration.applyToMultiLayerConfiguration(conf); } return conf; } }
throw new IllegalStateException("When using SGD updater, must also use lr=1.0 for layer " + layerCount + "; got " + u + " with lr=" + lr + " for layer \"" + n.getLayer().getLayerName() + "\""); double dropout = n.getLayer().getDropOut(); if (n.isUseRegularization() && dropout != 0.0) { throw new IllegalStateException("Must have dropout == 0.0 for gradient checks - got dropout = "
/** * Get a {@link MemoryReport} for the given MultiLayerConfiguration. This is used to estimate the * memory requirements for the given network configuration and input * * @param inputType Input types for the network * @return Memory report for the network */ public NetworkMemoryReport getMemoryReport(InputType inputType) { Map<String, MemoryReport> memoryReportMap = new LinkedHashMap<>(); int nLayers = confs.size(); for (int i = 0; i < nLayers; i++) { String layerName = confs.get(i).getLayer().getLayerName(); if (layerName == null) { layerName = String.valueOf(i); } //Pass input type through preprocessor, if necessary InputPreProcessor preproc = getInputPreProcess(0); //TODO memory requirements for preprocessor if (preproc != null) { inputType = preproc.getOutputType(inputType); } LayerMemoryReport report = confs.get(i).getLayer().getMemoryReport(inputType); memoryReportMap.put(layerName, report); inputType = confs.get(i).getLayer().getOutputType(i, inputType); } return new NetworkMemoryReport(memoryReportMap, MultiLayerConfiguration.class, "MultiLayerNetwork", inputType); }
for (int i = 0; i < nLayers; i++) { NeuralNetConfiguration conf = layerWiseConfigurations.getConf(i); nParamsPerLayer[i] = conf.getLayer().initializer().numParams(conf); paramLength += nParamsPerLayer[i]; layers[i] = conf.getLayer().instantiate(conf, listeners, i, paramsView, initializeParams); layerMap.put(conf.getLayer().getLayerName(), layers[i]);
l.setDropOut(dropOut); LayerValidation.updaterValidation(l.getLayerName(), l, learningRate, momentum, momentumSchedule, adamMeanDecay, adamVarDecay, rho, rmsDecay, epsilon); LayerValidation.generalValidation(l.getLayerName(), l, nnc.isUseRegularization(), useDropCon, dropOut, l2, l2Bias, l1, l1Bias, dist);
finetuneConfiguration.appliedNeuralNetConfigurationBuilder().layer(layer).build(); int numParams = layer.initializer().numParams(layerConf); INDArray params; if (numParams > 0) { params = Nd4j.create(1, numParams); org.deeplearning4j.nn.api.Layer someLayer = layer.instantiate(layerConf, null, 0, params, true); appendParams.add(someLayer.params()); appendConfs.add(someLayer.conf());
if (conf.isUseDropConnect() && training && conf.getLayer().getDropOut() > 0) { W = Dropout.applyDropConnect(this, CDAEParamInitializer.WEIGHT_KEY);
if (inputPreProcessors.get(i) == null) { InputPreProcessor inputPreProcessor = l.getPreProcessorForInputType(currentInputType); if (inputPreProcessor != null) { inputPreProcessors.put(i, inputPreProcessor); currentInputType = inputPreProcessor.getOutputType(currentInputType); l.setNIn(currentInputType, false); //Don't override the nIn setting, if it's manually set by the user currentInputType = l.getOutputType(i, currentInputType);
Layer layerImpl = layerConf.getLayer().clone(); layerImpl.resetLayerDefaultConfig(); FeedForwardLayer layerImplF = (FeedForwardLayer) layerImpl; layerImplF.setWeightInit(scheme); layerImpl = layerConf.getLayer().clone(); layerImplF = (FeedForwardLayer) layerImpl; layerImplF.setWeightInit(schemeNext);
@Override public void setLayerName(String layerName) { super.setLayerName(layerName); layer.setLayerName(layerName); }
InputPreProcessor preproc = l.getPreProcessorForInputType(layerInput); lv.setPreProcessor(preproc); afterPreproc = ip.getOutputType(layerInput); l.setNIn(afterPreproc, false);
private void copyConfigToLayer(String layerName, Layer layer) { if (Double.isNaN(layer.getDropOut())) layer.setDropOut(dropOut);
@Override public InputPreProcessor getPreProcessorForInputType(InputType inputType) { return layer.getPreProcessorForInputType(inputType); }
if (layerwise.get(i).getLayer().getLayerName() == null) { layerwise.get(i).getLayer().setLayerName("layer" + i);
throw new IllegalStateException("When using SGD updater, must also use lr=1.0 for layer " + layerCount + "; got " + u + " with lr=" + lr + " for layer \"" + lv.getLayerConf().getLayer().getLayerName() + "\""); double dropout = lv.getLayerConf().getLayer().getDropOut(); if (lv.getLayerConf().isUseRegularization() && dropout != 0.0) { throw new IllegalStateException("Must have dropout == 0.0 for gradient checks - got dropout = "
private void nOutReplaceBuild(int layerNum, int nOut, Pair<WeightInit, Distribution> schemedist, Pair<WeightInit, Distribution> schemedistNext) { NeuralNetConfiguration layerConf = editedConfs.get(layerNum); Layer layerImpl = layerConf.getLayer(); //not a clone need to modify nOut in place FeedForwardLayer layerImplF = (FeedForwardLayer) layerImpl; layerImplF.setWeightInit(schemedist.getLeft()); layerImplF.setDist(schemedist.getRight()); layerImplF.setNOut(nOut); int numParams = layerImpl.initializer().numParams(layerConf); INDArray params = Nd4j.create(1, numParams); org.deeplearning4j.nn.api.Layer someLayer = layerImpl.instantiate(layerConf, null, 0, params, true); editedParams.set(layerNum, someLayer.params()); if (layerNum + 1 < editedConfs.size()) { layerConf = editedConfs.get(layerNum + 1); layerImpl = layerConf.getLayer(); //modify in place layerImplF = (FeedForwardLayer) layerImpl; layerImplF.setWeightInit(schemedistNext.getLeft()); layerImplF.setDist(schemedistNext.getRight()); layerImplF.setNIn(nOut); numParams = layerImpl.initializer().numParams(layerConf); if (numParams > 0) { params = Nd4j.create(1, numParams); someLayer = layerImpl.instantiate(layerConf, null, 0, params, true); editedParams.set(layerNum + 1, someLayer.params()); } } }
/** * Reconstructs the visible INPUT. * A reconstruction is a propdown of the reconstructed hidden input. * @param training true or false * @return the reconstruction of the visible input */ @Override public INDArray activate(boolean training) { if (training && conf.getLayer().getDropOut() > 0.0) { Dropout.applyDropout(input, conf.getLayer().getDropOut()); } //reconstructed: propUp ----> hidden propDown to transform INDArray propUp = propUp(input, training); return propUp; }