Commit 82562f90 by wanglei

format

1 parent 2756155a
...@@ -26,20 +26,16 @@ import java.util.List; ...@@ -26,20 +26,16 @@ import java.util.List;
public interface Classifier { public interface Classifier {
List<Recognition> recognizeImage(Bitmap bitmap); List<Recognition> recognizeImage(Bitmap bitmap);
void enableStatLogging(final boolean debug);
String getStatString();
void close(); void close();
void setNumThreads(int num_threads); void setNumThreads(int num_threads);
abstract float getObjThresh(); float getObjThresh();
/** /**
* An immutable result returned by a Classifier describing what was recognized. * An immutable result returned by a Classifier describing what was recognized.
*/ */
public class Recognition { class Recognition {
/** /**
* A unique identifier for what has been recognized. Specific to the class, not the instance of * A unique identifier for what has been recognized. Specific to the class, not the instance of
* the object. * the object.
...@@ -63,14 +59,6 @@ public interface Classifier { ...@@ -63,14 +59,6 @@ public interface Classifier {
private int detectedClass; private int detectedClass;
public Recognition(
final String id, final String title, final Float confidence, final RectF location) {
this.id = id;
this.title = title;
this.confidence = confidence;
this.location = location;
}
public Recognition(final String id, final String title, final Float confidence, final RectF location, int detectedClass) { public Recognition(final String id, final String title, final Float confidence, final RectF location, int detectedClass) {
this.id = id; this.id = id;
this.title = title; this.title = title;
...@@ -103,10 +91,6 @@ public interface Classifier { ...@@ -103,10 +91,6 @@ public interface Classifier {
return detectedClass; return detectedClass;
} }
public void setDetectedClass(int detectedClass) {
this.detectedClass = detectedClass;
}
@Override @Override
public String toString() { public String toString() {
String resultString = ""; String resultString = "";
......
...@@ -128,15 +128,6 @@ public class YoloV5Classifier implements Classifier { ...@@ -128,15 +128,6 @@ public class YoloV5Classifier implements Classifier {
} }
@Override @Override
public void enableStatLogging(final boolean logStats) {
}
@Override
public String getStatString() {
return "";
}
@Override
public void close() { public void close() {
tfLite.close(); tfLite.close();
tfLite = null; tfLite = null;
...@@ -303,9 +294,6 @@ public class YoloV5Classifier implements Classifier { ...@@ -303,9 +294,6 @@ public class YoloV5Classifier implements Classifier {
return right - left; return right - left;
} }
protected static final int BATCH_SIZE = 1;
protected static final int PIXEL_SIZE = 3;
/** /**
* Writes Image data into a {@code ByteBuffer}. * Writes Image data into a {@code ByteBuffer}.
*/ */
...@@ -402,57 +390,4 @@ public class YoloV5Classifier implements Classifier { ...@@ -402,57 +390,4 @@ public class YoloV5Classifier implements Classifier {
final ArrayList<Recognition> recognitions = nms(detections); final ArrayList<Recognition> recognitions = nms(detections);
return recognitions; return recognitions;
} }
public boolean checkInvalidateBox(float x, float y, float width, float height, float oriW, float oriH,
int intputSize) {
// (1) (x, y, w, h) --> (xmin, ymin, xmax, ymax)
float halfHeight = height / 2.0f;
float halfWidth = width / 2.0f;
float[] pred_coor = new float[] { x - halfWidth, y - halfHeight, x + halfWidth, y + halfHeight };
// (2) (xmin, ymin, xmax, ymax) -> (xmin_org, ymin_org, xmax_org, ymax_org)
float resize_ratioW = 1.0f * intputSize / oriW;
float resize_ratioH = 1.0f * intputSize / oriH;
float resize_ratio = resize_ratioW > resize_ratioH ? resize_ratioH : resize_ratioW; // min
float dw = (intputSize - resize_ratio * oriW) / 2;
float dh = (intputSize - resize_ratio * oriH) / 2;
pred_coor[0] = 1.0f * (pred_coor[0] - dw) / resize_ratio;
pred_coor[2] = 1.0f * (pred_coor[2] - dw) / resize_ratio;
pred_coor[1] = 1.0f * (pred_coor[1] - dh) / resize_ratio;
pred_coor[3] = 1.0f * (pred_coor[3] - dh) / resize_ratio;
// (3) clip some boxes those are out of range
pred_coor[0] = pred_coor[0] > 0 ? pred_coor[0] : 0;
pred_coor[1] = pred_coor[1] > 0 ? pred_coor[1] : 0;
pred_coor[2] = pred_coor[2] < (oriW - 1) ? pred_coor[2] : (oriW - 1);
pred_coor[3] = pred_coor[3] < (oriH - 1) ? pred_coor[3] : (oriH - 1);
if ((pred_coor[0] > pred_coor[2]) || (pred_coor[1] > pred_coor[3])) {
pred_coor[0] = 0;
pred_coor[1] = 0;
pred_coor[2] = 0;
pred_coor[3] = 0;
}
// (4) discard some invalid boxes
float temp1 = pred_coor[2] - pred_coor[0];
float temp2 = pred_coor[3] - pred_coor[1];
float temp = temp1 * temp2;
if (temp < 0) {
Log.e("checkInvalidateBox", "temp < 0");
return false;
}
if (Math.sqrt(temp) > Float.MAX_VALUE) {
Log.e("checkInvalidateBox", "temp max");
return false;
}
return true;
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!