tensorflow / tensorflow/models

Detect Nothing on Android device

Open
#8,680 4 comments 0 reactions 3 assignees View on GitHub

@pkulzc is already working on this.

Since Jun 16, 2020.

models:research:odapi type:support
Dominant language
Python
Stars
77.7k
Forks
44.8k
PR merge metrics
No merged PRs in 30d

Description

I trained a mobilenet_v2_ssd and quantized to uint8. It runs ok on the official android demo, but detect nothing on my own app when input a same image.

The method as following, no detection result in outputMap.

    public List<Prediction> predict(Bitmap image) {
        outputLocations = new float[1][NUM_DETECTIONS][4];
        outputClasses = new float[1][NUM_DETECTIONS];
        outputScores = new float[1][NUM_DETECTIONS];
        numDetections = new float[1];
        int[] intValues = new int[300*300];
        image.getPixels(intValues, 0, 300, 0,0,300,300);
        this.imgData.rewind();
        for (int i = 0; i < 300; ++i) {
            for (int j = 0; j < 300; ++j) {
                int pixelValue = intValues[i * 300 + j];
                this.imgData.put((byte) ((pixelValue >> 16) & 0xFF));
                this.imgData.put((byte) ((pixelValue >> 8) & 0xFF));
                this.imgData.put((byte) (pixelValue & 0xFF));
            }
        }
        Object[] inputArray = {this.imgData};
        Map<Integer, Object> outputMap = new HashMap<>();
        outputMap.put(0, outputLocations);
        outputMap.put(1, outputClasses);
        outputMap.put(2, outputScores);
        outputMap.put(3, numDetections);
        this.interpreter.runForMultipleInputsOutputs(inputArray, outputMap);
        int numDetectionsOutput = Math.min(NUM_DETECTIONS, (int) numDetections[0]);
        final ArrayList<Prediction> predictions = new ArrayList<>(numDetectionsOutput);
        for (int i = 0; i < numDetectionsOutput; ++i) {
            final RectF bbox =
                    new RectF(
                            outputLocations[0][i][1] * inputSize,
                            outputLocations[0][i][0] * inputSize,
                            outputLocations[0][i][3] * inputSize,
                            outputLocations[0][i][2] * inputSize);
            int labelOffset = 1;
            predictions.add(
                    new Prediction(
                            "" + i,
                            labels.get((int) outputClasses[0][i] + labelOffset),
                            outputScores[0][i],
                            bbox));
            Log.i("InferenceEngine", predictions.get(i).toString());
        }
        return predictions;
    }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.