Implementing mobilenetssd with SNPE

248 views Asked by At

I managed to transform the ssd_mobilenet_v1_coco_2017_11_17 model to a dlc file.

The model ran on Android but the output is practically blank (only 1.0 for scores, 0.0 for boxes and classes)

I'm not sure what exactly is wrong.

float[] loadRgbBitmapAsFloat(Bitmap image) {
    final int[] pixels = new int[image.getWidth() * image.getHeight()];
    image.getPixels(pixels, 0, image.getWidth(), 0, 0,
            image.getWidth(), image.getHeight());

    final float[] pixelsBatched = new float[pixels.length * 3];
    for (int y = 0; y < image.getHeight(); y++) {
        for (int x = 0; x < image.getWidth(); x++) {
            final int idx = y * image.getWidth() + x;
            final int batchIdx = idx * 3;

            final float[] rgb = extractColorChannels(pixels[idx]);
            pixelsBatched[batchIdx]     = rgb[0];
            pixelsBatched[batchIdx + 1] = rgb[1];
            pixelsBatched[batchIdx + 2] = rgb[2];
        }
    }
    return pixelsBatched;
}

private float[] extractColorChannels(int pixel) {
    float b = ((pixel)       & 0xFF);
    float g = ((pixel >>  8) & 0xFF);
    float r = ((pixel >> 16) & 0xFF);

    return new float[] {r,g,b};

}

this is how I preprocessed the already cropped Image, which in this case is 300x300. The model is unquantized and I am using FloatTensor. I did try to use UserBufferTensor but I got an error instead saying that the forward propagation did not work.

0

There are 0 answers