@Override public void initializeBackend() { this.backend = new org.deeplearning4j.nn.conf.layers.ZeroPaddingLayer(); } }
@Override public InputPreProcessor getPreProcessorForInputType(InputType inputType) { if (inputType == null) { throw new IllegalStateException("Invalid input for ZeroPaddingLayer layer (layer name=\"" + getLayerName() + "\"): input is null"); } return InputTypeUtil.getPreProcessorForInputTypeCnnLayers(inputType, getLayerName()); }
public void setPadding(int[] padding) { backend.setPadding(padding); }
@OptionMetadata( displayName = "number of columns in padding", description = "The number of columns in the padding (default = 0).", commandLineParamName = "paddingColumns", commandLineParamSynopsis = "-paddingColumns <int>", displayOrder = 9 ) public int getPaddingColumns() { return backend.getPadding()[1]; }
/** * Get layer output type. * * @param inputType Array of InputTypes * @return output type as InputType * @throws InvalidKerasConfigurationException */ @Override public InputType getOutputType(InputType... inputType) throws InvalidKerasConfigurationException { if (inputType.length > 1) throw new InvalidKerasConfigurationException( "Keras ZeroPadding layer accepts only one input (received " + inputType.length + ")"); return this.getZeroPaddingLayer().getOutputType(-1, inputType[0]); }
@Override public org.deeplearning4j.nn.api.Layer instantiate(NeuralNetConfiguration conf, Collection<IterationListener> iterationListeners, int layerIndex, INDArray layerParamsView, boolean initializeParams) { org.deeplearning4j.nn.layers.convolution.ZeroPaddingLayer ret = new org.deeplearning4j.nn.layers.convolution.ZeroPaddingLayer(conf); ret.setListeners(iterationListeners); ret.setIndex(layerIndex); Map<String, INDArray> paramTable = initializer().init(conf, layerParamsView, initializeParams); ret.setParamTable(paramTable); ret.setConf(conf); return ret; }
@OptionMetadata( displayName = "number of rows in padding", description = "The number of rows in the padding (default = 0).", commandLineParamName = "paddingRows", commandLineParamSynopsis = "-paddingRows <int>", displayOrder = 8 ) public int getPaddingRows() { return backend.getPadding()[0]; }
@Override public LayerMemoryReport getMemoryReport(InputType inputType) { InputType outputType = getOutputType(-1, inputType); return new LayerMemoryReport.Builder(layerName, ZeroPaddingLayer.class, inputType, outputType) .standardMemory(0, 0) //No params //Inference and training is same - just output activations, no working memory in addition to that .workingMemory(0, 0, MemoryReport.CACHE_MODE_ALL_ZEROS, MemoryReport.CACHE_MODE_ALL_ZEROS) .cacheMemory(MemoryReport.CACHE_MODE_ALL_ZEROS, MemoryReport.CACHE_MODE_ALL_ZEROS) //No caching .build(); }
@ProgrammaticProperty public int[] getPadding() { return backend.getPadding(); }
@Override @SuppressWarnings("unchecked") public ZeroPaddingLayer build() { for (int p : padding) { if (p < 0) { throw new IllegalStateException( "Invalid zero padding layer config: padding [top, bottom, left, right]" + " must be > 0 for all elements. Got: " + Arrays.toString(padding)); } } return new ZeroPaddingLayer(this); } }
public void setPaddingColumns(int padding) { int[] pad = new int[]{getPaddingRows(), padding}; backend.setPadding(pad); }
public ZeroPaddingLayer(NeuralNetConfiguration conf) { super(conf); this.padding = ((org.deeplearning4j.nn.conf.layers.ZeroPaddingLayer) conf.getLayer()).getPadding(); }
public void setPaddingRows(int padding) { int[] pad = new int[]{padding, getPaddingColumns()}; backend.setPadding(pad); }