當前位置: 首頁>>代碼示例>>Java>>正文


Java FloatBuffer.array方法代碼示例

本文整理匯總了Java中java.nio.FloatBuffer.array方法的典型用法代碼示例。如果您正苦於以下問題:Java FloatBuffer.array方法的具體用法?Java FloatBuffer.array怎麽用?Java FloatBuffer.array使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.nio.FloatBuffer的用法示例。


在下文中一共展示了FloatBuffer.array方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toFloatArray

import java.nio.FloatBuffer; //導入方法依賴的package包/類
static
public float[] toFloatArray(Tensor tensor){
	FloatBuffer floatBuffer = FloatBuffer.allocate(tensor.numElements());

	tensor.writeTo(floatBuffer);

	return floatBuffer.array();
}
 
開發者ID:jpmml,項目名稱:jpmml-tensorflow,代碼行數:9,代碼來源:TensorUtil.java

示例2: bufferToFloatArray

import java.nio.FloatBuffer; //導入方法依賴的package包/類
private static float[] bufferToFloatArray(ByteBuffer buffer) {
	buffer.order(ByteOrder.nativeOrder());
	FloatBuffer floats = buffer.asFloatBuffer();

	if (floats.hasArray()) {
		return floats.array();
	} else {
		float[] resultArray = new float[floats.capacity()];
		floats.get(resultArray);
		return resultArray;
	}
}
 
開發者ID:OpenDA-Association,項目名稱:OpenDA,代碼行數:13,代碼來源:ThriftBmiBridge.java

示例3: executeDvsFrameGraph

import java.nio.FloatBuffer; //導入方法依賴的package包/類
/**
     * Executes the stored Graph of the CNN.
     *
     * //https://github.com/tensorflow/tensorflow/blob/master/tensorflow/java/src/main/java/org/tensorflow/op/Operands.java
     * // https://github.com/tensorflow/tensorflow/issues/7149
     * https://stackoverflow.com/questions/44774234/why-tensorflow-uses-channel-last-ordering-instead-of-row-major
     *
     * @param pixbuf the pixel buffer holding the frame, as collected from
     * DVSFramer in DVSFrame.
     *
     * @param width width of image
     * @param height height of image
     * @return activations of output
     */
    private float[] executeDvsFrameGraph(FloatBuffer pixbuf, int width, int height) {
//        final float mean = processor.getImageMean(), scale = processor.getImageScale();
        final int numChannels = processor.isMakeRGBFrames() ? 3 : 1;
        inputLayer = new InputLayer(width, height, numChannels); // TODO hack since we don't know the input size yet until network runs

        // TODO super hack brute force to flip image vertically because tobi cannot see how to flip an image in TensorFlow.
        // Also, make RGB frame from gray dvs image by cloning the gray value to each channel in WHC order
        final float[] origarray = pixbuf.array();
        FloatBuffer flipped = FloatBuffer.allocate(pixbuf.limit() * numChannels);
        final float[] flippedarray = flipped.array();
        // prepare rgb scaling factors to make RGB channels from grayscale. each channel has different weighting
        float[] rgb = null;
        if (processor.isMakeRGBFrames()) {
            rgb = new float[]{1, 1, 1};
        } else {
            rgb = new float[]{1};
        }
        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                final int origIdx = x + width * y;
                for (int c = 0; c < numChannels; c++) {
                    final int newIdx = c + numChannels * (x + (width * (height - y - 1)));
                    flippedarray[newIdx] = ((origarray[origIdx] * rgb[c]));
                }
            }
        }
        flipped = FloatBuffer.wrap(flippedarray);

        try (Tensor<Float> imageTensor = Tensor.create(new long[]{1, height, width, numChannels}, flipped);) { // use NHWC order according to last post above
//            int numElements = imageTensor.numElements();
//            long[] shape = imageTensor.shape();
            float[] output = TensorFlow.executeGraph(executionGraph, imageTensor, processor.getInputLayerName(), processor.getOutputLayerName());
            outputLayer = new OutputLayer(output);
            getSupport().firePropertyChange(EVENT_MADE_DECISION, null, this);
            return output;
        } catch (IllegalArgumentException ex) {
            StringBuilder msg = new StringBuilder("<html>Caught exception <p>" + ex.toString() + "<p>Did you set inputLayerName and outputLayerName in the property group <i>2. Analysis</i>?</p>");
            msg.append("<p>The IO layer names could be as follows (the string inside the single quotes):</p> <ul> ");
            for (String s : ioLayers) {
                msg.append("<li>" + (s.replaceAll("<", "").replaceAll(">", "")) + "</li>");
            }
            msg.append("</ul>");
            JOptionPane.showMessageDialog(processor.getChip().getAeViewer(), msg.toString(),
                    "Error computing network", JOptionPane.WARNING_MESSAGE);
            throw new IllegalArgumentException(ex.getCause());
        }
    }
 
開發者ID:SensorsINI,項目名稱:jaer,代碼行數:62,代碼來源:DavisCNNTensorFlow.java


注:本文中的java.nio.FloatBuffer.array方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。