Arresttb Model latest

This commit is contained in:
Ramandeep
2021-09-21 00:44:52 +05:30
parent 35fbea548a
commit 4db4918e39
5 changed files with 27 additions and 8 deletions

6
.idea/compiler.xml generated Normal file
View 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
View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <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" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

View File

@@ -3,6 +3,7 @@
<component name="RunConfigurationProducerService"> <component name="RunConfigurationProducerService">
<option name="ignoredProducers"> <option name="ignoredProducers">
<set> <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.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" /> <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" /> <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />

Binary file not shown.

View File

@@ -28,9 +28,14 @@ public class TensorFlowImageClassifier implements Classifier {
private static final int PIXEL_SIZE = 3; private static final int PIXEL_SIZE = 3;
private static final float THRESHOLD = 0.1f; 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 Interpreter interpreter;
private int inputSize; private int inputSize;
private List<String> labelList; private List<String> labelList;
private boolean quant;
private TensorFlowImageClassifier() { private TensorFlowImageClassifier() {
@@ -52,9 +57,13 @@ public class TensorFlowImageClassifier implements Classifier {
@Override @Override
public List<Recognition> recognizeImage(Bitmap bitmap) { public List<Recognition> recognizeImage(Bitmap bitmap) {
ByteBuffer byteBuffer = convertBitmapToByteBuffer(bitmap); ByteBuffer byteBuffer = convertBitmapToByteBuffer(bitmap);
/* ByteBuffer byteBuffer = convertBitmapToByteBuffer(bitmap);
byte[][] result = new byte[1][labelList.size()]; byte[][] result = new byte[1][labelList.size()];
interpreter.run(byteBuffer, result); 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 @Override
@@ -84,7 +93,8 @@ public class TensorFlowImageClassifier implements Classifier {
} }
private ByteBuffer convertBitmapToByteBuffer(Bitmap bitmap) { 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()); byteBuffer.order(ByteOrder.nativeOrder());
int[] intValues = new int[inputSize * inputSize]; int[] intValues = new int[inputSize * inputSize];
bitmap.getPixels(intValues, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight()); 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 i = 0; i < inputSize; ++i) {
for (int j = 0; j < inputSize; ++j) { for (int j = 0; j < inputSize; ++j) {
final int val = intValues[pixel++]; final int val = intValues[pixel++];
byteBuffer.put((byte) ((val >> 16) & 0xFF)); byteBuffer.putFloat((((val >> 16) & 0xFF)-IMAGE_MEAN)/IMAGE_STD);
byteBuffer.put((byte) ((val >> 8) & 0xFF)); byteBuffer.putFloat((((val >> 8) & 0xFF)-IMAGE_MEAN)/IMAGE_STD);
byteBuffer.put((byte) (val & 0xFF)); byteBuffer.putFloat((((val) & 0xFF)-IMAGE_MEAN)/IMAGE_STD);
} }
} }
return byteBuffer; return byteBuffer;
} }
@SuppressLint("DefaultLocale") @SuppressLint("DefaultLocale")
private List<Recognition> getSortedResult(byte[][] labelProbArray) { private List<Recognition> getSortedResultFloat(float[][] labelProbArray) {
PriorityQueue<Recognition> pq = PriorityQueue<Recognition> pq =
new PriorityQueue<>( new PriorityQueue<>(
@@ -114,7 +126,7 @@ public class TensorFlowImageClassifier implements Classifier {
}); });
for (int i = 0; i < labelList.size(); ++i) { for (int i = 0; i < labelList.size(); ++i) {
float confidence = (labelProbArray[0][i] & 0xff) / 255.0f; float confidence = labelProbArray[0][i];
if (confidence > THRESHOLD) { if (confidence > THRESHOLD) {
pq.add(new Recognition("" + i, pq.add(new Recognition("" + i,
labelList.size() > i ? labelList.get(i) : "unknown", labelList.size() > i ? labelList.get(i) : "unknown",