.build()) .inputPreProcessor(0, new RnnToCnnPreProcessor(V_HEIGHT, V_WIDTH, 3)) .inputPreProcessor(3, new CnnToFeedForwardPreProcessor(7, 7, 10)) .inputPreProcessor(4, new FeedForwardToRnnPreProcessor()) .pretrain(false).backprop(true)
@Override public TensorFlowCnnToFeedForwardPreProcessor clone() { return (TensorFlowCnnToFeedForwardPreProcessor) super.clone(); } }
@Override public INDArray backprop(INDArray epsilons, int miniBatchSize) { INDArray epsilonsReshaped = super.backprop(epsilons, miniBatchSize); return epsilonsReshaped.permute(0, 3, 1, 2); }
@Override public INDArray preProcess(INDArray input, int miniBatchSize) { if (input.rank() == 2) return input; //Should usually never happen /* DL4J convolutional input: # channels, # rows, # cols * TensorFlow convolutional input: # rows, # cols, # channels * Theano convolutional input: # channels, # rows, # cols */ /* TODO: remove the extra copies of the input. These are only * used for debugging purposes during development and testing. */ INDArray flatInput = super.preProcess(input, miniBatchSize); INDArray permuted = input.permute(0, 2, 3, 1); INDArray flatPermuted = super.preProcess(permuted, miniBatchSize); return flatPermuted; }
@Override public InputPreProcessor getPreProcessorForInputType(InputType inputType) { if (inputType == null) { throw new IllegalStateException( "Invalid input for layer (layer name = \"" + getLayerName() + "\"): input type is null"); } switch (inputType.getType()) { case FF: case CNNFlat: //FF -> FF and CNN (flattened format) -> FF: no preprocessor necessary return null; case RNN: //RNN -> FF return new RnnToFeedForwardPreProcessor(); case CNN: //CNN -> FF InputType.InputTypeConvolutional c = (InputType.InputTypeConvolutional) inputType; return new CnnToFeedForwardPreProcessor(c.getHeight(), c.getWidth(), c.getDepth()); default: throw new RuntimeException("Unknown input type: " + inputType); } }
case NONE: case THEANO: preprocessor = new CnnToFeedForwardPreProcessor(it.getHeight(), it.getWidth(), it.getDepth()); break; case TENSORFLOW:
.removeVertexKeepConnections("flatten") .addVertex("flatten", new PreprocessorVertex(new CnnToFeedForwardPreProcessor(8, 8, 512)), "block5_pool") .removeVertexKeepConnections("fc1")