Arresttb Model latest
This commit is contained in:
6
.idea/compiler.xml
generated
Normal file
6
.idea/compiler.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="11" />
|
||||
</component>
|
||||
</project>
|
||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
||||
1
.idea/runConfigurations.xml
generated
1
.idea/runConfigurations.xml
generated
@@ -3,6 +3,7 @@
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
|
||||
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
|
||||
|
||||
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