When I put date into a f tensor ,I found it took so much long time ?Why? it spent so much time? Here is my code.My tensor shape is 395*395*3, it took about 300+ms to fill tensor with data. but the excute process spent only 100+ms.
private void writeRgbBitmapAsFloat(Bitmap image, FloatBuffer meanImage, FloatTensor tensor) { final int[] pixels = new int[image.getWidth() * image.getHeight()]; image.getPixels(pixels, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight()); Log.i("-----","prepare data------1 - 0: " + (System.currentTimeMillis() - mTimeCounter)); mTimeCounter = System.currentTimeMillis(); for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { final int rgb = pixels[y * image.getWidth() + x]; float b = ((rgb) & 0xFF) - meanImage.get(); float g = ((rgb >> 8) & 0xFF) - meanImage.get(); float r = ((rgb >> 16) & 0xFF) - meanImage.get(); float[] pixelFloats = {b, g, r}; tensor.write(pixelFloats, 0, pixelFloats.length, y, x); } } Log.i("-----","prepare data------1-1: " + (System.currentTimeMillis() - mTimeCounter)); mTimeCounter = System.currentTimeMillis(); }
Try:
To see if it makes a difference.
Cheers,
Simon