Java Code Examples for org.nd4j.linalg.dataset.api.DataSet#setLabelsMaskArray()

The following examples show how to use org.nd4j.linalg.dataset.api.DataSet#setLabelsMaskArray() . 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: UnderSamplingByMaskingPreProcessor.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Override
public void preProcess(DataSet toPreProcess) {
    INDArray label = toPreProcess.getLabels();
    INDArray labelMask = toPreProcess.getLabelsMaskArray();
    INDArray sampledMask = adjustMasks(label, labelMask, minorityLabel, targetMinorityDist);
    toPreProcess.setLabelsMaskArray(sampledMask);
}
 
Example 2
Source File: UnderSamplingByMaskingPreProcessor.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Override
public void preProcess(DataSet toPreProcess) {
    INDArray label = toPreProcess.getLabels();
    INDArray labelMask = toPreProcess.getLabelsMaskArray();
    INDArray sampledMask = adjustMasks(label, labelMask, minorityLabel, targetMinorityDist);
    toPreProcess.setLabelsMaskArray(sampledMask);
}
 
Example 3
Source File: LabelLastTimeStepPreProcessor.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Override
public void preProcess(DataSet toPreProcess) {

    INDArray label3d = toPreProcess.getLabels();
    Preconditions.checkState(label3d.rank() == 3, "LabelLastTimeStepPreProcessor expects rank 3 labels, got rank %s labels with shape %ndShape", label3d.rank(), label3d);

    INDArray lMask = toPreProcess.getLabelsMaskArray();
    //If no mask: assume that examples for each minibatch are all same length
    INDArray labels2d;
    if(lMask == null){
        labels2d = label3d.get(NDArrayIndex.all(), NDArrayIndex.all(), NDArrayIndex.point(label3d.size(2)-1)).dup();
    } else {
        //Use the label mask to work out the last time step...
        INDArray lastIndex = BooleanIndexing.lastIndex(lMask, Conditions.greaterThan(0), 1);
        long[] idxs = lastIndex.data().asLong();

        //Now, extract out:
        labels2d = Nd4j.create(DataType.FLOAT, label3d.size(0), label3d.size(1));

        //Now, get and assign the corresponding subsets of 3d activations:
        for (int i = 0; i < idxs.length; i++) {
            long lastStepIdx = idxs[i];
            Preconditions.checkState(lastStepIdx >= 0, "Invalid last time step index: example %s in minibatch is entirely masked out" +
                    " (label mask is all 0s, meaning no label data is present for this example)", i);
            //TODO can optimize using reshape + pullRows
            labels2d.putRow(i, label3d.get(NDArrayIndex.point(i), NDArrayIndex.all(), NDArrayIndex.point(lastStepIdx)));
        }
    }

    toPreProcess.setLabels(labels2d);
    toPreProcess.setLabelsMaskArray(null);  //Remove label mask if present
}