-
Notifications
You must be signed in to change notification settings - Fork 45.3k
Open
Labels
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;
}
Reactions are currently unavailable