Search in sources :

Example 1 with ListValue

use of com.google.protobuf.ListValue in project seldon-core by SeldonIO.

the class PredictorUtils method getINDArray.

public static INDArray getINDArray(DefaultData data) {
    if (data.getDataOneofCase() == DataOneofCase.TENSOR) {
        List<Double> valuesList = data.getTensor().getValuesList();
        List<Integer> shapeList = data.getTensor().getShapeList();
        double[] values = new double[valuesList.size()];
        int[] shape = new int[shapeList.size()];
        for (int i = 0; i < values.length; i++) {
            values[i] = valuesList.get(i);
        }
        for (int i = 0; i < shape.length; i++) {
            shape[i] = shapeList.get(i);
        }
        INDArray newArr = Nd4j.create(values, shape, 'c');
        return newArr;
    } else if (data.getDataOneofCase() == DataOneofCase.NDARRAY) {
        ListValue list = data.getNdarray();
        int bLength = list.getValuesCount();
        int vLength = list.getValues(0).getListValue().getValuesCount();
        double[] values = new double[bLength * vLength];
        int[] shape = { bLength, vLength };
        for (int i = 0; i < bLength; ++i) {
            for (int j = 0; j < vLength; j++) {
                values[i * bLength + j] = list.getValues(i).getListValue().getValues(j).getNumberValue();
            }
        }
        INDArray newArr = Nd4j.create(values, shape, 'c');
        return newArr;
    }
    return null;
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) ListValue(com.google.protobuf.ListValue)

Aggregations

ListValue (com.google.protobuf.ListValue)1 INDArray (org.nd4j.linalg.api.ndarray.INDArray)1