.inputPreProcessor(0, new RnnToCnnPreProcessor(V_HEIGHT, V_WIDTH, 3)) .inputPreProcessor(3, new CnnToFeedForwardPreProcessor(7, 7, 10)) .inputPreProcessor(4, new FeedForwardToRnnPreProcessor()) .pretrain(false).backprop(true) .backpropType(BackpropType.TruncatedBPTT)
public static InputPreProcessor getPreprocessorForInputTypeRnnLayers(InputType inputType, String layerName) { if (inputType == null) { throw new IllegalStateException( "Invalid input for RNN layer (layer name = \"" + layerName + "\"): input type is null"); } switch (inputType.getType()) { case FF: case CNNFlat: //FF -> RNN or CNNFlat -> RNN //In either case, input data format is a row vector per example return new FeedForwardToRnnPreProcessor(); case RNN: //RNN -> RNN: No preprocessor necessary return null; case CNN: //CNN -> RNN InputType.InputTypeConvolutional c = (InputType.InputTypeConvolutional) inputType; return new CnnToRnnPreProcessor(c.getHeight(), c.getWidth(), c.getDepth()); default: throw new RuntimeException("Unknown input type: " + inputType); } }
/** * Gets appropriate DL4J InputPreProcessor for given InputTypes. * * @param inputType Array of InputTypes * @return DL4J InputPreProcessor * @throws InvalidKerasConfigurationException * @see org.deeplearning4j.nn.conf.InputPreProcessor */ public InputPreProcessor getInputPreprocessor(InputType... inputType) throws InvalidKerasConfigurationException { if (inputType.length > 1) throw new InvalidKerasConfigurationException( "Keras GlobalPooling layer accepts only one input (received " + inputType.length + ")"); InputPreProcessor preprocessor; if (inputType[0].getType() == InputType.Type.FF && this.dimensions.length == 1) { preprocessor = new FeedForwardToRnnPreProcessor(); } else { preprocessor = this.getGlobalPoolingLayer().getPreProcessorForInputType(inputType[0]); } return preprocessor; }