Java Code Examples for org.nd4j.linalg.dataset.api.DataSet#setFeatures()
The following examples show how to use
org.nd4j.linalg.dataset.api.DataSet#setFeatures() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageFlatteningDataSetPreProcessor.java From nd4j with Apache License 2.0 | 6 votes |
@Override public void preProcess(DataSet toPreProcess) { INDArray input = toPreProcess.getFeatures(); if (input.rank() == 2) return; //No op: should usually never happen in a properly configured data pipeline //Assume input is standard rank 4 activations - i.e., CNN image data //First: we require input to be in c order. But c order (as declared in array order) isn't enough; also need strides to be correct if (input.ordering() != 'c' || !Shape.strideDescendingCAscendingF(input)) input = input.dup('c'); val inShape = input.shape(); //[miniBatch,depthOut,outH,outW] val outShape = new long[] {inShape[0], inShape[1] * inShape[2] * inShape[3]}; INDArray reshaped = input.reshape('c', outShape); toPreProcess.setFeatures(reshaped); }
Example 2
Source File: ImageFlatteningDataSetPreProcessor.java From deeplearning4j with Apache License 2.0 | 6 votes |
@Override public void preProcess(DataSet toPreProcess) { INDArray input = toPreProcess.getFeatures(); if (input.rank() == 2) return; //No op: should usually never happen in a properly configured data pipeline //Assume input is standard rank 4 activations - i.e., CNN image data //First: we require input to be in c order. But c order (as declared in array order) isn't enough; also need strides to be correct if (input.ordering() != 'c' || !Shape.strideDescendingCAscendingF(input)) input = input.dup('c'); val inShape = input.shape(); //[miniBatch,depthOut,outH,outW] val outShape = new long[] {inShape[0], inShape[1] * inShape[2] * inShape[3]}; INDArray reshaped = input.reshape('c', outShape); toPreProcess.setFeatures(reshaped); }
Example 3
Source File: CropAndResizeDataSetPreProcessor.java From deeplearning4j with Apache License 2.0 | 6 votes |
/** * NOTE: The data format must be NHWC */ @Override public void preProcess(DataSet dataSet) { Preconditions.checkNotNull(dataSet, "Encountered null dataSet"); if(dataSet.isEmpty()) { return; } INDArray input = dataSet.getFeatures(); INDArray output = Nd4j.create(LongShapeDescriptor.fromShape(resizedShape, input.dataType()), false); CustomOp op = DynamicCustomOp.builder("crop_and_resize") .addInputs(input, boxes, indices, resize) .addIntegerArguments(method) .addOutputs(output) .build(); Nd4j.getExecutioner().exec(op); dataSet.setFeatures(output); }
Example 4
Source File: RGBtoGrayscaleDataSetPreProcessor.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public void preProcess(DataSet dataSet) { Preconditions.checkNotNull(dataSet, "Encountered null dataSet"); if(dataSet.isEmpty()) { return; } INDArray originalFeatures = dataSet.getFeatures(); long[] originalShape = originalFeatures.shape(); // result shape is NHW INDArray result = Nd4j.create(originalShape[0], originalShape[2], originalShape[3]); for(long n = 0, numExamples = originalShape[0]; n < numExamples; ++n) { // Extract channels INDArray itemFeatures = originalFeatures.slice(n, 0); // shape is CHW INDArray R = itemFeatures.slice(0, 0); // shape is HW INDArray G = itemFeatures.slice(1, 0); INDArray B = itemFeatures.slice(2, 0); // Convert R.muli(RED_RATIO); G.muli(GREEN_RATIO); B.muli(BLUE_RATIO); R.addi(G).addi(B); result.putSlice((int)n, R); } dataSet.setFeatures(result); }
Example 5
Source File: PermuteDataSetPreProcessor.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public void preProcess(DataSet dataSet) { Preconditions.checkNotNull(dataSet, "Encountered null dataSet"); if(dataSet.isEmpty()) { return; } INDArray input = dataSet.getFeatures(); INDArray output; switch (permutationType) { case NCHWtoNHWC: output = input.permute(0, 2, 3, 1); break; case NHWCtoNCHW: output = input.permute(0, 3, 1, 2); break; case Custom: output = input.permute(rearrange); break; default: output = input; break; } dataSet.setFeatures(output); }