Arresttb Model latest
This commit is contained in:
Binary file not shown.
@@ -28,9 +28,14 @@ public class TensorFlowImageClassifier implements Classifier {
|
||||
private static final int PIXEL_SIZE = 3;
|
||||
private static final float THRESHOLD = 0.1f;
|
||||
|
||||
private static final int IMAGE_MEAN = 128;
|
||||
private static final float IMAGE_STD = 128.0f;
|
||||
|
||||
private Interpreter interpreter;
|
||||
private int inputSize;
|
||||
private List<String> labelList;
|
||||
private boolean quant;
|
||||
|
||||
|
||||
private TensorFlowImageClassifier() {
|
||||
|
||||
@@ -52,9 +57,13 @@ public class TensorFlowImageClassifier implements Classifier {
|
||||
@Override
|
||||
public List<Recognition> recognizeImage(Bitmap bitmap) {
|
||||
ByteBuffer byteBuffer = convertBitmapToByteBuffer(bitmap);
|
||||
/* ByteBuffer byteBuffer = convertBitmapToByteBuffer(bitmap);
|
||||
byte[][] result = new byte[1][labelList.size()];
|
||||
interpreter.run(byteBuffer, result);
|
||||
return getSortedResult(result);
|
||||
return getSortedResult(result);*/
|
||||
float [][] result = new float[1][labelList.size()];
|
||||
interpreter.run(byteBuffer, result);
|
||||
return getSortedResultFloat(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -84,7 +93,8 @@ public class TensorFlowImageClassifier implements Classifier {
|
||||
}
|
||||
|
||||
private ByteBuffer convertBitmapToByteBuffer(Bitmap bitmap) {
|
||||
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(BATCH_SIZE * inputSize * inputSize * PIXEL_SIZE);
|
||||
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(4 * BATCH_SIZE * inputSize * inputSize * PIXEL_SIZE);
|
||||
|
||||
byteBuffer.order(ByteOrder.nativeOrder());
|
||||
int[] intValues = new int[inputSize * inputSize];
|
||||
bitmap.getPixels(intValues, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
|
||||
@@ -92,16 +102,18 @@ public class TensorFlowImageClassifier implements Classifier {
|
||||
for (int i = 0; i < inputSize; ++i) {
|
||||
for (int j = 0; j < inputSize; ++j) {
|
||||
final int val = intValues[pixel++];
|
||||
byteBuffer.put((byte) ((val >> 16) & 0xFF));
|
||||
byteBuffer.put((byte) ((val >> 8) & 0xFF));
|
||||
byteBuffer.put((byte) (val & 0xFF));
|
||||
byteBuffer.putFloat((((val >> 16) & 0xFF)-IMAGE_MEAN)/IMAGE_STD);
|
||||
byteBuffer.putFloat((((val >> 8) & 0xFF)-IMAGE_MEAN)/IMAGE_STD);
|
||||
byteBuffer.putFloat((((val) & 0xFF)-IMAGE_MEAN)/IMAGE_STD);
|
||||
}
|
||||
}
|
||||
return byteBuffer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@SuppressLint("DefaultLocale")
|
||||
private List<Recognition> getSortedResult(byte[][] labelProbArray) {
|
||||
private List<Recognition> getSortedResultFloat(float[][] labelProbArray) {
|
||||
|
||||
PriorityQueue<Recognition> pq =
|
||||
new PriorityQueue<>(
|
||||
@@ -114,7 +126,7 @@ public class TensorFlowImageClassifier implements Classifier {
|
||||
});
|
||||
|
||||
for (int i = 0; i < labelList.size(); ++i) {
|
||||
float confidence = (labelProbArray[0][i] & 0xff) / 255.0f;
|
||||
float confidence = labelProbArray[0][i];
|
||||
if (confidence > THRESHOLD) {
|
||||
pq.add(new Recognition("" + i,
|
||||
labelList.size() > i ? labelList.get(i) : "unknown",
|
||||
|
||||
Reference in New Issue
Block a user